Skip to main content
April 27, 2012
Question

How can I save and later return to an x,y position in postscript?

  • April 27, 2012
  • 1 reply
  • 3254 views

I think the question pretty much says it. I need to be able to save the x,y position of where I'm at, put in some other strings, and then return to the saved position in order to overprint some strings.

This topic has been closed for replies.

1 reply

Participating Frequently
May 3, 2012

currentpoint /y exch def /x exch def

Mr__Horton
Inspiring
May 3, 2012

Regarding the response by abeddie - "currentpoint /y exch def /x exch def":

Saving the values of the current x and y positions and then later using them to perform a x y moveto works fine as long as the current transformation matrix is the same as when the x and y values were stored. If there has been a scaling operation, or a rotate operation, or some other transform, then the stored x and y values are just numeric values that will position according to the now current transformation matrix, not the past position that you want to return to.

I would recommend using gsave and grestore which will return the graphics state, including the transformation matrix, to the corresponding saved state.

What you will need to keep in mind is that operations that affect the graphics state, performed after the gsave, will be lost when you use grestore (ie. the introduction of new fonts and font sizes).

Participating Frequently
August 21, 2012

This is a bit late, I know, but if it's really important to save the x,y, you could convert the currentpoint to Device Space and store those coordinates:

     currentpoint transform /y exch def /x exch def

To use the x,y pair at a later time, you convert them back to user space:

     x y itransform moverto

gsave/grestore is better if your intent is simply to return to the current location; if you must actually store the values, storing them in Device Space gives you a CTM-independent way of doing so.

- John

-------

John Deubert

Acumen Training

PostScript & PDF consulting and training

www.acumentraining.com