PostScript or should I say NotJavaScript
authorSam Moore <[email protected]>
Wed, 21 May 2014 09:44:24 +0000 (17:44 +0800)
committerSam Moore <[email protected]>
Wed, 21 May 2014 09:44:24 +0000 (17:44 +0800)
By the way Cairo outputs stupidly verbose PostScript
Making every single operator a single character does not help when you redefine paths every single time you use them.

Manually editing that one image into different formats is taking longer than working out what to say about them :S

.gitignore
chapters/Background.tex
chapters/Background_DOM.tex
chapters/Background_Interpreted.tex
figures/shape.eps [new file with mode: 0644]
figures/shape.pdf
thesis.pdf

index e022496..4e86ba5 100644 (file)
@@ -11,3 +11,4 @@ page*.svg
 ratings.db
 *.pyg
 *.lof
+*-eps-converted-to.pdf
index f11c1be..1d3e141 100644 (file)
@@ -99,29 +99,12 @@ In this section we will consider various approaches and motivations to specifyin
 
 \subsection{The Portable Document Format}
 
-``A PDF file should be thought of as a flattened representation of a data structure
-consisting of a collection of objects that can refer to each other in any arbitrary
-way.''
+Adobe's Portable Document Format (PDF) is used almost universally for sharing documents; the ability to export or print to PDF can be found in most graphical document editors, even text editors. 
 
-The PDF 1.7 standard describes a format which is \rephrase{essentially PostScript plus everything in the kitchen sink}.
-\begin{itemize}
-       \item PDF is not just crippled postscript
-       \item Objects - has a type system, like a programming language, not like the DOM where all objects are fundamentally the same - this is similar to PostScript
-       \item File structure - Header, body, reference table (location of objects in file), trailer (location of reference table and special objects)
-       \begin{itemize}
-               \item Read the file from the end
-               \item File can be updated incrementally as long as the trailer is at the end
-       \end{itemize}
-       \item Document structure - This is basically a graph, wheras the DOM is a tree
-       \item Content streams - objects but conceptually different - operators or instructions
-       \item Interactivity --- At this point, PDF suddenly changes from being PostScript to being XML
-       \begin{itemize}
-               \item 
-       \end{itemize}
-\end{itemize}
+Hayes describes PDF as ``... essentially 'flattened' PostScript; it’s what’s left when you remove all the procedures and loops in a program, replacing them with sequences of simple drawing commands.''\cite{hayes2012pixelsor}. Consultation of the PDF 1.7 standard shows that this statement does not a give a complete picture --- despite being based on the Adobe PostScript model of a document as a series of ``pages'' to be printed by executing sequential instructions, from version 1.5 the PDF standard began to borrow some ideas from the Document Object Model discussed in Section \ref{Document Object Model}. For example, interactive elements such as forms may be included as XHTML objects and styled using CSS. ``Actions'' are objects used to modify the data structure dynamically. In particular, it is possible to include Javascript Actions. Adobe defines the API for Javascript actions seperately to the PDF standard\cite{js_3d_pdf}. There is evidence in the literature of attempts to exploit these features, with mixed success\cite{barnes2013embedding, hayes2012pixelsor}.
+
+To quote Adobe's PDF 1.7 reference manual, ``A PDF file should be thought of as a flattened representation of a data structure consisting of a collection of objects that can refer to each other in any arbitrary way''\cite{pdfref17}.
 
-The biggest difference between the PDF design philosophy and the HTML5 philosophy is the emphasis in PDF on the actual file format.
-This means PDF is more complicated but also more efficient (at least, we would hope so).
 
 
 \subsection{Scientific Computation Packages}
index de0fe99..494f2b9 100644 (file)
@@ -20,18 +20,12 @@ var node = document.getElementById("curvedshape"); // Find the node by its uniqu
 node.style.fill = "#000000"; // Change the ``style'' attribute and set the CSS fill colour
 \end{minted}
 
