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

Can't understand a command line csm

Guest
Apr 22, 2016 Apr 22, 2016

Copy link to clipboard

Copied

Hello, Can somone explain to me this command line :

"/csm {1 dpi2point div -1 dpi2point div scale neg translate  dup landscapeMode eq {pop -90 rotate}   {rotateMode eq {90 rotate} if} ifelse} bdef" taken from a matlab generated .eps file ?

There are some already defined variables like:

/bdef {bind def} bind def

/portraitMode 0 def /landscapeMode 1 def /rotateMode 2 def

/dpi2point 0 def (redefined after beginning object drawing as /dpi2point 12 def)

This command is used as follows:

portraitMode 1056 6924 csm

What I don't get is:

1 - The role of the operands before the defined csm operator

2 - How can I read the stacked together operators (scale, ne, translate, ...), where are their operands and how are they supposed to work together ? And also how can I read the tests (if, ifelse) that define the csm operator?

Regards,

TOPICS
Programming

Views

981

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

correct answers 1 Correct answer

Explorer , Apr 23, 2016 Apr 23, 2016

Hi.

This is not a short-answer question, but I'll try to give you some idea of what's going on.

PostScript is a stack-based language, so when the csm procedure is called

portraitMode 1056 6924 csm

the values portraitMode (a number being used as a switch), 1056, and 6924 are pushed onto a stack, with portraitMode being the bottommost, like so:

  6924

  1056

  0     <— this is portraitMode

The csm procedure uses these values to rearrange the coordinate system. It scales by 1/dpi2point, then offsets the or

...

Votes

Translate

Translate
Explorer ,
Apr 23, 2016 Apr 23, 2016

Copy link to clipboard

Copied

Hi.

This is not a short-answer question, but I'll try to give you some idea of what's going on.

PostScript is a stack-based language, so when the csm procedure is called

portraitMode 1056 6924 csm

the values portraitMode (a number being used as a switch), 1056, and 6924 are pushed onto a stack, with portraitMode being the bottommost, like so:

  6924

  1056

  0     <— this is portraitMode

The csm procedure uses these values to rearrange the coordinate system. It scales by 1/dpi2point, then offsets the origin by x,y = 6924,1056 (here using the example numbers from above), removing the top two numbers from the stack, leaving only the portraitMode value (0 or 1, evidently) still on the stack. This is used to rotate either 90 or -90 degrees.

The upshot to this is that PostScript operators within a procedure (or anywhere else) take their arguments from the operand stack, those arguments having been placed there before the procedure is called. The only way to really understand what’s happening is to draw the stack (on paper) and then work through the code, redrawing the stack as needed.

I'm sorry if this is cryptic, but for a full understanding of what’s going on, you’ll need to learn how the PostScript language works; it’s a fun language (well, I enjoy it), but very different from any other language you’ve probably encountered. The PostScript Language Reference Manual does a good job of describing the language and there are some long-out-of-print books you can still get on Amazon. I teach PostScript classes when anyone wants one (pretty infrequently these days) and have several dozen free “Acumen Journals” with PostScript articles you may find useful, downloadable at  acumentraining.com/acumenjournal.html.

Hope this helped a bit.

Best regards,

John

-------

John Deubert

Acumen Training

PostScript & PDF consulting and training

john@acumentraining.com

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
Guest
Apr 25, 2016 Apr 25, 2016

Copy link to clipboard

Copied

LATEST

Hi John,

Thank you very much for your response. I'm starting to see more clearly now 🙂

I think that my problem was that I didn't know whether to start reading from the left or from the right, and how do I read or interpret the stacked commands (like: "scale neg translate dup" for example), what goes first and how does its result combine with the rest?

I've drawn the stack on a paper and I went through the code and I think I got it 🙂

If I'm right, and since the first operand (which will be put on the bottom of the stack) is "portraitMode", the code will (I you said) scale the coordinate system by a factor of 1/12 on the x-axis, scale it by a factor of -1/12 on the y-axis, translate it to the point (x, y) = (1056, -6924) (in the rescaled coordinate system) and that's it!

Otherwise if the first operand was "landscapeMode", the code would have done the same thing and after that it would have removed the last remaining element on the stack (after the pop command) and then rotated the coordinate system 90° (clockwise).

If, now, the first operand was "rotateMode", the code would have done the same thing as for the "portraitMode" case and after that it would have rotated the coordinate system 90° (counter-clockwise).

I want just to confirm that the boolean result of the "eq" operator is not put on the stack. Because otherwise, it won't work! Unless I'm missing something...

Thank you again, I really appreciated your help.

Best regards

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