X-Git-Url: https://git.ucc.asn.au/?p=ipdf%2Fsam.git;a=blobdiff_plain;f=chapters%2FBackground_DOM.tex;h=56ba48f3cb2566f6ed2718ce39c68acdd8a17470;hp=bb5d1690c61389c2fc867dc8d7e5bffc27bf2618;hb=3b509bbb92dc136e78e681973ca9ba364fa7be20;hpb=747a93660e5c5784f9f76b6c4f2a60bb92f7bdf3 diff --git a/chapters/Background_DOM.tex b/chapters/Background_DOM.tex index bb5d169..56ba48f 100644 --- a/chapters/Background_DOM.tex +++ b/chapters/Background_DOM.tex @@ -1,41 +1,57 @@ - 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 DOM is described within several W3C standards including XML, HTML and SVG. XML is a general language which is intended for representing any tree-like structure using the DOM, whilst languages such as HTML\cite{citationneeded} and SVG\cite{citationneeded} are specifically intended for representing visual information. SVG is defined as a type of XML, whilst HTML is tecnically distinct from XML. Both HTML and XML are supposedly be based upon a language called SGML which is not actually defined \rephrase{except in the foulest chapters of the necromonicom}. Then there is XHTML which is HTML but also XML. \rephrase{Cut the crap about what is and is not valid XML? We only care about the DOM we're not fucking web designers here}. +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 language Javascript (based upon ECMAScript \cite{ecma-262}) can be used to dynamically alter a HTML5 document in response to user input or other events, including communication with HTTP servers. + +The Scalable Vector Graphics (SVG) recommendation defines a language for representing vector images using the DOM. This is intended not only for stand alone images, but also for inclusion within HTML documents. In the SVG standard, each graphics primitive is an element in the DOM, whilst attributes of the element give information about how the primitive is to be drawn, such as path coordinates, line thickness, mitre styles and fill colours. Figure \ref{SVG} shows an example of an SVG image as rendered (left) and represented as text. The textual representation is syntactically a subset of XML and is similar to HTML.\footnote{The details of distinctions between these languages are beyond the scope of this report.} Here we have used \verb// elements to position rectangles and \verb// elements to define a straight line and a filled region bounded by a cubic bezier spline; note that the points and type of curves are defined as a data attribute. -The HyperText Markup Language (HTML) was, as its name implies, originally intended mostly for text. When combined with Cascading Style Sheets (CSS) control over the positioning and style of the text can be acheived. Images stored in some other format can be rendered within a HTML document, but HTML does not include ways to specify graphics primitives or their coordinates. -The Scalable Vector Graphics (SVG) standard was designed to represent a vector image. In the SVG standard, each graphics primitive is an element in the DOM, whilst attributes of the element give information about how the primitive is to be drawn, such as path coordinates, line thickness, mitre styles and fill colours. Figure \ref{SVG} shows an example of an image defined using the SVG format. The first two lines are only required for a stand alone image; the HTML standard allows for rendering an SVG within a web page using the \verb// tag. \rephrase{Read the standards a bit more carefully here...} +\subsubsection{Javascript and the DOM} +Using Javascript, an element in the DOM can be selected by its type, class, name, or unique identifier, each of which may be specified as an attribute in the original DOM. Once an element is selected Javascript can be used to modify its attributes, add children below it in the DOM, or remove it from the DOM entirely. + +For example, the following Javascript acting on the DOM described in Figure \ref{SVG} will change the fill colour of the curved region. +\begin{minted}{javascript} +var node = document.getElementById("curvedshape"); // Find the node by its unique id +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 an 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}. The W3C has produced a primer describing the use of HTML5 and Javascript to produce interactive SVG's\cite{w3c2010svghtmlprimer}, and the HTML5 and SVG standards themselves include several examples. + +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}. \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} + + - + + - + +