-To illustrate the power of this technique we have produced our own example to generate an SVG interactively using HTML. The example generates successive iterations of a particular type of fractal curve first described by Koch\cite{koch1904surune} in 1904 and a popular example in modern literature \cite{goldman_fractal}. Unfortunately as it is currently not possible to include HTML within a PDF, we are only able to provide some examples of the output as static images in Figure \ref{koch}.
+To illustrate the power of this technique we have produced our own example to generate an SVG interactively using HTML. The example generates successive iterations of a particular type of fractal curve first described by Koch\cite{koch1904surune} in 1904 and a popular example in modern literature \cite{goldman_fractal}. Unfortunately as it is currently possible to directly include W3C HTML in a PDF, we are only able to provide some examples of the output as static images in Figure \ref{koch}.
 
 In HTML5, Javascript is not restricted to merely manipulating the DOM to alter the appearance of a document. The \verb/<canvas>/ tag and associated API provide a means to directly set the values of pixels on a display. This sort of low level API is inteded for performance intensive graphical applications such as web based games\footnote{For an example by the author including both the canvas2d and experimental WebGL APIs see \url{http://rabbitgame.net}}. As Hayes points out, there is some similarity between the \verb/<canvas>/ API and the PostScript interpreted approach to drawing\cite{hayes2012pixelsor}.
 
 \begin{figure}[H]
-\begin{minipage}[t]{0.3\textwidth}
-       \begin{figure}[H]
-       \centering
-       \includegraphics[width=1\textwidth]{figures/shape.pdf}
-       \end{figure}
-\end{minipage}
-\begin{minipage}[t]{0.5\textwidth}
+\begin{minipage}[t]{0.65\textwidth}
 \begin{minted}{xml}
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
 <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" 
@@ -58,6 +52,12 @@ In HTML5, Javascript is not restricted to merely manipulating the DOM to alter t
                stroke:#000000;"/>
 </svg>
 \end{minted}
+\end{minipage}
+\begin{minipage}[t]{0.3\textwidth}
+       \begin{figure}[H]
+       \centering
+       \includegraphics[width=1\textwidth]{figures/shape.pdf}
+       \end{figure}
 \end{minipage}
        \caption{Vector image and a possible SVG representation}\label{SVG}
 \end{figure}
index e69de29..baa3849 100644 (file)
@@ -0,0 +1,50 @@
+\subsubsection{\TeX and Metafont}
+
+Donald Knuth's  ``The \TeX  Book'' and ``Metafont'' 
+
+\subsubsection{PostScript}
+
+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}.
+
+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}.
+
+\begin{figure}[H]
+\begin{minipage}[t]{0.65\textwidth}
+\begin{minted}{postscript}
+% These lines are comments to aid in human understanding
+% Define an operator to produce a rectangular path
+/re { exch dup neg 3 1 roll 5 3 roll moveto 0 rlineto
+      0 exch rlineto 0 rlineto closepath } bind def
+% Operator to produce the path for the first rectangle
+/re1 { 24.613 133.001 24 -120 re } bind def
+% Operator to produce the path for the second rectangle
+/re2 { 10.215 45.001 48 -16 re } bind def
+% Operator which will produce the curved path
+/curve { 46.215 1.001 moveto 
+46.215 1.001 91.812 11.399 71.812 35.399 curveto 51.812 59.399
+ 29.414 33.802 51.812 59.399 curveto 74.215 85.001 93.414 45.802 74.215 85.001
+ curveto 55.016 125.001 61.414 49.802 46.215 75.399 curveto 31.016 101.001 56.613 126.598
+ 56.613 126.598 curveto 56.613 126.598 88.613 166.598 56.613 137.802 curveto 24.613 
+109.001 -18.586 83.399 9.414 50.598 curveto 37.414 17.802 45.414 1.001 45.414 
+1.001 curveto closepath } bind def
+% Set stroke properties
+0.8 setlinewidth 0 setlinecap 0 setlinejoin [] 0.0 setdash 4 setmiterlimit 
+% Draw the straight line
+0 setgray 0.613 149.001 moveto 83.812 0.2 lineto fill 
+% Fill and outline the first rectangular path
+0 0 1 setrgbcolor re1 fill 0 setgray re1 stroke
+% Fill and outline the curved shape
+1 0 0 setrgbcolor curve fill 0 setgray curve stroke
+% Fill and outline the second rectangle 
+0 1 0 setrgbcolor re2 fill 0 setgray re2 stroke
+showpage
+\end{minted}
+\end{minipage}
+\begin{minipage}[t]{0.3\textwidth}
+       \begin{figure}[H]
+       \centering
+       \includegraphics[width=1\textwidth]{figures/shape.eps}
+       \end{figure}
+\end{minipage}
+       \caption{Vector image and a possible PostScript representation}\label{PS}
+\end{figure}
diff --git a/figures/shape.eps b/figures/shape.eps
new file mode 100644 (file)
index 0000000..3b8c509
--- /dev/null
@@ -0,0 +1,29 @@
+%!PS-Adobe-3.0 EPSF-3.0
+%%BoundingBox: 0 -1 85 150
+
+% A rectangular path
+/re { exch dup neg 3 1 roll 5 3 roll moveto 0 rlineto
+      0 exch rlineto 0 rlineto closepath } bind def
+% Path for the first rectangle
+/re1 { 24.613 133.001 24 -120 re } bind def
+% Path for the second rectangle
+/re2 { 10.215 45.001 48 -16 re } bind def
+% The curved path
+/curve { 46.215 1.001 moveto 
+46.215 1.001 91.812 11.399 71.812 35.399 curveto 51.812 59.399
+ 29.414 33.802 51.812 59.399 curveto 74.215 85.001 93.414 45.802 74.215 85.001
+ curveto 55.016 125.001 61.414 49.802 46.215 75.399 curveto 31.016 101.001 56.613 126.598
+ 56.613 126.598 curveto 56.613 126.598 88.613 166.598 56.613 137.802 curveto 24.613 
+109.001 -18.586 83.399 9.414 50.598 curveto 37.414 17.802 45.414 1.001 45.414 
+1.001 curveto closepath } bind def
+% Set stroke properties
+0.8 setlinewidth 0 setlinecap 0 setlinejoin [] 0.0 setdash 4 setmiterlimit 
+% Draw the straight line
+0 setgray 0.613 149.001 moveto 83.812 0.2 lineto fill 
+% Fill and outline the first rectangular path
+0 0 1 setrgbcolor re1 fill 0 setgray re1 stroke
+% Fill and outline the curved shape
+1 0 0 setrgbcolor curve fill 0 setgray curve stroke
+% Fill and outline the second rectangle 
+0 1 0 setrgbcolor re2 fill 0 setgray re2 stroke
+showpage
index d896a55..e4e19e2 100644 (file)
Binary files a/figures/shape.pdf and b/figures/shape.pdf differ
index 9327ea9..72517d4 100644 (file)
Binary files a/thesis.pdf and b/thesis.pdf differ

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