What it is
Page Description Language
Postscript was first popularised as a format for sending print-data to high end laser printers. It has long been a standard for professional printing. Nowadays, it is supported by many inexpensive personal laser printers such as the HP LaserJet 1200/1300 upward.
Postscript is also a fully functional programming language. Which means you can send your printer a few lines of text that cause it to internally
- calculate pi to a thousand places, to
- run a ray-tracing program or
- construct fractal recursive images, etc.
Scalable Vector Drawings
Bitmaps don’t scale. A drawing made using a “paint” tool generally can’t be resized without considerable loss of quality. For example, thin lines may disappear when scaled down, straight edges may get blocky and show staircase artifacts when scaled up. Paint tools include software such as PaintShopPro, the GIMP etc.
Drawing Maps in a Text Editor
I needed a small map for a web site, to show road directions to a building. I read up on Scalable Vector Graphics (SVG), the emerging web standard. However few browsers support it and plugins are messy. I briefly considered Windows Metafile Format (WMF) which Internet Explorer supports well (image dynamically rescaled as you resize the window). However other browsers dont support WMF so I don’t want to use that. I then used various drawing programs such as Corel Draw with the intention of producing a vector based image from which I could derive various sized bitmaps in Portable Network Graphics (PNG) form. However I couldn’t define my own line formats for roads (e.g. UK Ordnance Survey maps use yellow line with black border for “B” roads.)
I finally used a text editor to write postscript. I could define a b_road function to draw lines the way I wanted. It turned out to take less time than the time I’d spent fruitlessly with WYSIWYG tools. I used two windows: the editor (GVIM) and the viewer (GhostView). This worked well, Alt-Tab from Editor to Viewer and GSView automatically reloads the edited file and shows the latest edits.
Drawing logos in a text editor
Pretty much the same deal as with drawings. I have a company logo which I’ve had to redraw several times over the years as my software has changed. Often my original artwork gets stranded in a file format only understood by a tool which is either discontinued or where I’m not prepared to pay for an upgrade to a successor product. Case in point Xara Webster was a really excellent tool available at low cost. However the successor program is Xara X which is overkill.
The result is that I’ve redrawn the logo many times in different packages. Each time, I do it by hand, adding a curve and moving the control points until it looks right. A more precise way would be to extract and re-enter the coordinates and numeric parameters of the elements. However this is either inconvenient or impossible. Also sometimes a tool lacks some feature previously used, e.g. a colour fill polar-gradient between two arbitrary colours at an arbitrary angle. Another drawing packag might only support linear gradients or intensity/transparency gradients.
The result is that the logo on and old poster looks subtly different to the logo on last years’ letterheads and slightly different from the logo on the business cards. This is unsatisfactory.
Since all professional printers work with Postscript, I’m now making that my master format and deriving bitmaps from it as needed. Again, editing logos in a text editor is something I found surprisingly easy. OK its still slower to sketch something than in Corel-Draw but its more robust as a long-term file format. The postscript emitted by drawing tools is pretty nasty, too full of proprietary functions to be reusable in other tools or hand edited.
Using bezier curves to draw ellipses
The obvious way to draw an oblique ellipse is to draw a circle after applying a “rotate” transform and a “scale” transform. The problem with this is that the lines used to draw the ellipse get scaled too, so that their thickness varies. This is good if you want that effect (e.g. like a 3d view of a washer seen from an angle). Its not good of you want the line to have constant thickness.
One answer is to save the current transformation matrix before creating the path and restore the saved transformation matrix before stroking the path. This is shown in the blue book (ISBN 0–201–10179–3).
another approach is to construct the ellipse using four Bezier curves. This is only an approximation but it’s accurate to within one pixel at resolutions encountered in A4 printing.
In Postscript you can fill any arbitrary closed-path with a solid colour or a pattern. There’s no Postscript level 2 function to fill with a colour gradient.
I wanted to fill using a colour gradient so I wrote a Postscript leve 2 function to do it (Postscript 3 has the shfill function). It has a couple of disadvantages: It is a bit slow if you turn the resolution up (to avoid banding effects); It can produce moire fringes when rendered as a bitmap. However I like it!