weblog d’un abbe

20060106

Hello Postscript World…

Filed under: Experiences, Experiments — Tags: — abbe @ 1651

It all started off with HPGL, when in 1997, or 1998 my daddy used to export outputs of his designed PCBs (in DOS), as PRN files. These PRN files are in HPGL. I’d once seen (typed) the HPGL file and it consisted of purely text (some part of text resembles LOGO), I understood that it was some kind of language that HP plotters will understand. I decided to learn that language but no docs, so I dropped the idea.

But then, after few years I got to work on DTP softwares, and there I heard this Postscript, Encapsulated Postscript. I even had a book on Adobe Pagemaker 4, there I also seen this Postscript. And recently in one of the iLUG-d meet (actually on 23rd May, 2004), Raj Mathur told that how powerful Postscript was, that you can write a compiler in it. The next encounter with Postscript is when I got the NASM source code, the author supplied the documentation as a single text file, and with a perl script. The perl script generates the Postscript, RTF, HTML, etc. output from that file. I’m amazed I thought Postscript was as simple as HTML, or RTF. And now recently (actually 4th January, 2006), I downloaded the Postscript Language Reference Manual, and PostScript Language Tutorial & Cookbook. And then found that Postscript was as simple as writing programs for a stack machine.

Postscript machine is a stack machine with separate dictionary like memory (where it holds fonts, variables), etc. Anyways, here is one of my first postscript program.

/box {
 % stack contents
 % stroke width
 % right
 % top
 % left
 % bottom

 /outline exch def
 /right exch def
 /top exch def
 /left exch def
 /bottom exch def

 newpath
 left bottom moveto
 left top lineto
 right top lineto
 right bottom lineto
 left bottom lineto
 closepath
 outline setlinewidth
 stroke
} def

% Draw 4 boxes of stroke width 4/72"
100 100 200 200 4 box
100 100 175 275 4 box
100 100 150 250 4 box
100 100 225 225 4 box

% load a Times-Roman font
/Times-Roman findfont
36 scalefont
setfont

100 400 moveto
(Hello Postscript World) show
showpage

You can execute the above program on a Postscript interpreter (an opensource interpreter, GNU Ghostscript). Just after an hour of reading the tutorial, I’ve written this program. If you’ve ever programmed on a stack machine, you’ll find programming in Postscript very easy. If not programmed on stack machine, then also it is easy ;-).

Well, Postscript is really cool language. Give it a try.

P.S. The links I’ve provided for Postscript docs, I’ve found when I’ve searched for docs via Google and are not from the Adobe.com.

Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: