23 June 2009

Back to basics: Postscript

(Wikipedia): The Postscript language is a vectorial drawing format used to describe a page. It is an interpreted, stack-based language. The language syntax uses reverse Polish notation, which makes the order of operations unambiguous, but reading a program requires some practice, because one has to keep the layout of the stack in mind.
For example, the following postscript program draws a line from the point (0,0) to (100,100):
%!
0 0 moveto
100 100 lineto
stroke
You can view this file in ghostscript or drag this script onto your postscript printer.

I've played with postscript and created a XSLT stylesheet transforming a simple SVG document to postscript. The stylesheet is available here: svg2ps.xsl.

The following SVG document
<svg width="300px" height="300px" preserveAspectRatio="xMidYMid meet" zoomAndPan="magnify" version="1.0" contentScriptType="text/ecmascript" contentStyleType="text/css">
<title content="structured text">Small SVG example</title>
<circle cx="120" cy="150" r="60" fill="gold"/>
<polyline points="120 30, 25 150, 290 150" stroke-width="4" stroke="brown" fill="none"/>
<polygon points="210 100, 210 200, 270 150" fill="lawngreen"/>
<text x="60" y="250" fill="blue">Hello World</text>
</svg>




was transformed using my XSLT stylesheet, and here the result uploaded into scribd.com:

A Simple SVG document transformed to PDF with XSLT

Pierre

No comments:

Post a Comment