PostScript or should I say NotJavaScript
[ipdf/sam.git] / chapters / Background_Interpreted.tex
1 \subsubsection{\TeX and Metafont}
2
3 Donald Knuth's  ``The \TeX  Book'' and ``Metafont'' 
4
5 \subsubsection{PostScript}
6
7 Adobe's PostScript Language Reference Manual defines a turing complete language for producing graphics output on an abstract ``output device''\cite{plrm}. A PostScript document is treated as a procedural program; an interpreter executes instructions in the order they are written by the programmer. Each symbol is pushed onto a stack as it is read. Special symbols called ``operators'' can act upon this stack and/or the output device. An internal ``graphics state'' stack can be constructed to store styling information (such as colour, line thickness, the current cursor position). It is possible for the language to define new operators. Figure \ref{PS} shows a vector image and one possible way to express this image in PostScript. PostScript was and is still widely used in printing of documents onto paper; many printers execute postscript directly, and recent formats including PDFs must still be converted into PostScript by printer drivers\cite{pdfref17, cheng2002portable}.
8
9 There are some limitations in PostScript's model. As mentioned in Section\ref{Compositing}, there is no concept of transparency. In fact, using tools to convert between the SVG image in Figure \ref{SVG} and PostScript will simply rasterise the image and embed the rastered image in PostScript. Another limitation of PostScript is that the model of a document as a static page, convenient for printers which literally produce static pages, is unable to include interactive or dynamic elements. Dynamic PostScript attempted to fix this problem, but ``never caught on''\cite{hayes2012pixelsor}.
10
11 \begin{figure}[H]
12 \begin{minipage}[t]{0.65\textwidth}
13 \begin{minted}{postscript}
14 % These lines are comments to aid in human understanding
15 % Define an operator to produce a rectangular path
16 /re { exch dup neg 3 1 roll 5 3 roll moveto 0 rlineto
17       0 exch rlineto 0 rlineto closepath } bind def
18 % Operator to produce the path for the first rectangle
19 /re1 { 24.613 133.001 24 -120 re } bind def
20 % Operator to produce the path for the second rectangle
21 /re2 { 10.215 45.001 48 -16 re } bind def
22 % Operator which will produce the curved path
23 /curve { 46.215 1.001 moveto 
24 46.215 1.001 91.812 11.399 71.812 35.399 curveto 51.812 59.399
25  29.414 33.802 51.812 59.399 curveto 74.215 85.001 93.414 45.802 74.215 85.001
26  curveto 55.016 125.001 61.414 49.802 46.215 75.399 curveto 31.016 101.001 56.613 126.598
27  56.613 126.598 curveto 56.613 126.598 88.613 166.598 56.613 137.802 curveto 24.613 
28 109.001 -18.586 83.399 9.414 50.598 curveto 37.414 17.802 45.414 1.001 45.414 
29 1.001 curveto closepath } bind def
30 % Set stroke properties
31 0.8 setlinewidth 0 setlinecap 0 setlinejoin [] 0.0 setdash 4 setmiterlimit 
32 % Draw the straight line
33 0 setgray 0.613 149.001 moveto 83.812 0.2 lineto fill 
34 % Fill and outline the first rectangular path
35 0 0 1 setrgbcolor re1 fill 0 setgray re1 stroke
36 % Fill and outline the curved shape
37 1 0 0 setrgbcolor curve fill 0 setgray curve stroke
38 % Fill and outline the second rectangle 
39 0 1 0 setrgbcolor re2 fill 0 setgray re2 stroke
40 showpage
41 \end{minted}
42 \end{minipage}
43 \begin{minipage}[t]{0.3\textwidth}
44         \begin{figure}[H]
45         \centering
46         \includegraphics[width=1\textwidth]{figures/shape.eps}
47         \end{figure}
48 \end{minipage}
49         \caption{Vector image and a possible PostScript representation}\label{PS}
50 \end{figure}

UCC git Repository :: git.ucc.asn.au