A
Algorithms for Determining Coordinates Relative to
the Page
This appendix provides algorithms that can be used to determine an object’s position relative to the page
coordinates. For brevity, within this section a container is referred to as a
parent
and the contained object
as a
child.
A single container object may be parent to one object and child to another.
Suppose, for example, a child object places its internal origin at the top-left corner of its nominal content
region
(the typical case). If we have a point (Cx,Cy) in child coordinates, we can generate common
coordinates (CCx,CCY) for the parent with the following simple equations:
CCx = Cx + Mx
CCY = Cy + My
where Mx and My are the child's left and top margin insets, respectively.
In order to convert these common coordinates into its own space, the parent must first determine the
origin (Ox,Oy) of the child's top-left corner in its (the parent's) own coordinate space. These would be
computed from the child's anchor point (Ax,Ay), using the child's nominal extent's width and height (W,H)
as follows:
Ox = Ax (TopLeft, MiddleLeft, BottomLeft)
Ox = Ax - W/2 (TopCenter, MiddleCenter, BottomCenter)
Ox = Ax - W (TopRight, MiddleRight, BottomRight)
Oy = Ay (TopLeft, TopCenter, TopRight)
Oy = Ay - H/2 (MiddleLeft, MiddleCenter, MiddleRight)
Oy = Ay - H (BottomLeft, BottomCenter, BottomRight)
Now, it's a very simple transformation to generate parent coordinates (Px,Py) from common coordinates:
Px = CCx + Ox
Py = CCy + Oy
Or,
Px = Cx + Mx + Ox
Py = Cx + My + Oy
A slight optimization could be to avoid recalculating the invariants (Mx+Ox, My+Oy) through a little
cooperation between the parent and the child.
954