I am parsing a simple PowerPoint with three shapes. One shape is visibly to the left of the two other. But not when comparing it using python-pptx. The right side of that left shape (shape.left+shape.width) has a higher value than one of the other shapes left side (shape.left). The python-pptx result seem to indicate the right-hand shape starts within the left-hand shapes border. This seem to be caused by the group shape the right-hand shape is within.
What is the proper code to compare correctly that the right-hand shapes left side in fact is to the right of the left-hand shape?
I have tried removing the group, and then comparisons show expected values. I have tried creating new group shapes with shapes within, and again, they show expected values. However, the linked PowerPoint file at www.mibnet.se/LeftBoxIssue.pptx is an example where the group shape affects the normal result. When running the code, I do not know how the shapes were created. I need a generic way to test this special case correctly.
from pptx import Presentation
from pptx.enum.shapes import MSO_SHAPE_TYPE
strStartPowerPoint=r".\LeftBoxIssue.pptx"
prs=Presentation(strStartPowerPoint)
slide=prs.slides[0]
for shpShape in slide.shapes:
if shpShape.shape_type == MSO_SHAPE_TYPE.GROUP:
print(shpShape.shapes[0].text+
" has Left="+str(shpShape.shapes[0].left)+
" and right="+
str(shpShape.shapes[0].left+shpShape.shapes[0].width))
else:
print(shpShape.text+" has Left="+str(shpShape.left)+
" and right="+str(shpShape.left+shpShape.width))
I expect the right hand shape to have its "left" value greater than the left-hand shapes "right" value. But instead, it prints a smaller value:
Left has Left=160326 and right=6254527
Right has Left=3291751 and right=3846370