Copy link to clipboard
Copied
I'm having some troubles finding the exact frame of a text box page item.
The code I'm using is simply:
InterfacePtr<IShape> itemShape(pageItemUIDRef, UseDefaultIID());
clippingBounds = itemShape->GetPrintedBBox(PMMatrix(), Transform::SpreadCoordinates());
InterfacePtr<IGeometry> pageGeometry(pageUIDRef, IID_IGEOMETRY);
PMRect pageBounds = (pageGeometry->GetStrokeBoundingBox(::InnerToParentMatrix(pageGeometry)));
clippingBounds.Top(clippingBounds.Top() - pageBounds.Top());
clippingBounds.Left(clippingBounds.Left() - pageBounds.Left());
clippingBounds.Bottom(clippingBounds.Bottom() - pageBounds.Top());
clippingBounds.Right(clippingBounds.Right() - pageBounds.Left());
For the text box in the attached screenshot, this gives me back clipping bounds as X:174, Y:175, W:246, H:470. However, you can see in the screenshot that the text frame itself is X:174, Y:190, W:246, H:454
The values I'm getting seem to correspond to the extent of the selection highlight if I have the text highlighted.
I've not yet managed to find any values / combination of values in text-related interfaces that will enable me to directly get (or correct to) the actual frame rect as shown by InDesign.
Does anyone know how to go about this?
Thanks
Liz
1 Correct answer
Hello LizW,
do not assume that the page has its origin at the left top of the page. If you want to have the page item coordinates relative to the left top of the page then transform the bounding box of the page item from its inner coordinates to spread coordinates and than to the inner coordinate of the page. After that translate the result by the origin of the page bounding box.
Markus
Copy link to clipboard
Copied
Hello LizW,
the coordinates in the screenshot are relative to the reference point (left outside the screenshot) and in ruler cooridante system measured in pixel (px). Your computed values are relative to the left top corner of the page measured in point (pt). You must also consider that the function GetPaintedBBox() from IShape considers adornments. It is better to get the bounding box from the IGeometry interface of the page item.
I hope that helps you.
Markus
Copy link to clipboard
Copied
Hi Markus, thanks for your reply...
"Your computed values are relative to the left top corner of the page measured in point (pt)"
- Except that the X and Width values match what InDesign is showing - it's just Y and Height that are different. Would my values be in whatever units I've set in the preferences dialog? (pixels in this case)
"It is better to get the bounding box from the IGeometry interface of the page item."
- Thanks, I've tried this and although now the W/H dimensions it gives me are what I'm after, whatever Transform type I use, the origin is a negative value. E.g. PageCoordinates gives me X=-210, Y=-312. The reference point I had set which gave the coordinates in the screenshot was the top left of the frame (see new grab). Do you know what I would use to transform the negative values I'm getting to a coordinate space relative to the page's top left, or whatever those screenshot coords are from? I would have thought that's what PageCoordinates would give me, but apparently not!
Thanks again for your help
Liz
Copy link to clipboard
Copied
Hello LizW,
do not assume that the page has its origin at the left top of the page. If you want to have the page item coordinates relative to the left top of the page then transform the bounding box of the page item from its inner coordinates to spread coordinates and than to the inner coordinate of the page. After that translate the result by the origin of the page bounding box.
Markus
Copy link to clipboard
Copied
Brill, thanks Markus. All sorted!

