Shape coordinates for editing

12/06/2010

Dynamic imaging shapes can be located on the preview image using relative coordinates as explained in Shape metadata post. ZetaPrints dynamic imaging and web-to-print system accepts a number of parameters with every text and image field to move/crop/resize the shapes they are in. This post explains how the coordinates should be calculated.

The coordinate system

All coordinates are relative to width and height of the preview, where x1:0,y1:0 (top left) and x2:1,y2:1 (bottom right). A shape has 2 sets of coordinates:

  • box-x1, box-y1, box-x2, box-y2 – default preview
  • box-x1-u, box-y1-u, box-x2-u, box-y2-u – updated preview

As many shapes are transformed automatically depending on the contents the two sets can differ considerably. Even the actual size and proportions of the preview may differ. They can be normalized using page coordinates as the reference point. See attributes of TemplateDetails/Pages/Page element (page2box-x, page2box-y, page2box-w, page2box-h) for page to default preview relationship and page2box-x-u, page2box-y-u, page2box-w-u, page2box-h-u for page to updated preview relationship.

Page is the known point of reference

ZetaPrints dynamic imaging is stateless when it comes to preview generation. It remembers some of the details of the last call, but as the processing is distributed this info may not be readily available. It is more reliable if all coordinates in the metadata are specified in relation to a stable point of reference, which is the top left of the page. Read more about page to preview relationship in Shape metadata post.

When the default preview is showing for the first time the state of the template and the position of the shapes is known to ZetaPrints web-to-print system and the next request can be processed with it as reference point. However, further on as more previews are generated the shapes and the preview image itself flex and change size. The only stable reference point known to ZetaPrints and the script on the client is the page itself.

Coordinates normalization

All coordinates and distances submitted in metadata parameters need to be in reference to the page, not the preview. The client side script need to recalculate them.

Calculation example

From template details XML: box-x1-u = 0.25, page2box-x-u=-0.25, page2box-w-u=0.75

Position on the page = ([box-x1-u] – [page2box-x-u]) /[page2box-w-u] = (0.25 – (-0.25))/0.75=0.6666

Shift left by 30% of the last preview width: sh-x=shift / [page2box-w-u] = 0.30/0.75=0.4

See also: