• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

Guest
Apr 27, 2012 Apr 27, 2012

Copy link to clipboard

Copied

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.

TOPICS
Programming

Views

2.8K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
May 03, 2012 May 03, 2012

Copy link to clipboard

Copied

currentpoint /y exch def /x exch def

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
May 03, 2012 May 03, 2012

Copy link to clipboard

Copied

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).

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 21, 2012 Aug 21, 2012

Copy link to clipboard

Copied

LATEST

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines