Calculate absolute sizes and positions of grouped shapes

• Question

• Hi,

1.) We have a group of two shapes (group.docx).  Their extents and offsets defined as follows.

```    <wpg:wgp>
<a:xfrm>
<a:off x="0" y="0"/>
<a:ext cx="9117584" cy="572082"/>
<a:chOff x="2144" y="360"/>
<a:chExt cx="11536" cy="1138"/>
</a:xfrm>
<wps:wsp>
<a:xfrm>
<a:off x="2149" y="360"/>
<a:ext cx="0" cy="1138"/>
</a:xfrm>
<a:prstGeom prst="line">
<a:ln w="6350">
</wps:wsp>
<wps:wsp>
<a:xfrm>
<a:off x="2144" y="1462"/>
<a:ext cx="11536" cy="0"/>
</a:xfrm>
<a:prstGeom prst="line">
<a:ln w="45720">```

2.) If I ungroup those shapes (ungroup.docx), Word writes their offsets/extents this way.

```    <wps:wsp>
<a:xfrm>
<a:off x="0" y="0"/>
<a:ext cx="0" cy="572082"/>
</a:xfrm>
<a:prstGeom prst="line">
<a:ln w="6350">
<wps:wsp>
<a:xfrm>
<a:off x="0" y="0"/>
<a:ext cx="9117584" cy="0"/>
</a:xfrm>
<a:prstGeom prst="line">
<a:ln w="45720">```

Annex L.4.2 in the Office OpenXML specification (part 1) describes the process of transformations.

My problem is that I cannot figure out how to calculate 2.) from 1.) in practice.

Thanks for a help,

Igor

• Edited by Thursday, September 13, 2018 1:27 PM
Thursday, September 13, 2018 12:38 PM

All replies

• Thank you, Igor, for your question.  An engineer will contact you soon.

Bryan S. Burgin Senior Escalation Engineer Microsoft Protocol Open Specifications Team

Thursday, September 13, 2018 5:05 PM
• Hello Igor:

Thank you for contacting Microsoft Protocol Support. I'm looking into your query and will get back.

Thanks

Tarun Chopra | Escalation Engineer | Open Specifications Support Team

Thursday, September 13, 2018 5:59 PM
• Hello Igor:

The size of the bounding box of the shape is specified with the <a:ext> or extents element. The way I see it is - After ungrouping, the cy of bounding box becomes cy of first shape which is Vertical line and cx of bounding box becomes cx of second shape which is Horizontal line. Can you please share with us what exactly is blocking you interpreting this transformation?

PS: Per latest version of Office OpenXML specification (ISO 29500), Annex L.4.4 covers the translation not L.4.2. Looks like you are using an old version of OpenXML spec.

Thanks

Tarun Chopra | Escalation Engineer | Open Specifications Support Team

Tuesday, September 18, 2018 4:02 PM
• Hi Tarun,

I have only 1). and need to draw each shape.  This leads to a question of how to get the absolute ext/off for each shape.

I'll look for the latest spec.  Thanks.

Wednesday, September 19, 2018 4:36 AM
• Hello Igor:

The shapes reside inside bounding rectangle specified by <wgp> element. Considering scaling offsets and extents of X and Y by using <wgp> element value we will get following scaling values –

Scaling X offset: a:off/ a:choff = 0/2144

Scaling X ext: a:ext / a:chExt = 9117584/11536

Scaling Y offset: a:off/ a:choff = 0/360

Scaling Y ext: a:ext / a:chExt = 572082/ 1138

Now when we use these above scaling values with respective shapes offset\extent values we get their ungrouped values.

Ungrouped shape 1:

a:off x = (Scaling X offset) * (grouped a:off x) = 0/2144* 2149 = ~0.

a:off y = (Scaling Y offset) * (grouped a:off y) = 0/360* 360 = 0.

a:ext cx = (Scaling X ext) * (grouped a:ext cx) = 9117584/11536 * 0 = 0

a:ext cy = (Scaling Y ext) * (grouped a:ext cy) = 572082/ 1138 * 1138 = 572082

Can you use above logic and validate if you are able to draw each shape after ungrouping.

Thanks.

Tarun Chopra | Escalation Engineer | Open Specifications Support Team

Monday, October 1, 2018 4:03 PM
• Hi Tarun,

thank you for the answer.  It works well with extents, but with the offset I still have an issue.  What I'm getting is two lines rendered like this

---------

|

|

that is the horizontal line is placed above the vertical one.

According to your calculations it's looks correct, but there should be something more to that.  In group.docx and ungroup.docx the horizontal line is drawn under the vertical one.

And when I do ungroup, Word updates these elements which become different for each line.

```<wp:positionH relativeFrom="column">
<wp:posOffset>3952</wp:posOffset>
</wp:positionH>
<wp:positionV relativeFrom="paragraph">
<wp:posOffset>-190500</wp:posOffset>
</wp:positionV>

<wp:positionH relativeFrom="column">
<wp:posOffset>0</wp:posOffset>
</wp:positionH>
<wp:positionV relativeFrom="paragraph">
<wp:posOffset>363485</wp:posOffset>
</wp:positionV>```

So, I still can't get the correct absolute positions for the lines.

Thursday, October 11, 2018 1:13 PM
• Hello Igor:

Can you please share your .docx file so that I can have a look?

Thanks.

Tarun Chopra | Escalation Engineer | Open Specifications Support Team

Thursday, October 11, 2018 4:25 PM
• Tarun,

both, group.docx and ungroup.docx are attached to my first post.  Can you access those?

igor

Friday, October 12, 2018 6:30 AM
• Hello Igor:

I've access to your files. The image that you posted of dotted horizontal line and 2 vertical lines threw me off as your original file has only one vertical and one horizontal line. Can you drop me an mail at dochelp at Microsoft.com so that we can work it out offline thro' email and post our findings here later?

Thanks.

Tarun Chopra | Escalation Engineer | Open Specifications Support Team

Friday, October 12, 2018 4:54 PM
• Hello lgor,

I am having the same issue. ext value are coming absolutely accurate but positions are not correct.

If issue is resolved, please share your finding here.

Thanks,

Vishal Sood

Friday, November 23, 2018 4:05 AM
• Hi,

This is what Tarun Chopra has provided for the positioning problem.

------------------------------------------------------------

The group shape property gives the dimension of outer bounding box. Height = 572135/914400 = 0.63" and Width = 9117330/914400 = 9.97”. This ‘chExt’ tells us that the size dimension of child extent rectangle with starting offset as 2144,360. This chExt maps between .63” and 9.97”

<wpg:grpSpPr bwMode="auto">

<a:xfrm>

<a:off x="0" y="0"/>

<a:ext cx="9117330" cy="572135"/>

<a:chOff x="2144" y="360"/>

<a:chExt cx="11536" cy="1138"/>

</a:xfrm>

</wpg:grpSpPr>

Now for Horizontal line; the offset is 2144, 1462. If we try to map these offsets considering the line is inside a box with size as .63”h x 9.97”w, you will get close to this .61” Word rendering engine does all this mapping considering scaling and other attributes. However, this logic is out of scope of open specification hence we won't be able to provide much guidance. If you work along the lines of baseline logic shared above, I'm pretty sure you will be able to come close to what Word is doing.

------------------------------------------------------------

So, mapping the shape’s offsets from its chExt rectangle to the group’s bounding box gave me the desired outcome.

It is not perfect, but it is something very close to what I was expecting.

Monday, December 3, 2018 9:38 AM