From: Sam Moore Date: Tue, 20 May 2014 16:33:45 +0000 (+0800) Subject: Six Degrees of Document Format X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=3cc6f72b6bbdde973827f4f3cd47563d240cc345;p=ipdf%2Fsam.git Six Degrees of Document Format This just in, PDF has Javascript in it but it isn't quite the same as the DOM Why Oh also, does Javascript have its own standard or is it just included in HTML's standard --- diff --git a/chapters/Background.tex b/chapters/Background.tex index 8a85ce0..87d18ce 100644 --- a/chapters/Background.tex +++ b/chapters/Background.tex @@ -34,19 +34,34 @@ There are many different ways to define a spline. One approach is to specify ``k \subsubsection{Bezier Curves} \input{chapters/Background_Bezier} +\subsection{Font Rendering} + +Donald Knuth's 1986 textbook ``Metafont'' blargh + + + \subsection{Shading} Algorithms for shading on vector displays involved drawing equally spaced lines in the region with endpoints defined by the boundaries of the region\cite{brassel1979analgorithm}. Apart from being unrealistic, these techniques required a computationally expensive sorting of vertices\cite{lane1983analgorithm}. On raster displays, shading is typically based upon Lane's algorithm of 1983\cite{lane1983analgorithm}. Lane's algorithm relies on the ability to ``subtract'' fill from a region. This algorithm is now implemented in the GPU \rephrase{stencil buffer-y and... stuff} \cite{kilgard2012gpu} -\subsection{Compositing} +\subsection{Compositing and the Painter's Model}\label{Compositing and the Painter's Model} So far we have discussed techniques for rendering vector graphics primitives in isolation, with no regard to the overall structure of a document which may contain many thousands of primitives. A straight forward approach would be to render all elements sequentially to the display, with the most recently drawn pixels overwriting lower elements. Such an approach is particularly inconvenient for anti-aliased images where colours must appear to smoothly blur between the edge of a primitive and any drawn underneath it. -Most raster displays are based on an additive red-green-blue colour representation which matches the human eye's response to light\cite{citationneeded}. In 1984, Porter and Duff introduced a fourth colour channel to be used when combining rasterised images called the ``alpha'' channel, analogous to the transparency of a pixel\cite{porter1984compositing}. Elements can be rendered seperately, with the four colour channels of successively drawn elements being combined according to one of several possible operations described by Porter and Duff. +Colour raster displays are based on an additive red-green-blue $(r,g,b)$ colour representation which matches the human eye's response to light\cite{computergraphics2}. In 1984, Porter and Duff introduced a fourth colour channel for rasterised images called the ``alpha'' channel, analogous to the transparency of a pixel\cite{porter1984compositing}. In compositing models, elements can be rendered seperately, with the four colour channels of successively drawn elements being combined according to one of several possible operations. + +In the ``painter's model'' as described by the SVG standard, Porter and Duff's ``over'' operation is used when rendering one primitive over another\cite{svg2011-1.1}. +Given an existing pixel $P_1$ with colour values $(r_1, g_1, b_1, a_1)$ and a pixel $P_2$ with colours $(r_2, g_2, b_2, a_2)$ to be painted over $P_1$, the resultant pixel $P_T$ has colours given by: +\begin{align} + a_T &= 1 - (1-a_1)(1-a_2) \\ + r_T &= (1 - a_2)r_1 + r_2 \quad \text{(similar for $g_T$ and $b_T$)} +\end{align} +It should be apparent that alpha values of $1$ correspond to an opaque pixel; that is, when $a_2 = 1$ the resultant pixel $P_T$ is the same as $P_2$. +When the final pixel is actually drawn on an rgb display, the $(r, g, b)$ components are $(r_T/a_T, g_T/a_T, b_T/a_T)$. -In the ``painter's model'' described by the SVG standard, the ``over'' operation is used when rendering one primitive over another; the red-green-blue components of overlapping pixels are added but the alpha component is set to that of the uppermost pixel\cite{svg2011-1.1}. The PostScript and PDF standards also use the ``painter's model''. The painter's model is demonstrated in Figure \ref{SVG} --- originally an SVG image but converted to a PDF for inclusion in this report\footnote{PDF and SVG formats may be converted but neither standard allows for importing the other directly}. +The PostScript and PDF standards, as well as the OpenGL API also use a painter's model for compositing. However, PostScript does not include an alpha channel, so $P_T = P_2$ always\cite{plrm}. Figure \ref{SVG} illustrates the painter's model for partially transparent shapes as they would appear in both the SVG and PDF models. \subsection{Rasterisation on the CPU and GPU} @@ -58,11 +73,11 @@ Traditionally, vector graphics have been rasterized by the CPU before being sent The representation of information, particularly for scientific purposes, has changed dramatically over the last few decades. For example, Brassel's 1979 paper referenced earlier has been produced on a mechanical type writer. Although the paper discusses an algorithm for shading on computer displays, the figures illustrating this algorithm have not been generated by a computer, but drawn by Brassel's assistant\cite{brassel1979analgorithm}. In contrast, modern papers such as Barnes et. al's recent paper on embedding 3d images in PDF documents\cite{barnes2013embeddding} can themselves be an interactive proof of concept. -\rephrase{Say some stuff about Knuth's Metafont and \TeX here} +In this section we will consider various approaches and motivations to specifying the structure and appearance of a document, including: early interpreted formats (PostScript, \TeX, DVI), the Document Object Model popular in standards for web based documents (HTML, SVG), and Adobe's ubiquitous Portable Document Format (PDF). Some of these formats were discussed in a recent paper ``Pixels Or Perish'' by Hayes\cite{hayes2012pixelsor} who argues for greater interactivity in the PDF standard. -Hayes' 2012 article ``Pixels or Perish'' discusses the recent history and current state of the art in documents for scientific publications\cite{hayes2012pixels}. +\subsection{Interpreted Document Formats} +\input{chapters/Background_Interpreted} -\subsection{Interpreted Model} \begin{itemize} \item This model treats a document as the source code program which produces graphics @@ -78,19 +93,13 @@ Hayes' 2012 article ``Pixels or Perish'' discusses the recent history and curren \item Problems with security --- Turing complete, can be exploited easily \end{itemize} -\subsection{Crippled Interpreted Model} - -\rephrase{I'm pretty sure I made that one up} - -\begin{itemize} - \item PDF is PostScript but without the Turing Completeness - \item Solves security issues, more efficient -\end{itemize} - \pagebreak \subsection{Document Object Model}\label{Document Object Model} \input{chapters/Background_DOM} +\subsection{The Portable Document Format} + + \subsection{Scientific Computation Packages} The document and the code that produces it are one and the same. diff --git a/chapters/Background_DOM.tex b/chapters/Background_DOM.tex index f6adfd4..de0fe99 100644 --- a/chapters/Background_DOM.tex +++ b/chapters/Background_DOM.tex @@ -1,6 +1,6 @@ The Document Object Model (DOM) represents a document as a tree like data structure with the document as a root node. The elements of the document are represented as children of either this root node or of a parent element. In addition, elements may have attributes which contain information about that particular element. -The World Wide Web Consortium (W3C) is an organisation devoted to the development of standards for structuring and rendering web pages based on industry needs. The DOM is used by several W3C recommendations including XML\cite{xml2008-1.0}, HTML\cite{html2014-draft} and SVG\cite{svg2011-1.1}. XML is a general language which is intended for representing any tree-like structure using the DOM, whilst HTML and SVG are specifically intended for representing visual information to humans. These languages make use of Cascading Style Sheets (CSS)\cite{css2011-level2} for specifying the appearance of elements. +The World Wide Web Consortium (W3C) is an organisation devoted to the development of standards for structuring and rendering web pages based on industry needs. The DOM is used in and described by several W3C recommendations including XML\cite{xml2008-1.0}, HTML\cite{html2014-draft} and SVG\cite{svg2011-1.1}. XML is a general language which is intended for representing any tree-like structure using the DOM, whilst HTML and SVG are specifically intended for representing visual information to humans. These languages make use of Cascading Style Sheets (CSS)\cite{css2011-level2} for specifying the appearance of elements. Version 5 of the Hypertext Markup Language (HTML5) is currently a candidate recommendation which aims to standardise the state of the art in technologies relating to web based documents. In HTML5 it is possible to achieve almost any level of control over both the structure and rendering of a document desirable. In particular, the interpreted language Javascript included in the HTML5 standard can be used to dynamically alter the document as it is viewed in response to user input or other events such as communication with a remote server. @@ -20,7 +20,7 @@ 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{koch, 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 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}. In HTML5, Javascript is not restricted to merely manipulating the DOM to alter the appearance of a document. The \verb// 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// API and the PostScript interpreted approach to drawing\cite{hayes2012pixelsor}. @@ -59,7 +59,7 @@ In HTML5, Javascript is not restricted to merely manipulating the DOM to alter t \end{minted} \end{minipage} - \caption{Vector image and a possible SVG representation. This image also demonstrates concepts discussed in Section \ref{Rasterising Vector Images} including Spline Curves (\ref{}) and Compositing (\ref{})}\label{SVG} + \caption{Vector image and a possible SVG representation}\label{SVG} \end{figure} \begin{figure}[H] @@ -84,3 +84,4 @@ In HTML5, Javascript is not restricted to merely manipulating the DOM to alter t \caption{Koch ``snowflakes'' generated using Javascript to modify an SVG DOM. The interactive HTML5 document can be found at \url{http://szmoore.net/ipdf/sam/figures/koch.html}}\label{koch} \end{figure} + diff --git a/chapters/Background_Interpreted.tex b/chapters/Background_Interpreted.tex new file mode 100644 index 0000000..e69de29 diff --git a/thesis.pdf b/thesis.pdf index 11a8cd9..9327ea9 100644 Binary files a/thesis.pdf and b/thesis.pdf differ