Penguin

Differences between version 3 and predecessor to the previous major change of PostScript.

Other diffs: Previous Revision, Previous Author, or view the Annotated Edit History

Newer page: version 3 Last edited on Sunday, November 2, 2003 5:01:17 pm by JohnMcPherson Revert
Older page: version 2 Last edited on Sunday, October 6, 2002 4:24:33 pm by JohnMcPherson Revert
@@ -19,4 +19,130 @@
 It's open 
  
 Postscript is fully specified in a publically available series of books (which you can find at any good bookstore). Although Adobe invented it and provides the dominant commercial implementation, other vendors like Aladdin produce independently coded implementations as well. 
 ---- 
+  
+Here is a very simple PostScript file that hopefully demonstrates very basic postscript commands and functionality:  
+  
+<verbatim>  
+%!PS-Adobe-2.0  
+%%BoundingBox: 0 0 400 400  
+%%Pages: 1  
+%%EndComments  
+  
+% any line starting with % is treated as a comment. "%!" as the first two  
+% bytes of the file is the "magic marker" that implies postscript.  
+  
+% Exception...  
+% need postscript version 2 or later to understand the above-style  
+% "special" comments starting with "%%". Also can use like that per-page  
+  
+%%Page: 1 1  
+  
+% disclaimer: the commands and examples given here aren't taken from a  
+% reference manual or anything, so some of the comments might be wrong or  
+% mis-understand what is actually happening...  
+  
+save % save the current colour, scale factor, etc variables to the stack  
+  
+% set the active colour to red (this is an R G B setting, between 0 and 1)  
+1.0 0 0 setrgbcolor  
+  
+% scale is global... if you double the scale, you need to halve it again  
+% later, unless you use save and restore...  
+  
+2 1 scale % set the scaling factor to 2x for x and 1x (ie normal) for y  
+  
+% draw a circle (well, it would be a circle if scaling was 1x)  
+  
+% x-origin y-origin radius startangle endangle arc (before scaling)  
+  
+100 100 50 0 360 arc % draws an arc (might be invisible)  
+  
+fill % fills the previous object with the active colour  
+  
+restore % go back to colour, scale, etc of the last save  
+  
+% create some constants  
+/x 100 def  
+/y 100 def  
+/radius 50 def  
+  
+% draw a circle using the saved state  
+x y radius 0 360 arc fill  
+  
+  
+% make some alias commands  
+/black {0 0 0 setrgbcolor} bind def  
+/blue {0 0 1 setrgbcolor} bind def  
+  
+% use them  
+blue  
+  
+% move the "cursor"  
+100 300 moveto  
+  
+% print some text  
+% before we can print text, we need to select the active font.  
+/Times-Roman findfont % font name  
+12 scalefont % font size  
+setfont % make that font the active font  
+  
+(Hello. This is blue text) show  
+  
+black  
+100 250 moveto ( You need to escape \( and \) as \\\( and \\\)) show  
+  
+% the "translate" command draws everything offset by this x and y,  
+% save and restore this - takes effect until the next translate or restore  
+% 200 0 translate % causes everything from here-on to be drawn  
+% 200 pts to the right  
+  
+  
+50 200 moveto % set current position  
+3 -5 (diagonal) ashow  
+  
+% print out the memory usage info  
+  
+/Times-Roman-Bold findfont % choose font  
+15 scalefont % font size  
+setfont % make active  
+  
+200 225 moveto (Memory Info:) show  
+  
+% print out information about the memory usage  
+vmstatus % ps function that puts 3 numbers on the stack...  
+% to be honest, I'm not sure what the numbers are. I suspect  
+% the 2nd is the mem used, and the 3rd is mem allocated. But ghostscript  
+% can dynamically increase the avail mem, so it isn't really a very useful  
+% number in most cases. If you send this file to a postscript printer it  
+% might actually mean something...  
+%  
+3 1 roll % take top value on stack and put it 3rd  
+exch % swap the top 2 values  
+%%% - now have reversed the order of the 3 numbers from vmstatus  
+200 204 moveto  
+  
+/Times-Roma findfont 12 scalefont setfont  
+(Min(?): ) show  
+10 string % create a 10-byte string  
+cvs % fill the string with the previous number on the stack  
+show ( bytes) show  
+200 192 moveto  
+(Used: ) show  
+10 string cvs show ( bytes) show  
+200 180 moveto  
+(Max: ) show 10 string cvs show ( bytes) show  
+  
+% print something to gv's pop-up informative window, or stdout for gs  
+(Example simple postscript commands\n) print  
+flush % cause it to be sent (from buffered)  
+  
+  
+  
+%%EndPage  
+  
+showpage % render the page  
+  
+%%EOF  
+  
+</verbatim>