we1
we1

Reputation: 71

How to get the absolute position of child shapes by using apache poi

This is a groupShape with a child shape:

<p:nvgrpsppr> 
   <p:cnvpr name="Group 256" id="260" /> 
   <p:cnvgrpsppr> 
    <a:grpsplocks nochangeaspect="1" /> 
   </p:cnvgrpsppr> 
   <p:nvpr /> 
  </p:nvgrpsppr> 
  <p:grpsppr bwmode="auto"> 
   <a:xfrm> 
    <a:off y="1940518" x="2952779" /> 
    <a:ext cy="2209679" cx="1219680" /> 
    <a:choff y="1052" x="1972" /> 
    <a:chext cy="1116" cx="616" /> 
   </a:xfrm> 
   <a:solidfill> 
    <a:srgbclr val="F7B63E" /> 
   </a:solidfill> 
  </p:grpsppr> 
  <p:sp> 
   <p:nvsppr> 
    <p:cnvpr name="Freeform 257" id="262" /> 
    <p:cnvsppr> 
     <a:splocks noeditpoints="1" /> 
    </p:cnvsppr> 
    <p:nvpr /> 
   </p:nvsppr> 
   <p:sppr bwmode="auto"> 
    <a:xfrm> 
     <a:off y="1160" x="2161" /> 
     <a:ext cy="287" cx="288" /> 
    </a:xfrm>
   </p:sppr>
  </p:sp>

When I ungroup, get this:

  <p:grpsppr> 
   <a:xfrm> 
    <a:off y="0" x="0" /> 
    <a:ext cy="0" cx="0" /> 
    <a:choff y="0" x="0" /> 
    <a:chext cy="0" cx="0" /> 
   </a:xfrm> 
  </p:grpsppr> 
  <p:sp> 
   <p:nvsppr> 
    <p:cnvpr name="Freeform 257" id="262" /> 
    <p:cnvsppr> 
     <a:splocks noeditpoints="1" /> 
    </p:cnvsppr> 
    <p:nvpr /> 
   </p:nvsppr> 
   <p:sppr bwmode="auto"> 
    <a:xfrm> 
     <a:off y="2154358" x="3326999" /> 
     <a:ext cy="568260" cx="570240" /> 
    </a:xfrm>
   </p:sppr>
  </p:sp>

The childShape converted to absolute positioning.

<a:xfrm> 
 <a:off y="1160" x="2161" /> 
 <a:ext cy="287" cx="288" /> 
</a:xfrm>

converted to:

<a:xfrm> 
 <a:off y="2154358" x="3326999" /> 
 <a:ext cy="568260" cx="570240" /> 
</a:xfrm>

I calculated the length and width by calculation.

width = (group a:ext:cx) / (group a:chExt:cx) * (child a:ext:x);

height = (group a:ext:cy) / (group a:chExt:cy) * (child a:ext:y);

But I tried many kinds of operations, and I couldn't get how to convert the x coordinate and y coordinate.

What operation should I pass to convert y:1160 to y:2154358.

please give me some advices.

Upvotes: 2

Views: 938

Answers (1)

Axel Richter
Axel Richter

Reputation: 61945

In your group XML

<a:off y="1940518" x="2952779" /> 
<a:ext cy="2209679" cx="1219680" /> 

means: The group starts at y 1940518, x 2952779 and has extent of height 2209679 and width 1219680.

The

<a:choff y="1052" x="1972" /> 
<a:chext cy="1116" cx="616" /> 

means: The child section of the group starts at y 1052, x 1972 and has extent of height 1116 and width 616. This are the original values of the shapes while grouping.

This shows that your group shape is heavily scaled. It was small and then was scaled with factor 1980.

scale_factor_y = ext_cy / chext_cy 
               = 2209679 / 1116 
               ≈ 1980

scale_factor_x = ext_cx / chext_cx 
               = 1219680 / 616
               = 1980

For your child in the group

 <a:off y="1160" x="2161" /> 
 <a:ext cy="287" cx="288" /> 

means: The not scaled offset is y 1160, x 2161. And the not scaled extent is height 287 and width 288.

If ungrouped, the scaled offset is:

off_y = (not_scaled_off_y - choff_y) * scale_factor_y + group_off_y
      = (1160  - 1052) * 1980 + 1940518
      = 2154358

off_x = (not_scaled_off_x - choff_x) * scale_factor_x + group_off_x
      = (2161  - 1972) * 1980 + 2952779
      = 3326999

and the scaled extent is:

ext_cy = not_scaled_ext_cy * scale_factor_y
       = 287 * 1980
       = 568260

ext_cx = not_scaled_ext_cx * scale_factor_x
       = 288 * 1980
       = 570240

This leads to your

<a:off y="2154358" x="3326999" /> 
<a:ext cy="568260" cx="570240" /> 

for the child out of the group which is now in same scaled size as the group was before.

Upvotes: 8

Related Questions