xmlgraphics-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From build...@apache.org
Subject svn commit: r840735 [4/19] - in /websites/staging/xmlgraphics/trunk/content: ./ batik/ batik/dev/ batik/tools/ batik/using/ batik/using/scripting/ commons/ fop/ fop/0.95/ fop/1.0/ fop/1.1/ fop/trunk/
Date Tue, 04 Dec 2012 15:59:44 GMT
Modified: websites/staging/xmlgraphics/trunk/content/batik/using/svg-generator.html
==============================================================================
--- websites/staging/xmlgraphics/trunk/content/batik/using/svg-generator.html (original)
+++ websites/staging/xmlgraphics/trunk/content/batik/using/svg-generator.html Tue Dec  4 15:59:34 2012
@@ -170,7 +170,7 @@ $(document).ready(function () {
 <div class="figure"> ![Flow diagram illustrating that Java programs can have their graphics converted to SVG and then viewed in any SVG viewer](images/svggen.jpg "") </div>
 
 <p>As SVG is emerging as a promising graphics format for a wide range of domains and applications, bridging it with Java becomes important. This page explains how Batik’s <a href="../javadoc/org/apache/batik/svggen/SVGGraphics2D.html">SVGGraphics2D</a> , referred to as the SVG Generator, makes this possible.</p>
-<h2 id="the-svggraphics2d-class-wzxhzdk16wzxhzdk17">The SVGGraphics2D class <a id="whatIsIt"></a></h2>
+<h2 id="the-svggraphics2d-class-wzxhzdk14wzxhzdk15">The SVGGraphics2D class <a id="whatIsIt"></a></h2>
 <p>On the Java platform, all rendering goes through the <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/awt/Graphics2D.html">Graphics2D</a> abstract class, which offers methods such as <code>drawRect</code> , <code>fillRect</code> , and <code>drawString</code> . There are specialized implementations of this abstract class for each type of output, such as a screen or a printer. <code>SVGGraphics2D</code> is a new implementation of that interface that generates SVG content instead of drawing to a screen or a printer.</p>
 <p><code>SVGGraphics2D</code> has the following features:</p>
 <ul>
@@ -189,53 +189,53 @@ $(document).ready(function () {
 <p>The above figure shows how the generator works with the DOM API. The W3C has defined an API for representing XML content with a Java object. That API allows programmers to manipulate, create, and/or modify XML content in memory. The DOM API contains interfaces such as <a href="http://java.sun.com/j2se/1.5.0/docs/api/org/w3c/dom/Document.html">Document</a> , <a href="http://java.sun.com/j2se/1.5.0/docs/api/org/w3c/dom/Element.html">Element</a> , and <a href="http://java.sun.com/j2se/1.5.0/docs/api/org/w3c/dom/Attr.html">Attr</a> , which model the Java programming language equivalent of XML documents, elements and attributes.</p>
 <p>The generator manages a tree of DOM objects that represent the SVG content corresponding to the rendering calls made on the <code>SVGGraphics2D</code> instance. In other words, every time a program invokes a rendering method, such as <code>fillRect</code> , on a <code>SVGGraphics2D</code> instance, a new DOM object, representing the SVG equivalent, is appended to the DOM tree. For example, a <code>rect</code> element will be appended after the <code>fillRect</code> method has been invoked).</p>
 <p>The programmer, using this generator, can then access the DOM tree to further manipulate it or can directly write the content to an output stream, as we see in the following section.</p>
-<h2 id="how-to-use-svggraphics2d-wzxhzdk18wzxhzdk19">How to use SVGGraphics2D <a id="howToUse"></a></h2>
+<h2 id="how-to-use-svggraphics2d-wzxhzdk16wzxhzdk17">How to use SVGGraphics2D <a id="howToUse"></a></h2>
 <p>From the figure in the previous section we can see that in order for an instance of <code>SVGGraphics2D</code> to build the SVG content (the DOM tree), an instance of a <code>Document</code> class is needed. The DOM tree is an in-memory representation of the SVG document, which can be further manipulated by the user using DOM API or be streamed out by a <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/io/Writer.html">Writer</a> object.</p>
 <p>The following example program demonstrates how to generate SVG content from Java graphics.</p>
-<div class="codehilite"><pre><span class="nb">import</span> <span class="n">java</span><span class="o">.</span><span class="n">awt</span><span class="o">.</span><span class="n">Rectangle</span><span class="p">;</span>
-<span class="nb">import</span> <span class="n">java</span><span class="o">.</span><span class="n">awt</span><span class="o">.</span><span class="n">Graphics2D</span><span class="p">;</span>
-<span class="nb">import</span> <span class="n">java</span><span class="o">.</span><span class="n">awt</span><span class="o">.</span><span class="n">Color</span><span class="p">;</span>
-<span class="nb">import</span> <span class="n">java</span><span class="o">.</span><span class="n">io</span><span class="o">.</span><span class="n">Writer</span><span class="p">;</span>
-<span class="nb">import</span> <span class="n">java</span><span class="o">.</span><span class="n">io</span><span class="o">.</span><span class="n">OutputStreamWriter</span><span class="p">;</span>
-<span class="nb">import</span> <span class="n">java</span><span class="o">.</span><span class="n">io</span><span class="o">.</span><span class="n">IOException</span><span class="p">;</span>
-
-<span class="nb">import</span> <span class="n">org</span><span class="o">.</span><span class="n">apache</span><span class="o">.</span><span class="n">batik</span><span class="o">.</span><span class="n">svggen</span><span class="o">.</span><span class="n">SVGGraphics2D</span><span class="p">;</span>
-<span class="nb">import</span> <span class="n">org</span><span class="o">.</span><span class="n">apache</span><span class="o">.</span><span class="n">batik</span><span class="o">.</span><span class="n">dom</span><span class="o">.</span><span class="n">GenericDOMImplementation</span><span class="p">;</span>
-
-<span class="nb">import</span> <span class="n">org</span><span class="o">.</span><span class="n">w3c</span><span class="o">.</span><span class="n">dom</span><span class="o">.</span><span class="n">Document</span><span class="p">;</span>
-<span class="nb">import</span> <span class="n">org</span><span class="o">.</span><span class="n">w3c</span><span class="o">.</span><span class="n">dom</span><span class="o">.</span><span class="n">DOMImplementation</span><span class="p">;</span>
-
-<span class="n">public</span> <span class="n">class</span> <span class="n">TestSVGGen</span> <span class="p">{</span>
-
-    <span class="n">public</span> <span class="n">void</span> <span class="n">paint</span><span class="p">(</span><span class="n">Graphics2D</span> <span class="n">g2d</span><span class="p">)</span> <span class="p">{</span>
-        <span class="n">g2d</span><span class="o">.</span><span class="n">setPaint</span><span class="p">(</span><span class="n">Color</span><span class="o">.</span><span class="n">red</span><span class="p">);</span>
-        <span class="n">g2d</span><span class="o">.</span><span class="n">fill</span><span class="p">(</span><span class="k">new</span> <span class="n">Rectangle</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span> <span class="mi">10</span><span class="p">,</span> <span class="mi">100</span><span class="p">,</span> <span class="mi">100</span><span class="p">));</span>
-    <span class="p">}</span>
-
-    <span class="n">public</span> <span class="n">static</span> <span class="n">void</span> <span class="n">main</span><span class="p">(</span><span class="n">String</span><span class="o">[]</span> <span class="n">args</span><span class="p">)</span> <span class="n">throws</span> <span class="n">IOException</span> <span class="p">{</span>
-
-        <span class="sr">//</span> <span class="n">Get</span> <span class="n">a</span> <span class="n">DOMImplementation</span><span class="o">.</span>
-        <span class="n">DOMImplementation</span> <span class="n">domImpl</span> <span class="o">=</span>
-            <span class="n">GenericDOMImplementation</span><span class="o">.</span><span class="n">getDOMImplementation</span><span class="p">();</span>
-
-        <span class="sr">//</span> <span class="n">Create</span> <span class="n">an</span> <span class="n">instance</span> <span class="n">of</span> <span class="n">org</span><span class="o">.</span><span class="n">w3c</span><span class="o">.</span><span class="n">dom</span><span class="o">.</span><span class="n">Document</span><span class="o">.</span>
-        <span class="n">String</span> <span class="n">svgNS</span> <span class="o">=</span> <span class="s">&quot;http://www.w3.org/2000/svg&quot;</span><span class="p">;</span>
-        <span class="n">Document</span> <span class="n">document</span> <span class="o">=</span> <span class="n">domImpl</span><span class="o">.</span><span class="n">createDocument</span><span class="p">(</span><span class="n">svgNS</span><span class="p">,</span> <span class="s">&quot;svg&quot;</span><span class="p">,</span> <span class="n">null</span><span class="p">);</span>
-
-        <span class="sr">//</span> <span class="n">Create</span> <span class="n">an</span> <span class="n">instance</span> <span class="n">of</span> <span class="n">the</span> <span class="n">SVG</span> <span class="n">Generator</span><span class="o">.</span>
-        <span class="n">SVGGraphics2D</span> <span class="n">svgGenerator</span> <span class="o">=</span> <span class="k">new</span> <span class="n">SVGGraphics2D</span><span class="p">(</span><span class="n">document</span><span class="p">);</span>
-
-        <span class="sr">//</span> <span class="n">Ask</span> <span class="n">the</span> <span class="n">test</span> <span class="n">to</span> <span class="n">render</span> <span class="n">into</span> <span class="n">the</span> <span class="n">SVG</span> <span class="n">Graphics2D</span> <span class="n">implementation</span><span class="o">.</span>
-        <span class="n">TestSVGGen</span> <span class="n">test</span> <span class="o">=</span> <span class="k">new</span> <span class="n">TestSVGGen</span><span class="p">();</span>
-        <span class="n">test</span><span class="o">.</span><span class="n">paint</span><span class="p">(</span><span class="n">svgGenerator</span><span class="p">);</span>
-
-        <span class="sr">//</span> <span class="n">Finally</span><span class="p">,</span> <span class="n">stream</span> <span class="n">out</span> <span class="n">SVG</span> <span class="n">to</span> <span class="n">the</span> <span class="n">standard</span> <span class="n">output</span> <span class="n">using</span>
-        <span class="sr">//</span> <span class="n">UTF</span><span class="o">-</span><span class="mi">8</span> <span class="n">encoding</span><span class="o">.</span>
-        <span class="n">boolean</span> <span class="n">useCSS</span> <span class="o">=</span> <span class="n">true</span><span class="p">;</span> <span class="sr">//</span> <span class="n">we</span> <span class="n">want</span> <span class="n">to</span> <span class="k">use</span> <span class="n">CSS</span> <span class="n">style</span> <span class="n">attributes</span>
-        <span class="n">Writer</span> <span class="n">out</span> <span class="o">=</span> <span class="k">new</span> <span class="n">OutputStreamWriter</span><span class="p">(</span><span class="n">System</span><span class="o">.</span><span class="n">out</span><span class="p">,</span> <span class="s">&quot;UTF-8&quot;</span><span class="p">);</span>
-        <span class="n">svgGenerator</span><span class="o">.</span><span class="n">stream</span><span class="p">(</span><span class="n">out</span><span class="p">,</span> <span class="n">useCSS</span><span class="p">);</span>
-    <span class="p">}</span>
-<span class="p">}</span>
+<div class="codehilite"><pre><span class="kn">import</span> <span class="nn">java.awt.Rectangle</span><span class="o">;</span>
+<span class="kn">import</span> <span class="nn">java.awt.Graphics2D</span><span class="o">;</span>
+<span class="kn">import</span> <span class="nn">java.awt.Color</span><span class="o">;</span>
+<span class="kn">import</span> <span class="nn">java.io.Writer</span><span class="o">;</span>
+<span class="kn">import</span> <span class="nn">java.io.OutputStreamWriter</span><span class="o">;</span>
+<span class="kn">import</span> <span class="nn">java.io.IOException</span><span class="o">;</span>
+
+<span class="kn">import</span> <span class="nn">org.apache.batik.svggen.SVGGraphics2D</span><span class="o">;</span>
+<span class="kn">import</span> <span class="nn">org.apache.batik.dom.GenericDOMImplementation</span><span class="o">;</span>
+
+<span class="kn">import</span> <span class="nn">org.w3c.dom.Document</span><span class="o">;</span>
+<span class="kn">import</span> <span class="nn">org.w3c.dom.DOMImplementation</span><span class="o">;</span>
+
+<span class="kd">public</span> <span class="kd">class</span> <span class="nc">TestSVGGen</span> <span class="o">{</span>
+
+  <span class="kd">public</span> <span class="kt">void</span> <span class="nf">paint</span><span class="o">(</span><span class="n">Graphics2D</span> <span class="n">g2d</span><span class="o">)</span> <span class="o">{</span>
+    <span class="n">g2d</span><span class="o">.</span><span class="na">setPaint</span><span class="o">(</span><span class="n">Color</span><span class="o">.</span><span class="na">red</span><span class="o">);</span>
+    <span class="n">g2d</span><span class="o">.</span><span class="na">fill</span><span class="o">(</span><span class="k">new</span> <span class="n">Rectangle</span><span class="o">(</span><span class="mi">10</span><span class="o">,</span> <span class="mi">10</span><span class="o">,</span> <span class="mi">100</span><span class="o">,</span> <span class="mi">100</span><span class="o">));</span>
+  <span class="o">}</span>
+
+  <span class="kd">public</span> <span class="kd">static</span> <span class="kt">void</span> <span class="nf">main</span><span class="o">(</span><span class="n">String</span><span class="o">[]</span> <span class="n">args</span><span class="o">)</span> <span class="kd">throws</span> <span class="n">IOException</span> <span class="o">{</span>
+
+    <span class="c1">// Get a DOMImplementation.</span>
+    <span class="n">DOMImplementation</span> <span class="n">domImpl</span> <span class="o">=</span>
+      <span class="n">GenericDOMImplementation</span><span class="o">.</span><span class="na">getDOMImplementation</span><span class="o">();</span>
+
+    <span class="c1">// Create an instance of org.w3c.dom.Document.</span>
+    <span class="n">String</span> <span class="n">svgNS</span> <span class="o">=</span> <span class="s">&quot;http://www.w3.org/2000/svg&quot;</span><span class="o">;</span>
+    <span class="n">Document</span> <span class="n">document</span> <span class="o">=</span> <span class="n">domImpl</span><span class="o">.</span><span class="na">createDocument</span><span class="o">(</span><span class="n">svgNS</span><span class="o">,</span> <span class="s">&quot;svg&quot;</span><span class="o">,</span> <span class="kc">null</span><span class="o">);</span>
+
+    <span class="c1">// Create an instance of the SVG Generator.</span>
+    <span class="n">SVGGraphics2D</span> <span class="n">svgGenerator</span> <span class="o">=</span> <span class="k">new</span> <span class="n">SVGGraphics2D</span><span class="o">(</span><span class="n">document</span><span class="o">);</span>
+
+    <span class="c1">// Ask the test to render into the SVG Graphics2D implementation.</span>
+    <span class="n">TestSVGGen</span> <span class="n">test</span> <span class="o">=</span> <span class="k">new</span> <span class="n">TestSVGGen</span><span class="o">();</span>
+    <span class="n">test</span><span class="o">.</span><span class="na">paint</span><span class="o">(</span><span class="n">svgGenerator</span><span class="o">);</span>
+
+    <span class="c1">// Finally, stream out SVG to the standard output using</span>
+    <span class="c1">// UTF-8 encoding.</span>
+    <span class="kt">boolean</span> <span class="n">useCSS</span> <span class="o">=</span> <span class="kc">true</span><span class="o">;</span> <span class="c1">// we want to use CSS style attributes</span>
+    <span class="n">Writer</span> <span class="n">out</span> <span class="o">=</span> <span class="k">new</span> <span class="n">OutputStreamWriter</span><span class="o">(</span><span class="n">System</span><span class="o">.</span><span class="na">out</span><span class="o">,</span> <span class="s">&quot;UTF-8&quot;</span><span class="o">);</span>
+    <span class="n">svgGenerator</span><span class="o">.</span><span class="na">stream</span><span class="o">(</span><span class="n">out</span><span class="o">,</span> <span class="n">useCSS</span><span class="o">);</span>
+  <span class="o">}</span>
+<span class="o">}</span>
 </pre></div>
 
 
@@ -243,305 +243,298 @@ $(document).ready(function () {
 <ol>
 <li>
 <p>Create an instance of <code>org.w3c.dom.Document</code> that the generator will use to build its XML content, and create an SVG generator using the <code>Document</code> instance.</p>
-<div class="codehilite"><pre><span class="sr">//</span> <span class="n">Get</span> <span class="n">a</span> <span class="n">DOMImplementation</span><span class="o">.</span>
-<span class="n">DOMImplementation</span> <span class="n">domImpl</span> <span class="o">=</span>
-    <span class="n">GenericDOMImplementation</span><span class="o">.</span><span class="n">getDOMImplementation</span><span class="p">();</span>
-
-<span class="sr">//</span> <span class="n">Create</span> <span class="n">an</span> <span class="n">instance</span> <span class="n">of</span> <span class="n">org</span><span class="o">.</span><span class="n">w3c</span><span class="o">.</span><span class="n">dom</span><span class="o">.</span><span class="n">Document</span><span class="o">.</span>
-<span class="n">String</span> <span class="n">svgNS</span> <span class="o">=</span> <span class="s">&quot;http://www.w3.org/2000/svg&quot;</span><span class="p">;</span>
-<span class="n">Document</span> <span class="n">document</span> <span class="o">=</span> <span class="n">domImpl</span><span class="o">.</span><span class="n">createDocument</span><span class="p">(</span><span class="n">svgNS</span><span class="p">,</span> <span class="s">&quot;svg&quot;</span><span class="p">,</span> <span class="n">null</span><span class="p">);</span>
-
-<span class="sr">//</span> <span class="n">Create</span> <span class="n">an</span> <span class="n">instance</span> <span class="n">of</span> <span class="n">the</span> <span class="n">SVG</span> <span class="n">Generator</span><span class="o">.</span>
-<span class="n">SVGGraphics2D</span> <span class="n">svgGenerator</span> <span class="o">=</span> <span class="k">new</span> <span class="n">SVGGraphics2D</span><span class="p">(</span><span class="n">document</span><span class="p">);</span>
-</pre></div>
-
-
+<p>:::java
+// Get a DOMImplementation.
+DOMImplementation domImpl =
+    GenericDOMImplementation.getDOMImplementation();</p>
+<p>// Create an instance of org.w3c.dom.Document.
+String svgNS = "http://www.w3.org/2000/svg";
+Document document = domImpl.createDocument(svgNS, "svg", null);</p>
+<p>// Create an instance of the SVG Generator.
+SVGGraphics2D svgGenerator = new SVGGraphics2D(document);</p>
 </li>
 <li>
 <p>Invoke the rendering code on our SVG generator. In our example, we invoke <code>TestSVGGen</code> ‘s <code>paint</code> method:</p>
-<div class="codehilite"><pre><span class="sr">//</span> <span class="n">Ask</span> <span class="n">the</span> <span class="n">test</span> <span class="n">to</span> <span class="n">render</span> <span class="n">into</span> <span class="n">the</span> <span class="n">SVG</span> <span class="n">Graphics2D</span> <span class="n">implementation</span><span class="o">.</span>
-<span class="n">TestSVGGen</span> <span class="n">test</span> <span class="o">=</span> <span class="k">new</span> <span class="n">TestSVGGen</span><span class="p">();</span>
-<span class="n">test</span><span class="o">.</span><span class="n">paint</span><span class="p">(</span><span class="n">svgGenerator</span><span class="p">);</span>
-</pre></div>
-
-
+<p>:::java
+// Ask the test to render into the SVG Graphics2D implementation.
+TestSVGGen test = new TestSVGGen();
+test.paint(svgGenerator);</p>
 </li>
-<li>
-<p>Stream out the SVG content. The SVG generator can stream its content into any <code>java.io.Writer</code> . In our example, we stream the content to the standard output stream:</p>
-<div class="codehilite"><pre><span class="sr">//</span> <span class="n">Finally</span><span class="p">,</span> <span class="n">stream</span> <span class="n">out</span> <span class="n">SVG</span> <span class="n">to</span> <span class="n">the</span> <span class="n">standard</span> <span class="n">output</span> <span class="n">using</span>
-<span class="sr">//</span> <span class="n">UTF</span><span class="o">-</span><span class="mi">8</span> <span class="n">encoding</span><span class="o">.</span>
-<span class="n">boolean</span> <span class="n">useCSS</span> <span class="o">=</span> <span class="n">true</span><span class="p">;</span> <span class="sr">//</span> <span class="n">we</span> <span class="n">want</span> <span class="n">to</span> <span class="k">use</span> <span class="n">CSS</span> <span class="n">style</span> <span class="n">attributes</span>
-<span class="n">Writer</span> <span class="n">out</span> <span class="o">=</span> <span class="k">new</span> <span class="n">OutputStreamWriter</span><span class="p">(</span><span class="n">System</span><span class="o">.</span><span class="n">out</span><span class="p">,</span> <span class="s">&quot;UTF-8&quot;</span><span class="p">);</span>
-<span class="n">svgGenerator</span><span class="o">.</span><span class="n">stream</span><span class="p">(</span><span class="n">out</span><span class="p">,</span> <span class="n">useCSS</span><span class="p">);</span>
+</ol>
+<p>1.
+Stream out the SVG content. The SVG generator can stream its content into any <code>java.io.Writer</code> . In our example, we stream the content to the standard output stream:</p>
+<div class="codehilite"><pre><span class="c1">// Finally, stream out SVG to the standard output using</span>
+<span class="c1">// UTF-8 encoding.</span>
+<span class="kt">boolean</span> <span class="n">useCSS</span> <span class="o">=</span> <span class="kc">true</span><span class="o">;</span> <span class="c1">// we want to use CSS style attributes</span>
+<span class="n">Writer</span> <span class="n">out</span> <span class="o">=</span> <span class="k">new</span> <span class="n">OutputStreamWriter</span><span class="o">(</span><span class="n">System</span><span class="o">.</span><span class="na">out</span><span class="o">,</span> <span class="s">&quot;UTF-8&quot;</span><span class="o">);</span>
+<span class="n">svgGenerator</span><span class="o">.</span><span class="na">stream</span><span class="o">(</span><span class="n">out</span><span class="o">,</span> <span class="n">useCSS</span><span class="o">);</span>
 </pre></div>
 
 
-</li>
-</ol>
 <p>SVG has <a href="http://www.w3.org/TR/SVG11/styling.html#AlternativesForStyling">two ways to specify styling properties</a> , such as the fill color: presentation attributes (one XML attribute per property) or the CSS <code>style</code> attribute (any number of properties in one CSS inline stylesheet). The <code>useCss</code> parameter allows the user to control that option.</p>
-<h2 id="svg-generator-customization-wzxhzdk20wzxhzdk21">SVG Generator customization <a id="custom"></a></h2>
+<h2 id="svg-generator-customization-wzxhzdk18wzxhzdk19">SVG Generator customization <a id="custom"></a></h2>
 <p>In the previous section, we have just seen that the SVG generation process can be customized to output SVG styling properties as presentation attributes or CSS inline stylesheets. In this section we will talk about some examples of more advanced customizations.</p>
 <p>Instead of creating the <code>SVGGraphics2D</code> just by using the <code>Document</code> that will be used as a factory for creating the SVG elements, we can use the constructor that uses an <a href="../javadoc/org/apache/batik/svggen/SVGGeneratorContext.html">SVGGeneratorContext</a> instance. By providing your own <code>SVGGeneratorContext</code> instance, you will be able to do advanced customization. You will find below several examples of possible customizations.</p>
-<h3 id="have-your-own-comment-in-the-generated-svg-file-wzxhzdk22wzxhzdk23">Have your own comment in the generated SVG file <a id="Have+your+own+comment+in+the+generated+SVG+file"></a></h3>
+<h3 id="have-your-own-comment-in-the-generated-svg-file-wzxhzdk20wzxhzdk21">Have your own comment in the generated SVG file <a id="Have+your+own+comment+in+the+generated+SVG+file"></a></h3>
 <p>We begin with the simplest possible example. If you integrate the Batik SVG generator in your own Java application, you may want to specialize the comment generated in the XML code.</p>
 <div class="codehilite"><pre><span class="n">DOMImplementation</span> <span class="n">impl</span> <span class="o">=</span>
-    <span class="n">GenericDOMImplementation</span><span class="o">.</span><span class="n">getDOMImplementation</span><span class="p">();</span>
-<span class="n">String</span> <span class="n">svgNS</span> <span class="o">=</span> <span class="s">&quot;http://www.w3.org/2000/svg&quot;</span><span class="p">;</span>
-<span class="n">Document</span> <span class="n">myFactory</span> <span class="o">=</span> <span class="n">impl</span><span class="o">.</span><span class="n">createDocument</span><span class="p">(</span><span class="n">svgNS</span><span class="p">,</span> <span class="s">&quot;svg&quot;</span><span class="p">,</span> <span class="n">null</span><span class="p">);</span>
+    <span class="n">GenericDOMImplementation</span><span class="o">.</span><span class="na">getDOMImplementation</span><span class="o">();</span>
+<span class="n">String</span> <span class="n">svgNS</span> <span class="o">=</span> <span class="s">&quot;http://www.w3.org/2000/svg&quot;</span><span class="o">;</span>
+<span class="n">Document</span> <span class="n">myFactory</span> <span class="o">=</span> <span class="n">impl</span><span class="o">.</span><span class="na">createDocument</span><span class="o">(</span><span class="n">svgNS</span><span class="o">,</span> <span class="s">&quot;svg&quot;</span><span class="o">,</span> <span class="kc">null</span><span class="o">);</span>
 
-<span class="n">SVGGeneratorContext</span> <span class="n">ctx</span> <span class="o">=</span> <span class="n">SVGGeneratorContext</span><span class="o">.</span><span class="n">createDefault</span><span class="p">(</span><span class="n">myFactory</span><span class="p">);</span>
-<span class="n">ctx</span><span class="o">.</span><span class="n">setComment</span><span class="p">(</span><span class="s">&quot;Generated by FooApplication with Batik SVG Generator&quot;</span><span class="p">);</span>
-<span class="n">SVGGraphics2D</span> <span class="n">g2d</span> <span class="o">=</span> <span class="k">new</span> <span class="n">SVGGraphics2D</span><span class="p">(</span><span class="n">ctx</span><span class="p">,</span> <span class="n">false</span><span class="p">);</span>
+<span class="n">SVGGeneratorContext</span> <span class="n">ctx</span> <span class="o">=</span> <span class="n">SVGGeneratorContext</span><span class="o">.</span><span class="na">createDefault</span><span class="o">(</span><span class="n">myFactory</span><span class="o">);</span>
+<span class="n">ctx</span><span class="o">.</span><span class="na">setComment</span><span class="o">(</span><span class="s">&quot;Generated by FooApplication with Batik SVG Generator&quot;</span><span class="o">);</span>
+<span class="n">SVGGraphics2D</span> <span class="n">g2d</span> <span class="o">=</span> <span class="k">new</span> <span class="n">SVGGraphics2D</span><span class="o">(</span><span class="n">ctx</span><span class="o">,</span> <span class="kc">false</span><span class="o">);</span>
 </pre></div>
 
 
-<h2 id="use-embedded-svg-fonts-in-the-generated-svg-file-wzxhzdk24wzxhzdk25">Use embedded SVG Fonts in the generated SVG file <a id="Use+embedded+SVG+Fonts+in+the+generated+SVG+file"></a></h2>
+<h2 id="use-embedded-svg-fonts-in-the-generated-svg-file-wzxhzdk22wzxhzdk23">Use embedded SVG Fonts in the generated SVG file <a id="Use+embedded+SVG+Fonts+in+the+generated+SVG+file"></a></h2>
 <p>In order to have a self-contained SVG file that doesn't have to use system fonts to be displayed, you can embed the fonts you used for drawing strings in the SVG file through the SVG fonts facility.</p>
 <div class="codehilite"><pre><span class="n">DOMImplementation</span> <span class="n">impl</span> <span class="o">=</span>
-    <span class="n">GenericDOMImplementation</span><span class="o">.</span><span class="n">getDOMImplementation</span><span class="p">();</span>
-<span class="n">String</span> <span class="n">svgNS</span> <span class="o">=</span> <span class="s">&quot;http://www.w3.org/2000/svg&quot;</span><span class="p">;</span>
-<span class="n">Document</span> <span class="n">myFactory</span> <span class="o">=</span> <span class="n">impl</span><span class="o">.</span><span class="n">createDocument</span><span class="p">(</span><span class="n">svgNS</span><span class="p">,</span> <span class="s">&quot;svg&quot;</span><span class="p">,</span> <span class="n">null</span><span class="p">);</span>
+    <span class="n">GenericDOMImplementation</span><span class="o">.</span><span class="na">getDOMImplementation</span><span class="o">();</span>
+<span class="n">String</span> <span class="n">svgNS</span> <span class="o">=</span> <span class="s">&quot;http://www.w3.org/2000/svg&quot;</span><span class="o">;</span>
+<span class="n">Document</span> <span class="n">myFactory</span> <span class="o">=</span> <span class="n">impl</span><span class="o">.</span><span class="na">createDocument</span><span class="o">(</span><span class="n">svgNS</span><span class="o">,</span> <span class="s">&quot;svg&quot;</span><span class="o">,</span> <span class="kc">null</span><span class="o">);</span>
 
-<span class="n">SVGGeneratorContext</span> <span class="n">ctx</span> <span class="o">=</span> <span class="n">SVGGeneratorContext</span><span class="o">.</span><span class="n">createDefault</span><span class="p">(</span><span class="n">myFactory</span><span class="p">);</span>
-<span class="n">ctx</span><span class="o">.</span><span class="n">setEmbeddedFontsOn</span><span class="p">(</span><span class="n">true</span><span class="p">);</span>
-<span class="n">SVGGraphics2D</span> <span class="n">g2d</span> <span class="o">=</span> <span class="k">new</span> <span class="n">SVGGraphics2D</span><span class="p">(</span><span class="n">ctx</span><span class="p">,</span> <span class="n">true</span><span class="p">);</span>
+<span class="n">SVGGeneratorContext</span> <span class="n">ctx</span> <span class="o">=</span> <span class="n">SVGGeneratorContext</span><span class="o">.</span><span class="na">createDefault</span><span class="o">(</span><span class="n">myFactory</span><span class="o">);</span>
+<span class="n">ctx</span><span class="o">.</span><span class="na">setEmbeddedFontsOn</span><span class="o">(</span><span class="kc">true</span><span class="o">);</span>
+<span class="n">SVGGraphics2D</span> <span class="n">g2d</span> <span class="o">=</span> <span class="k">new</span> <span class="n">SVGGraphics2D</span><span class="o">(</span><span class="n">ctx</span><span class="o">,</span> <span class="kc">true</span><span class="o">);</span>
 </pre></div>
 
 
-<h2 id="customizing-the-way-images-are-stored-wzxhzdk26wzxhzdk27">Customizing the way images are stored <a id="Customizing+the+way+images+are+stored"></a></h2>
+<h2 id="customizing-the-way-images-are-stored-wzxhzdk24wzxhzdk25">Customizing the way images are stored <a id="Customizing+the+way+images+are+stored"></a></h2>
 <p>Every time you call one of the <code>drawImage</code> methods provided by the <code>Graphics2D</code> interface, a default representation of your image is created in a location and put in a default file. For instance, a base64 encoding is created and embedded in the SVG file by default. Alternatively, you can choose to have your images written to separate files in a predefined directory, in one of the two raster formats required by the SVG specification: JPEG or PNG.</p>
 <p>You can change the default behavior by explicitly providing the image handler to be used by the SVG generator. Once again, you use the <code>SVGGeneratorContext</code> for this. In the example below, all images are converted to PNG format and written to directory <code>res/images</code> .</p>
 <div class="codehilite"><pre><span class="n">DOMImplementation</span> <span class="n">impl</span> <span class="o">=</span>
-    <span class="n">GenericDOMImplementation</span><span class="o">.</span><span class="n">getDOMImplementation</span><span class="p">();</span>
-<span class="n">String</span> <span class="n">svgNS</span> <span class="o">=</span> <span class="s">&quot;http://www.w3.org/2000/svg&quot;</span><span class="p">;</span>
-<span class="n">Document</span> <span class="n">myFactory</span> <span class="o">=</span> <span class="n">impl</span><span class="o">.</span><span class="n">createDocument</span><span class="p">(</span><span class="n">svgNS</span><span class="p">,</span> <span class="s">&quot;svg&quot;</span><span class="p">,</span> <span class="n">null</span><span class="p">);</span>
-
-<span class="n">SVGGeneratorContext</span> <span class="n">ctx</span> <span class="o">=</span> <span class="n">SVGGeneratorContext</span><span class="o">.</span><span class="n">createDefault</span><span class="p">(</span><span class="n">myFactory</span><span class="p">);</span>
-<span class="n">GenericImageHandler</span> <span class="n">ihandler</span> <span class="o">=</span> <span class="k">new</span> <span class="n">ImageHandlerPNGEncoder</span><span class="p">(</span><span class="s">&quot;res/images&quot;</span><span class="p">,</span> <span class="n">null</span><span class="p">);</span>
-<span class="n">ctx</span><span class="o">.</span><span class="n">setImageHandler</span><span class="p">(</span><span class="n">ihandler</span><span class="p">);</span>
-<span class="n">SVGGraphics2D</span> <span class="n">g2d</span> <span class="o">=</span> <span class="k">new</span> <span class="n">SVGGraphics2D</span><span class="p">(</span><span class="n">ctx</span><span class="p">,</span> <span class="n">false</span><span class="p">);</span>
+    <span class="n">GenericDOMImplementation</span><span class="o">.</span><span class="na">getDOMImplementation</span><span class="o">();</span>
+<span class="n">String</span> <span class="n">svgNS</span> <span class="o">=</span> <span class="s">&quot;http://www.w3.org/2000/svg&quot;</span><span class="o">;</span>
+<span class="n">Document</span> <span class="n">myFactory</span> <span class="o">=</span> <span class="n">impl</span><span class="o">.</span><span class="na">createDocument</span><span class="o">(</span><span class="n">svgNS</span><span class="o">,</span> <span class="s">&quot;svg&quot;</span><span class="o">,</span> <span class="kc">null</span><span class="o">);</span>
+
+<span class="n">SVGGeneratorContext</span> <span class="n">ctx</span> <span class="o">=</span> <span class="n">SVGGeneratorContext</span><span class="o">.</span><span class="na">createDefault</span><span class="o">(</span><span class="n">myFactory</span><span class="o">);</span>
+<span class="n">GenericImageHandler</span> <span class="n">ihandler</span> <span class="o">=</span> <span class="k">new</span> <span class="n">ImageHandlerPNGEncoder</span><span class="o">(</span><span class="s">&quot;res/images&quot;</span><span class="o">,</span> <span class="kc">null</span><span class="o">);</span>
+<span class="n">ctx</span><span class="o">.</span><span class="na">setImageHandler</span><span class="o">(</span><span class="n">ihandler</span><span class="o">);</span>
+<span class="n">SVGGraphics2D</span> <span class="n">g2d</span> <span class="o">=</span> <span class="k">new</span> <span class="n">SVGGraphics2D</span><span class="o">(</span><span class="n">ctx</span><span class="o">,</span> <span class="kc">false</span><span class="o">);</span>
 </pre></div>
 
 
 <p>Using the default image handlers results in a new copy of the image data being written to the SVG file or an external file, for every single <code>drawImage</code> call. If you use the same images over and over again, then this may result in an SVG file containing a lot of redundant data. At the price of a slight performance penalty during initial generation of the SVG DOM tree, you can choose to have your image data reused. For this you use a specialized image handler, as shown below.</p>
 <div class="codehilite"><pre><span class="n">DOMImplementation</span> <span class="n">impl</span> <span class="o">=</span>
-    <span class="n">GenericDOMImplementation</span><span class="o">.</span><span class="n">getDOMImplementation</span><span class="p">();</span>
-<span class="n">String</span> <span class="n">svgNS</span> <span class="o">=</span> <span class="s">&quot;http://www.w3.org/2000/svg&quot;</span><span class="p">;</span>
-<span class="n">Document</span> <span class="n">myFactory</span> <span class="o">=</span> <span class="n">impl</span><span class="o">.</span><span class="n">createDocument</span><span class="p">(</span><span class="n">svgNS</span><span class="p">,</span> <span class="s">&quot;svg&quot;</span><span class="p">,</span> <span class="n">null</span><span class="p">);</span>
+    <span class="n">GenericDOMImplementation</span><span class="o">.</span><span class="na">getDOMImplementation</span><span class="o">();</span>
+<span class="n">String</span> <span class="n">svgNS</span> <span class="o">=</span> <span class="s">&quot;http://www.w3.org/2000/svg&quot;</span><span class="o">;</span>
+<span class="n">Document</span> <span class="n">myFactory</span> <span class="o">=</span> <span class="n">impl</span><span class="o">.</span><span class="na">createDocument</span><span class="o">(</span><span class="n">svgNS</span><span class="o">,</span> <span class="s">&quot;svg&quot;</span><span class="o">,</span> <span class="kc">null</span><span class="o">);</span>
 
-<span class="n">SVGGeneratorContext</span> <span class="n">ctx</span> <span class="o">=</span> <span class="n">SVGGeneratorContext</span><span class="o">.</span><span class="n">createDefault</span><span class="p">(</span><span class="n">myFactory</span><span class="p">);</span>
+<span class="n">SVGGeneratorContext</span> <span class="n">ctx</span> <span class="o">=</span> <span class="n">SVGGeneratorContext</span><span class="o">.</span><span class="na">createDefault</span><span class="o">(</span><span class="n">myFactory</span><span class="o">);</span>
 
-<span class="sr">//</span> <span class="n">Reuse</span> <span class="k">our</span> <span class="n">embedded</span> <span class="n">base64</span><span class="o">-</span><span class="n">encoded</span> <span class="n">image</span> <span class="n">data</span><span class="o">.</span>
-<span class="n">GenericImageHandler</span> <span class="n">ihandler</span> <span class="o">=</span> <span class="k">new</span> <span class="n">CachedImageHandlerBase64Encoder</span><span class="p">();</span>
-<span class="n">ctx</span><span class="o">.</span><span class="n">setGenericImageHandler</span><span class="p">(</span><span class="n">ihandler</span><span class="p">);</span>
+<span class="c1">// Reuse our embedded base64-encoded image data.</span>
+<span class="n">GenericImageHandler</span> <span class="n">ihandler</span> <span class="o">=</span> <span class="k">new</span> <span class="n">CachedImageHandlerBase64Encoder</span><span class="o">();</span>
+<span class="n">ctx</span><span class="o">.</span><span class="na">setGenericImageHandler</span><span class="o">(</span><span class="n">ihandler</span><span class="o">);</span>
 
-<span class="n">SVGGraphics2D</span> <span class="n">g2d</span> <span class="o">=</span> <span class="k">new</span> <span class="n">SVGGraphics2D</span><span class="p">(</span><span class="n">ctx</span><span class="p">,</span> <span class="n">false</span><span class="p">);</span>
+<span class="n">SVGGraphics2D</span> <span class="n">g2d</span> <span class="o">=</span> <span class="k">new</span> <span class="n">SVGGraphics2D</span><span class="o">(</span><span class="n">ctx</span><span class="o">,</span> <span class="kc">false</span><span class="o">);</span>
 </pre></div>
 
 
 <p>With the caching image handlers, it is even possible to reuse the same copy of your image data across several different SVG documents. Just keep a reference to the image handler, and pass it to the <code>SVGGraphics2D</code> instance used for generating the SVG DOM tree. The following simplified example shows how different SVG trees might be created by separate SVG generators, efficiently storing any common images just once.</p>
-<div class="codehilite"><pre><span class="n">class</span> <span class="n">MySVGGenerator</span> <span class="p">{</span>
+<div class="codehilite"><pre><span class="kd">class</span> <span class="nc">MySVGGenerator</span> <span class="o">{</span>
 
-    <span class="sr">//</span> <span class="n">The</span> <span class="n">image</span> <span class="n">handler</span> <span class="n">will</span> <span class="nb">write</span> <span class="n">all</span> <span class="n">images</span> <span class="n">files</span> <span class="n">to</span> <span class="s">&quot;res/images&quot;</span><span class="o">.</span>
-    <span class="n">private</span> <span class="n">static</span> <span class="n">ImageHandler</span> <span class="n">ihandler</span> <span class="o">=</span>
-        <span class="k">new</span> <span class="n">CachedImageHandlerPNGEncoder</span><span class="p">(</span><span class="s">&quot;res/images&quot;</span><span class="p">,</span> <span class="n">null</span><span class="p">);</span>
+  <span class="c1">// The image handler will write all images files to &quot;res/images&quot;.</span>
+  <span class="kd">private</span> <span class="kd">static</span> <span class="n">ImageHandler</span> <span class="n">ihandler</span> <span class="o">=</span>
+    <span class="k">new</span> <span class="nf">CachedImageHandlerPNGEncoder</span><span class="o">(</span><span class="s">&quot;res/images&quot;</span><span class="o">,</span> <span class="kc">null</span><span class="o">);</span>
 
-    <span class="n">public</span> <span class="n">void</span> <span class="n">generateSVG</span><span class="p">(</span><span class="n">JPanel</span> <span class="n">myCanvas</span><span class="p">,</span> <span class="n">OutputStream</span> <span class="n">outStream</span><span class="p">)</span> <span class="p">{</span>
-        <span class="n">DOMImplementation</span> <span class="n">domImpl</span> <span class="o">=</span>
-            <span class="n">GenericDOMImplementation</span><span class="o">.</span><span class="n">getDOMImplementation</span><span class="p">();</span>
-        <span class="n">Document</span> <span class="n">myFactory</span> <span class="o">=</span> <span class="n">domImpl</span><span class="o">.</span><span class="n">createDocument</span><span class="p">(</span><span class="n">svgNS</span><span class="p">,</span> <span class="s">&quot;svg&quot;</span><span class="p">,</span> <span class="n">null</span><span class="p">);</span>
-        <span class="n">SVGGeneratorContext</span> <span class="n">ctx</span> <span class="o">=</span>
-            <span class="n">SVGGeneratorContext</span><span class="o">.</span><span class="n">createDefault</span><span class="p">(</span><span class="n">myFactory</span><span class="p">);</span>
-        <span class="n">ctx</span><span class="o">.</span><span class="n">setGenericImageHandler</span><span class="p">(</span><span class="n">ihandler</span><span class="p">);</span>
+  <span class="kd">public</span> <span class="kt">void</span> <span class="nf">generateSVG</span><span class="o">(</span><span class="n">JPanel</span> <span class="n">myCanvas</span><span class="o">,</span> <span class="n">OutputStream</span> <span class="n">outStream</span><span class="o">)</span> <span class="o">{</span>
+    <span class="n">DOMImplementation</span> <span class="n">domImpl</span> <span class="o">=</span>
+      <span class="n">GenericDOMImplementation</span><span class="o">.</span><span class="na">getDOMImplementation</span><span class="o">();</span>
+    <span class="n">Document</span> <span class="n">myFactory</span> <span class="o">=</span> <span class="n">domImpl</span><span class="o">.</span><span class="na">createDocument</span><span class="o">(</span><span class="n">svgNS</span><span class="o">,</span> <span class="s">&quot;svg&quot;</span><span class="o">,</span> <span class="kc">null</span><span class="o">);</span>
+    <span class="n">SVGGeneratorContext</span> <span class="n">ctx</span> <span class="o">=</span>
+      <span class="n">SVGGeneratorContext</span><span class="o">.</span><span class="na">createDefault</span><span class="o">(</span><span class="n">myFactory</span><span class="o">);</span>
+    <span class="n">ctx</span><span class="o">.</span><span class="na">setGenericImageHandler</span><span class="o">(</span><span class="n">ihandler</span><span class="o">);</span>
 
-        <span class="n">SVGGraphics2D</span> <span class="n">svgGenerator</span> <span class="o">=</span> <span class="k">new</span> <span class="n">SVGGraphics2D</span><span class="p">(</span><span class="n">ctx</span><span class="p">,</span> <span class="n">false</span><span class="p">);</span>
+    <span class="n">SVGGraphics2D</span> <span class="n">svgGenerator</span> <span class="o">=</span> <span class="k">new</span> <span class="n">SVGGraphics2D</span><span class="o">(</span><span class="n">ctx</span><span class="o">,</span> <span class="kc">false</span><span class="o">);</span>
 
-        <span class="sr">//</span> <span class="n">Create</span> <span class="n">the</span> <span class="n">SVG</span> <span class="n">DOM</span> <span class="n">tree</span><span class="o">.</span>
-        <span class="n">myCanvas</span><span class="o">.</span><span class="n">paintComponent</span><span class="p">(</span><span class="n">svgGenerator</span><span class="p">);</span>
+    <span class="c1">// Create the SVG DOM tree.</span>
+    <span class="n">myCanvas</span><span class="o">.</span><span class="na">paintComponent</span><span class="o">(</span><span class="n">svgGenerator</span><span class="o">);</span>
 
-        <span class="n">Writer</span> <span class="n">out</span> <span class="o">=</span> <span class="k">new</span> <span class="n">OutputStreamWriter</span><span class="p">(</span><span class="n">outStream</span><span class="p">,</span> <span class="s">&quot;UTF-8&quot;</span><span class="p">);</span>
-        <span class="n">svgGenerator</span><span class="o">.</span><span class="n">stream</span><span class="p">(</span><span class="n">out</span><span class="p">,</span> <span class="n">true</span><span class="p">);</span>
-    <span class="p">}</span>
-<span class="p">}</span>
+    <span class="n">Writer</span> <span class="n">out</span> <span class="o">=</span> <span class="k">new</span> <span class="n">OutputStreamWriter</span><span class="o">(</span><span class="n">outStream</span><span class="o">,</span> <span class="s">&quot;UTF-8&quot;</span><span class="o">);</span>
+    <span class="n">svgGenerator</span><span class="o">.</span><span class="na">stream</span><span class="o">(</span><span class="n">out</span><span class="o">,</span> <span class="kc">true</span><span class="o">);</span>
+  <span class="o">}</span>
+<span class="o">}</span>
 </pre></div>
 
 
-<h2 id="customizing-the-generated-svg-style-wzxhzdk28wzxhzdk29">Customizing the generated SVG style <a id="Customizing+the+generated+SVG+style"></a></h2>
+<h2 id="customizing-the-generated-svg-style-wzxhzdk26wzxhzdk27">Customizing the generated SVG style <a id="Customizing+the+generated+SVG+style"></a></h2>
 <p>Your needs in matter of styling may be different from the two provided options (XML presentation attributes or CSS inline stylesheets). For example, you may want to put the CSS properties in a SVG <code>style</code> element section and reference them through the class attribute. In this case you will need to define a new <a href="../javadoc/org/apache/batik/svggen/StyleHandler.html">StyleHandler</a> as below.</p>
-<div class="codehilite"><pre><span class="n">public</span> <span class="n">class</span> <span class="n">StyleSheetStyleHandler</span> <span class="n">implements</span> <span class="n">StyleHandler</span> <span class="p">{</span>
+<div class="codehilite"><pre><span class="kd">public</span> <span class="kd">class</span> <span class="nc">StyleSheetStyleHandler</span> <span class="kd">implements</span> <span class="n">StyleHandler</span> <span class="o">{</span>
 
-    <span class="sr">//</span> <span class="n">The</span> <span class="n">CDATA</span> <span class="n">section</span> <span class="n">that</span> <span class="n">holds</span> <span class="n">the</span> <span class="n">CSS</span> <span class="n">stylesheet</span><span class="o">.</span>
-    <span class="n">private</span> <span class="n">CDATASection</span> <span class="n">styleSheet</span><span class="p">;</span>
+  <span class="c1">// The CDATA section that holds the CSS stylesheet.</span>
+  <span class="kd">private</span> <span class="n">CDATASection</span> <span class="n">styleSheet</span><span class="o">;</span>
 
-    <span class="sr">//</span> <span class="n">Build</span> <span class="n">the</span> <span class="n">handler</span> <span class="n">with</span> <span class="n">a</span> <span class="n">reference</span> <span class="n">to</span> <span class="n">the</span> <span class="n">stylesheet</span> <span class="n">section</span><span class="o">.</span>
-    <span class="n">public</span> <span class="n">StyleSheetStyleHandler</span><span class="p">(</span><span class="n">CDATASection</span> <span class="n">styleSheet</span><span class="p">)</span> <span class="p">{</span>
-        <span class="n">this</span><span class="o">.</span><span class="n">styleSheet</span> <span class="o">=</span> <span class="n">styleSheet</span><span class="p">;</span>
-    <span class="p">}</span>
-
-    <span class="n">public</span> <span class="n">void</span> <span class="n">setStyle</span><span class="p">(</span><span class="n">Element</span> <span class="n">element</span><span class="p">,</span> <span class="n">Map</span> <span class="n">styleMap</span><span class="p">,</span>
-                         <span class="n">SVGGeneratorContext</span> <span class="n">generatorContext</span><span class="p">)</span> <span class="p">{</span>
-        <span class="n">Iterator</span> <span class="n">iter</span> <span class="o">=</span> <span class="n">styleMap</span><span class="o">.</span><span class="n">keySet</span><span class="p">()</span><span class="o">.</span><span class="n">iterator</span><span class="p">();</span>
-
-        <span class="sr">//</span> <span class="n">Create</span> <span class="n">a</span> <span class="k">new</span> <span class="n">class</span> <span class="n">in</span> <span class="n">the</span> <span class="n">style</span> <span class="n">sheet</span><span class="o">.</span>
-        <span class="n">String</span> <span class="n">id</span> <span class="o">=</span> <span class="n">generatorContext</span><span class="o">.</span><span class="n">getIDGenerator</span><span class="p">()</span><span class="o">.</span><span class="n">generateID</span><span class="p">(</span><span class="s">&quot;C&quot;</span><span class="p">);</span>
-        <span class="n">styleSheet</span><span class="o">.</span><span class="n">appendData</span><span class="p">(</span><span class="s">&quot;.&quot;</span><span class="o">+</span> <span class="n">id</span> <span class="o">+</span><span class="s">&quot; {&quot;</span><span class="p">);</span>
-
-        <span class="sr">//</span> <span class="n">Append</span> <span class="nb">each</span> <span class="n">key</span><span class="o">/</span><span class="n">value</span> <span class="n">pair</span><span class="o">.</span>
-        <span class="k">while</span> <span class="p">(</span><span class="n">iter</span><span class="o">.</span><span class="n">hasNext</span><span class="p">())</span> <span class="p">{</span>
-            <span class="n">String</span> <span class="n">key</span> <span class="o">=</span> <span class="p">(</span><span class="n">String</span><span class="p">)</span> <span class="n">iter</span><span class="o">.</span><span class="k">next</span><span class="p">();</span>
-            <span class="n">String</span> <span class="n">value</span> <span class="o">=</span> <span class="p">(</span><span class="n">String</span><span class="p">)</span> <span class="n">styleMap</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">key</span><span class="p">);</span>
-            <span class="n">styleSheet</span><span class="o">.</span><span class="n">appendData</span><span class="p">(</span><span class="n">key</span> <span class="o">+</span> <span class="s">&quot;:&quot;</span> <span class="o">+</span> <span class="n">value</span> <span class="o">+</span> <span class="s">&quot;;&quot;</span><span class="p">);</span>
-        <span class="p">}</span>
-
-        <span class="n">styleSheet</span><span class="o">.</span><span class="n">appendData</span><span class="p">(</span><span class="s">&quot;}\n&quot;</span><span class="p">);</span>
-
-        <span class="sr">//</span> <span class="n">Reference</span> <span class="n">the</span> <span class="n">stylesheet</span> <span class="n">class</span> <span class="n">on</span> <span class="n">the</span> <span class="n">element</span> <span class="n">to</span> <span class="n">be</span> <span class="n">styled</span><span class="o">.</span>
-        <span class="n">element</span><span class="o">.</span><span class="n">setAttributeNS</span><span class="p">(</span><span class="n">null</span><span class="p">,</span> <span class="s">&quot;class&quot;</span><span class="p">,</span> <span class="n">id</span><span class="p">);</span>
-    <span class="p">}</span>
-<span class="p">}</span>
+  <span class="c1">// Build the handler with a reference to the stylesheet section.</span>
+  <span class="kd">public</span> <span class="nf">StyleSheetStyleHandler</span><span class="o">(</span><span class="n">CDATASection</span> <span class="n">styleSheet</span><span class="o">)</span> <span class="o">{</span>
+    <span class="k">this</span><span class="o">.</span><span class="na">styleSheet</span> <span class="o">=</span> <span class="n">styleSheet</span><span class="o">;</span>
+  <span class="o">}</span>
+
+  <span class="kd">public</span> <span class="kt">void</span> <span class="nf">setStyle</span><span class="o">(</span><span class="n">Element</span> <span class="n">element</span><span class="o">,</span> <span class="n">Map</span> <span class="n">styleMap</span><span class="o">,</span>
+             <span class="n">SVGGeneratorContext</span> <span class="n">generatorContext</span><span class="o">)</span> <span class="o">{</span>
+    <span class="n">Iterator</span> <span class="n">iter</span> <span class="o">=</span> <span class="n">styleMap</span><span class="o">.</span><span class="na">keySet</span><span class="o">().</span><span class="na">iterator</span><span class="o">();</span>
+
+    <span class="c1">// Create a new class in the style sheet.</span>
+    <span class="n">String</span> <span class="n">id</span> <span class="o">=</span> <span class="n">generatorContext</span><span class="o">.</span><span class="na">getIDGenerator</span><span class="o">().</span><span class="na">generateID</span><span class="o">(</span><span class="s">&quot;C&quot;</span><span class="o">);</span>
+    <span class="n">styleSheet</span><span class="o">.</span><span class="na">appendData</span><span class="o">(</span><span class="s">&quot;.&quot;</span><span class="o">+</span> <span class="n">id</span> <span class="o">+</span><span class="s">&quot; {&quot;</span><span class="o">);</span>
+
+    <span class="c1">// Append each key/value pair.</span>
+    <span class="k">while</span> <span class="o">(</span><span class="n">iter</span><span class="o">.</span><span class="na">hasNext</span><span class="o">())</span> <span class="o">{</span>
+      <span class="n">String</span> <span class="n">key</span> <span class="o">=</span> <span class="o">(</span><span class="n">String</span><span class="o">)</span> <span class="n">iter</span><span class="o">.</span><span class="na">next</span><span class="o">();</span>
+      <span class="n">String</span> <span class="n">value</span> <span class="o">=</span> <span class="o">(</span><span class="n">String</span><span class="o">)</span> <span class="n">styleMap</span><span class="o">.</span><span class="na">get</span><span class="o">(</span><span class="n">key</span><span class="o">);</span>
+      <span class="n">styleSheet</span><span class="o">.</span><span class="na">appendData</span><span class="o">(</span><span class="n">key</span> <span class="o">+</span> <span class="s">&quot;:&quot;</span> <span class="o">+</span> <span class="n">value</span> <span class="o">+</span> <span class="s">&quot;;&quot;</span><span class="o">);</span>
+    <span class="o">}</span>
+
+    <span class="n">styleSheet</span><span class="o">.</span><span class="na">appendData</span><span class="o">(</span><span class="s">&quot;}\n&quot;</span><span class="o">);</span>
+
+    <span class="c1">// Reference the stylesheet class on the element to be styled.</span>
+    <span class="n">element</span><span class="o">.</span><span class="na">setAttributeNS</span><span class="o">(</span><span class="kc">null</span><span class="o">,</span> <span class="s">&quot;class&quot;</span><span class="o">,</span> <span class="n">id</span><span class="o">);</span>
+  <span class="o">}</span>
+<span class="o">}</span>
 </pre></div>
 
 
 <p>Then you can create and use an <code>SVGGraphics2D</code> with a correctly configured <code>SVGGeneratorContext</code> .</p>
-<div class="codehilite"><pre><span class="sr">//</span> <span class="n">Configure</span> <span class="n">the</span> <span class="n">SVGGraphics2D</span> <span class="k">for</span> <span class="n">a</span> <span class="n">given</span> <span class="n">Document</span> <span class="n">myFactory</span><span class="o">.</span>
-<span class="n">SVGGeneratorContext</span> <span class="n">ctx</span> <span class="o">=</span> <span class="n">SVGGeneratorContext</span><span class="o">.</span><span class="n">createDefault</span><span class="p">(</span><span class="n">myFactory</span><span class="p">);</span>
-<span class="n">CDATASection</span> <span class="n">styleSheet</span> <span class="o">=</span> <span class="n">myFactory</span><span class="o">.</span><span class="n">createCDATASection</span><span class="p">(</span><span class="s">&quot;&quot;</span><span class="p">);</span>
-<span class="n">ctx</span><span class="o">.</span><span class="n">setStyleHandler</span><span class="p">(</span><span class="k">new</span> <span class="n">StyleSheetStyleHandler</span><span class="p">(</span><span class="n">styleSheet</span><span class="p">));</span>
-<span class="n">SVGGraphics2D</span> <span class="n">g2d</span> <span class="o">=</span> <span class="k">new</span> <span class="n">SVGGraphics2D</span><span class="p">(</span><span class="n">ctx</span><span class="p">,</span> <span class="n">false</span><span class="p">);</span>
+<div class="codehilite"><pre><span class="c1">// Configure the SVGGraphics2D for a given Document myFactory.</span>
+<span class="n">SVGGeneratorContext</span> <span class="n">ctx</span> <span class="o">=</span> <span class="n">SVGGeneratorContext</span><span class="o">.</span><span class="na">createDefault</span><span class="o">(</span><span class="n">myFactory</span><span class="o">);</span>
+<span class="n">CDATASection</span> <span class="n">styleSheet</span> <span class="o">=</span> <span class="n">myFactory</span><span class="o">.</span><span class="na">createCDATASection</span><span class="o">(</span><span class="s">&quot;&quot;</span><span class="o">);</span>
+<span class="n">ctx</span><span class="o">.</span><span class="na">setStyleHandler</span><span class="o">(</span><span class="k">new</span> <span class="n">StyleSheetStyleHandler</span><span class="o">(</span><span class="n">styleSheet</span><span class="o">));</span>
+<span class="n">SVGGraphics2D</span> <span class="n">g2d</span> <span class="o">=</span> <span class="k">new</span> <span class="n">SVGGraphics2D</span><span class="o">(</span><span class="n">ctx</span><span class="o">,</span> <span class="kc">false</span><span class="o">);</span>
 
-<span class="sr">//</span> <span class="n">Use</span> <span class="n">the</span> <span class="n">g2d</span> <span class="n">to</span> <span class="n">draw</span> <span class="p">(</span><span class="n">e</span><span class="o">.</span><span class="n">g</span><span class="o">.</span><span class="p">,</span> <span class="n">component</span><span class="o">.</span><span class="n">paint</span><span class="p">(</span><span class="n">g2d</span><span class="p">))</span><span class="o">.</span>
+<span class="c1">// Use the g2d to draw (e.g., component.paint(g2d)).</span>
 
-<span class="sr">//</span> <span class="n">Add</span> <span class="n">a</span> <span class="n">stylesheet</span> <span class="n">to</span> <span class="n">the</span> <span class="n">definition</span> <span class="n">section</span><span class="o">.</span>
-<span class="n">SVGSVGElement</span> <span class="n">root</span> <span class="o">=</span> <span class="p">(</span><span class="n">SVGSVGElement</span><span class="p">)</span> <span class="n">g2d</span><span class="o">.</span><span class="n">getRoot</span><span class="p">();</span>
-<span class="n">Element</span> <span class="n">defs</span> <span class="o">=</span> <span class="n">root</span><span class="o">.</span><span class="n">getElementById</span><span class="p">(</span><span class="n">SVGSyntax</span><span class="o">.</span><span class="n">ID_PREFIX_GENERIC_DEFS</span><span class="p">);</span>
-<span class="n">Element</span> <span class="n">style</span> <span class="o">=</span> <span class="n">myFactory</span><span class="o">.</span><span class="n">createElementNS</span>
-    <span class="p">(</span><span class="n">SVGSyntax</span><span class="o">.</span><span class="n">SVG_NAMESPACE_URI</span><span class="p">,</span> <span class="n">SVGSyntax</span><span class="o">.</span><span class="n">SVG_STYLE_TAG</span><span class="p">);</span>
-<span class="n">style</span><span class="o">.</span><span class="n">setAttributeNS</span><span class="p">(</span><span class="n">null</span><span class="p">,</span> <span class="n">SVGSyntax</span><span class="o">.</span><span class="n">SVG_TYPE_ATTRIBUTE</span><span class="p">,</span> <span class="s">&quot;text/css&quot;</span><span class="p">);</span>
-<span class="n">style</span><span class="o">.</span><span class="n">appendChild</span><span class="p">(</span><span class="n">styleSheet</span><span class="p">);</span>
-<span class="n">defs</span><span class="o">.</span><span class="n">appendChild</span><span class="p">(</span><span class="n">style</span><span class="p">);</span>
+<span class="c1">// Add a stylesheet to the definition section.</span>
+<span class="n">SVGSVGElement</span> <span class="n">root</span> <span class="o">=</span> <span class="o">(</span><span class="n">SVGSVGElement</span><span class="o">)</span> <span class="n">g2d</span><span class="o">.</span><span class="na">getRoot</span><span class="o">();</span>
+<span class="n">Element</span> <span class="n">defs</span> <span class="o">=</span> <span class="n">root</span><span class="o">.</span><span class="na">getElementById</span><span class="o">(</span><span class="n">SVGSyntax</span><span class="o">.</span><span class="na">ID_PREFIX_GENERIC_DEFS</span><span class="o">);</span>
+<span class="n">Element</span> <span class="n">style</span> <span class="o">=</span> <span class="n">myFactory</span><span class="o">.</span><span class="na">createElementNS</span>
+  <span class="o">(</span><span class="n">SVGSyntax</span><span class="o">.</span><span class="na">SVG_NAMESPACE_URI</span><span class="o">,</span> <span class="n">SVGSyntax</span><span class="o">.</span><span class="na">SVG_STYLE_TAG</span><span class="o">);</span>
+<span class="n">style</span><span class="o">.</span><span class="na">setAttributeNS</span><span class="o">(</span><span class="kc">null</span><span class="o">,</span> <span class="n">SVGSyntax</span><span class="o">.</span><span class="na">SVG_TYPE_ATTRIBUTE</span><span class="o">,</span> <span class="s">&quot;text/css&quot;</span><span class="o">);</span>
+<span class="n">style</span><span class="o">.</span><span class="na">appendChild</span><span class="o">(</span><span class="n">styleSheet</span><span class="o">);</span>
+<span class="n">defs</span><span class="o">.</span><span class="na">appendChild</span><span class="o">(</span><span class="n">style</span><span class="o">);</span>
 
-<span class="sr">//</span> <span class="n">Dump</span> <span class="n">the</span> <span class="n">root</span> <span class="n">content</span> <span class="n">to</span> <span class="n">a</span> <span class="n">given</span> <span class="n">Writer</span> <span class="n">myWriter</span><span class="o">.</span>
-<span class="n">g2d</span><span class="o">.</span><span class="n">stream</span><span class="p">(</span><span class="n">root</span><span class="p">,</span> <span class="n">myWriter</span><span class="p">);</span>
+<span class="c1">// Dump the root content to a given Writer myWriter.</span>
+<span class="n">g2d</span><span class="o">.</span><span class="na">stream</span><span class="o">(</span><span class="n">root</span><span class="o">,</span> <span class="n">myWriter</span><span class="o">);</span>
 </pre></div>
 
 
-<h2 id="extending-paint-object-to-svg-element-translation-wzxhzdk30wzxhzdk31">Extending Paint object to SVG element translation <a id="Extending+Paint+object+to+SVG+element+translation"></a></h2>
+<h2 id="extending-paint-object-to-svg-element-translation-wzxhzdk28wzxhzdk29">Extending Paint object to SVG element translation <a id="Extending+Paint+object+to+SVG+element+translation"></a></h2>
 <p>The <code>SVGGraphics2D</code> is able to generate SVG elements for generic Java 2D objects, but you sometimes have your own classes such as implementations of the Java 2D <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/awt/Paint.html">Paint</a> interface. In this case, you will need to write an <a href="../javadoc/org/apache/batik/svggen/ExtensionHandler.html">ExtensionHandler</a> that you will set on your <code>SVGGeneratorContext</code> .</p>
 <p>In the following example we define the first draft of an <code>ExtensionHandler</code> allowing to translate a Batik implementation of the <code>Paint</code> interface named <a href="../javadoc/org/apache/batik/ext/awt/LinearGradientPaint.html">LinearGradientPaint</a> .</p>
-<div class="codehilite"><pre><span class="n">class</span> <span class="n">MyExtensionHandler</span> <span class="n">extends</span> <span class="n">DefaultExtensionHandler</span> <span class="p">{</span>
+<div class="codehilite"><pre><span class="kd">class</span> <span class="nc">MyExtensionHandler</span> <span class="kd">extends</span> <span class="n">DefaultExtensionHandler</span> <span class="o">{</span>
 
-    <span class="n">public</span> <span class="n">SVGPaintDescriptor</span> <span class="n">handlePaint</span><span class="p">(</span><span class="n">Paint</span> <span class="n">paint</span><span class="p">,</span>
-                                          <span class="n">SVGGeneratorContext</span> <span class="n">generatorCtx</span><span class="p">)</span> <span class="p">{</span>
-        <span class="k">if</span> <span class="p">(</span><span class="n">paint</span> <span class="n">instanceof</span> <span class="n">LinearGradientPaint</span><span class="p">)</span> <span class="p">{</span>
-            <span class="n">LinearGradientPaint</span> <span class="n">gradient</span> <span class="o">=</span> <span class="p">(</span><span class="n">LinearGradientPaint</span><span class="p">)</span> <span class="n">paint</span><span class="p">;</span>
-
-            <span class="sr">//</span> <span class="n">Create</span> <span class="n">a</span> <span class="k">new</span> <span class="n">SVG</span> <span class="s">&#39;linearGradient&#39;</span> <span class="n">element</span> <span class="n">to</span> <span class="n">represent</span> <span class="n">the</span>
-            <span class="sr">//</span> <span class="n">LinearGradientPaint</span> <span class="n">being</span> <span class="n">used</span><span class="o">.</span>
-            <span class="n">String</span> <span class="n">id</span> <span class="o">=</span> <span class="n">generatorCtx</span><span class="o">.</span><span class="n">getIDGenerator</span><span class="p">()</span><span class="o">.</span><span class="n">generateID</span><span class="p">(</span><span class="s">&quot;gradient&quot;</span><span class="p">);</span>
-            <span class="n">Document</span> <span class="n">doc</span> <span class="o">=</span> <span class="n">generatorCtx</span><span class="o">.</span><span class="n">getDOMFactory</span><span class="p">();</span>
-            <span class="n">Element</span> <span class="n">grad</span> <span class="o">=</span> <span class="n">doc</span><span class="o">.</span><span class="n">createElementNS</span>
-                <span class="p">(</span><span class="n">SVGSyntax</span><span class="o">.</span><span class="n">SVG_NAMESPACE_URI</span><span class="p">,</span>
-                 <span class="n">SVGSyntax</span><span class="o">.</span><span class="n">SVG_LINEAR_GRADIENT_TAG</span><span class="p">);</span>
-
-            <span class="sr">//</span> <span class="n">Set</span> <span class="n">the</span> <span class="n">relevant</span> <span class="n">attributes</span> <span class="n">on</span> <span class="n">the</span> <span class="s">&#39;linearGradient&#39;</span> <span class="n">element</span><span class="o">.</span>
-            <span class="n">grad</span><span class="o">.</span><span class="n">setAttributeNS</span><span class="p">(</span><span class="n">null</span><span class="p">,</span> <span class="n">SVGSyntax</span><span class="o">.</span><span class="n">SVG_ID_ATTRIBUTE</span><span class="p">,</span> <span class="n">id</span><span class="p">);</span>
-            <span class="n">grad</span><span class="o">.</span><span class="n">setAttributeNS</span><span class="p">(</span><span class="n">null</span><span class="p">,</span> <span class="n">SVGSyntax</span><span class="o">.</span><span class="n">SVG_GRADIENT_UNITS_ATTRIBUTE</span><span class="p">,</span>
-                                <span class="n">SVGSyntax</span><span class="o">.</span><span class="n">SVG_USER_SPACE_ON_USE_VALUE</span><span class="p">);</span>
-            <span class="n">Point2D</span> <span class="n">pt</span> <span class="o">=</span> <span class="n">gradient</span><span class="o">.</span><span class="n">getStartPoint</span><span class="p">();</span>
-            <span class="n">grad</span><span class="o">.</span><span class="n">setAttributeNS</span><span class="p">(</span><span class="n">null</span><span class="p">,</span> <span class="s">&quot;x1&quot;</span><span class="p">,</span> <span class="n">pt</span><span class="o">.</span><span class="n">getX</span><span class="p">());</span>
-            <span class="n">grad</span><span class="o">.</span><span class="n">setAttributeNS</span><span class="p">(</span><span class="n">null</span><span class="p">,</span> <span class="s">&quot;y1&quot;</span><span class="p">,</span> <span class="n">pt</span><span class="o">.</span><span class="n">getY</span><span class="p">());</span>
-            <span class="n">pt</span> <span class="o">=</span> <span class="n">gradient</span><span class="o">.</span><span class="n">getEndPoint</span><span class="p">();</span>
-            <span class="n">grad</span><span class="o">.</span><span class="n">setAttributeNS</span><span class="p">(</span><span class="n">null</span><span class="p">,</span> <span class="s">&quot;x2&quot;</span><span class="p">,</span> <span class="n">pt</span><span class="o">.</span><span class="n">getX</span><span class="p">());</span>
-            <span class="n">grad</span><span class="o">.</span><span class="n">setAttributeNS</span><span class="p">(</span><span class="n">null</span><span class="p">,</span> <span class="s">&quot;y2&quot;</span><span class="p">,</span> <span class="n">pt</span><span class="o">.</span><span class="n">getY</span><span class="p">());</span>
-
-            <span class="n">switch</span> <span class="p">(</span><span class="n">gradient</span><span class="o">.</span><span class="n">getCycleMethod</span><span class="p">())</span> <span class="p">{</span>
-            <span class="k">case</span> <span class="n">MultipleGradientPaint</span><span class="o">.</span><span class="n">REFLECT:</span>
-                <span class="n">grad</span><span class="o">.</span><span class="n">setAttributeNS</span>
-                    <span class="p">(</span><span class="n">null</span><span class="p">,</span> <span class="n">SVGSyntax</span><span class="o">.</span><span class="n">SVG_SPREAD_METHOD_ATTRIBUTE</span><span class="p">,</span>
-                     <span class="n">SVGSyntax</span><span class="o">.</span><span class="n">SVG_REFLECT_VALUE</span><span class="p">);</span>
-                <span class="n">break</span><span class="p">;</span>
-            <span class="k">case</span> <span class="n">MultipleGradientPaint</span><span class="o">.</span><span class="n">REPEAT:</span>
-                <span class="n">grad</span><span class="o">.</span><span class="n">setAttributeNS</span>
-                    <span class="p">(</span><span class="n">null</span><span class="p">,</span> <span class="n">SVGSyntax</span><span class="o">.</span><span class="n">SVG_SPREAD_METHOD_ATTRIBUTE</span><span class="p">,</span>
-                     <span class="n">SVGSyntax</span><span class="o">.</span><span class="n">SVG_REPEAT_VALUE</span><span class="p">);</span>
-                <span class="n">break</span><span class="p">;</span>
-            <span class="sr">//</span> <span class="s">&#39;pad&#39;</span> <span class="n">is</span> <span class="n">the</span> <span class="n">default</span><span class="o">...</span>
-            <span class="p">}</span>
-
-            <span class="sr">//</span> <span class="n">Here</span> <span class="n">we</span> <span class="n">should</span> <span class="nb">write</span> <span class="n">the</span> <span class="n">transform</span> <span class="n">of</span> <span class="n">the</span> <span class="n">gradient</span>
-            <span class="sr">//</span> <span class="n">in</span> <span class="n">the</span> <span class="n">transform</span> <span class="n">attribute</span><span class="o">...</span>
-
-            <span class="sr">//</span> <span class="n">Here</span> <span class="n">we</span> <span class="n">should</span> <span class="nb">write</span> <span class="n">the</span> <span class="n">stops</span> <span class="n">of</span> <span class="n">the</span> <span class="n">gradients</span> <span class="n">as</span> 
-            <span class="sr">//</span> <span class="n">children</span> <span class="n">elements</span><span class="o">...</span>
-
-            <span class="k">return</span> <span class="k">new</span> <span class="n">SVGPaintDescriptor</span>
-                <span class="p">(</span><span class="s">&quot;url(#&quot;</span> <span class="o">+</span> <span class="nb">ref</span> <span class="o">+</span> <span class="s">&quot;)&quot;</span><span class="p">,</span> <span class="n">SVGSyntax</span><span class="o">.</span><span class="n">SVG_OPAQUE_VALUE</span><span class="p">,</span> <span class="n">grad</span><span class="p">);</span>
-        <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
-            <span class="sr">//</span> <span class="n">Let</span> <span class="n">the</span> <span class="n">default</span> <span class="n">mechanism</span> <span class="k">do</span> <span class="n">its</span> <span class="n">job</span><span class="o">.</span>
-            <span class="k">return</span> <span class="n">null</span><span class="p">;</span>
-        <span class="p">}</span>
-    <span class="p">}</span>
-<span class="p">}</span>
+  <span class="kd">public</span> <span class="n">SVGPaintDescriptor</span> <span class="nf">handlePaint</span><span class="o">(</span><span class="n">Paint</span> <span class="n">paint</span><span class="o">,</span>
+                      <span class="n">SVGGeneratorContext</span> <span class="n">generatorCtx</span><span class="o">)</span> <span class="o">{</span>
+    <span class="k">if</span> <span class="o">(</span><span class="n">paint</span> <span class="k">instanceof</span> <span class="n">LinearGradientPaint</span><span class="o">)</span> <span class="o">{</span>
+      <span class="n">LinearGradientPaint</span> <span class="n">gradient</span> <span class="o">=</span> <span class="o">(</span><span class="n">LinearGradientPaint</span><span class="o">)</span> <span class="n">paint</span><span class="o">;</span>
+
+      <span class="c1">// Create a new SVG &#39;linearGradient&#39; element to represent the</span>
+      <span class="c1">// LinearGradientPaint being used.</span>
+      <span class="n">String</span> <span class="n">id</span> <span class="o">=</span> <span class="n">generatorCtx</span><span class="o">.</span><span class="na">getIDGenerator</span><span class="o">().</span><span class="na">generateID</span><span class="o">(</span><span class="s">&quot;gradient&quot;</span><span class="o">);</span>
+      <span class="n">Document</span> <span class="n">doc</span> <span class="o">=</span> <span class="n">generatorCtx</span><span class="o">.</span><span class="na">getDOMFactory</span><span class="o">();</span>
+      <span class="n">Element</span> <span class="n">grad</span> <span class="o">=</span> <span class="n">doc</span><span class="o">.</span><span class="na">createElementNS</span>
+        <span class="o">(</span><span class="n">SVGSyntax</span><span class="o">.</span><span class="na">SVG_NAMESPACE_URI</span><span class="o">,</span>
+         <span class="n">SVGSyntax</span><span class="o">.</span><span class="na">SVG_LINEAR_GRADIENT_TAG</span><span class="o">);</span>
+
+      <span class="c1">// Set the relevant attributes on the &#39;linearGradient&#39; element.</span>
+      <span class="n">grad</span><span class="o">.</span><span class="na">setAttributeNS</span><span class="o">(</span><span class="kc">null</span><span class="o">,</span> <span class="n">SVGSyntax</span><span class="o">.</span><span class="na">SVG_ID_ATTRIBUTE</span><span class="o">,</span> <span class="n">id</span><span class="o">);</span>
+      <span class="n">grad</span><span class="o">.</span><span class="na">setAttributeNS</span><span class="o">(</span><span class="kc">null</span><span class="o">,</span> <span class="n">SVGSyntax</span><span class="o">.</span><span class="na">SVG_GRADIENT_UNITS_ATTRIBUTE</span><span class="o">,</span>
+                <span class="n">SVGSyntax</span><span class="o">.</span><span class="na">SVG_USER_SPACE_ON_USE_VALUE</span><span class="o">);</span>
+      <span class="n">Point2D</span> <span class="n">pt</span> <span class="o">=</span> <span class="n">gradient</span><span class="o">.</span><span class="na">getStartPoint</span><span class="o">();</span>
+      <span class="n">grad</span><span class="o">.</span><span class="na">setAttributeNS</span><span class="o">(</span><span class="kc">null</span><span class="o">,</span> <span class="s">&quot;x1&quot;</span><span class="o">,</span> <span class="n">pt</span><span class="o">.</span><span class="na">getX</span><span class="o">());</span>
+      <span class="n">grad</span><span class="o">.</span><span class="na">setAttributeNS</span><span class="o">(</span><span class="kc">null</span><span class="o">,</span> <span class="s">&quot;y1&quot;</span><span class="o">,</span> <span class="n">pt</span><span class="o">.</span><span class="na">getY</span><span class="o">());</span>
+      <span class="n">pt</span> <span class="o">=</span> <span class="n">gradient</span><span class="o">.</span><span class="na">getEndPoint</span><span class="o">();</span>
+      <span class="n">grad</span><span class="o">.</span><span class="na">setAttributeNS</span><span class="o">(</span><span class="kc">null</span><span class="o">,</span> <span class="s">&quot;x2&quot;</span><span class="o">,</span> <span class="n">pt</span><span class="o">.</span><span class="na">getX</span><span class="o">());</span>
+      <span class="n">grad</span><span class="o">.</span><span class="na">setAttributeNS</span><span class="o">(</span><span class="kc">null</span><span class="o">,</span> <span class="s">&quot;y2&quot;</span><span class="o">,</span> <span class="n">pt</span><span class="o">.</span><span class="na">getY</span><span class="o">());</span>
+
+      <span class="k">switch</span> <span class="o">(</span><span class="n">gradient</span><span class="o">.</span><span class="na">getCycleMethod</span><span class="o">())</span> <span class="o">{</span>
+      <span class="k">case</span> <span class="n">MultipleGradientPaint</span><span class="o">.</span><span class="na">REFLECT</span><span class="o">:</span>
+        <span class="n">grad</span><span class="o">.</span><span class="na">setAttributeNS</span>
+          <span class="o">(</span><span class="kc">null</span><span class="o">,</span> <span class="n">SVGSyntax</span><span class="o">.</span><span class="na">SVG_SPREAD_METHOD_ATTRIBUTE</span><span class="o">,</span>
+           <span class="n">SVGSyntax</span><span class="o">.</span><span class="na">SVG_REFLECT_VALUE</span><span class="o">);</span>
+        <span class="k">break</span><span class="o">;</span>
+      <span class="k">case</span> <span class="n">MultipleGradientPaint</span><span class="o">.</span><span class="na">REPEAT</span><span class="o">:</span>
+        <span class="n">grad</span><span class="o">.</span><span class="na">setAttributeNS</span>
+          <span class="o">(</span><span class="kc">null</span><span class="o">,</span> <span class="n">SVGSyntax</span><span class="o">.</span><span class="na">SVG_SPREAD_METHOD_ATTRIBUTE</span><span class="o">,</span>
+           <span class="n">SVGSyntax</span><span class="o">.</span><span class="na">SVG_REPEAT_VALUE</span><span class="o">);</span>
+        <span class="k">break</span><span class="o">;</span>
+      <span class="c1">// &#39;pad&#39; is the default...</span>
+      <span class="o">}</span>
+
+      <span class="c1">// Here we should write the transform of the gradient</span>
+      <span class="c1">// in the transform attribute...</span>
+
+      <span class="c1">// Here we should write the stops of the gradients as</span>
+      <span class="c1">// children elements...</span>
+
+      <span class="k">return</span> <span class="k">new</span> <span class="nf">SVGPaintDescriptor</span>
+        <span class="o">(</span><span class="s">&quot;url(#&quot;</span> <span class="o">+</span> <span class="n">ref</span> <span class="o">+</span> <span class="s">&quot;)&quot;</span><span class="o">,</span> <span class="n">SVGSyntax</span><span class="o">.</span><span class="na">SVG_OPAQUE_VALUE</span><span class="o">,</span> <span class="n">grad</span><span class="o">);</span>
+    <span class="o">}</span> <span class="k">else</span> <span class="o">{</span>
+      <span class="c1">// Let the default mechanism do its job.</span>
+      <span class="k">return</span> <span class="kc">null</span><span class="o">;</span>
+    <span class="o">}</span>
+  <span class="o">}</span>
+<span class="o">}</span>
 </pre></div>
 
 
 <p>You should then set it on the <code>SVGGeneratorContext</code> by using the <code>setExtensionHandler</code> method.</p>
-<div class="codehilite"><pre><span class="n">SVGGeneratorContext</span> <span class="n">ctx</span> <span class="o">=</span> <span class="n">SVGGeneratorContext</span><span class="o">.</span><span class="n">createDefault</span><span class="p">(</span><span class="n">myFactory</span><span class="p">);</span>
-<span class="n">ctx</span><span class="o">.</span><span class="n">setExtensionHandler</span><span class="p">(</span><span class="k">new</span> <span class="n">MyExtensionHandler</span><span class="p">());</span>
-<span class="n">SVGGraphics2D</span> <span class="n">g2d</span> <span class="o">=</span> <span class="k">new</span> <span class="n">SVGGraphics2D</span><span class="p">(</span><span class="n">ctx</span><span class="p">,</span> <span class="n">false</span><span class="p">);</span>
+<div class="codehilite"><pre><span class="n">SVGGeneratorContext</span> <span class="n">ctx</span> <span class="o">=</span> <span class="n">SVGGeneratorContext</span><span class="o">.</span><span class="na">createDefault</span><span class="o">(</span><span class="n">myFactory</span><span class="o">);</span>
+<span class="n">ctx</span><span class="o">.</span><span class="na">setExtensionHandler</span><span class="o">(</span><span class="k">new</span> <span class="n">MyExtensionHandler</span><span class="o">());</span>
+<span class="n">SVGGraphics2D</span> <span class="n">g2d</span> <span class="o">=</span> <span class="k">new</span> <span class="n">SVGGraphics2D</span><span class="o">(</span><span class="n">ctx</span><span class="o">,</span> <span class="kc">false</span><span class="o">);</span>
 </pre></div>
 
 
-<h1 id="how-to-view-the-generated-svg-document-wzxhzdk32wzxhzdk33">How to view the generated SVG document <a id="view"></a></h1>
+<h1 id="how-to-view-the-generated-svg-document-wzxhzdk30wzxhzdk31">How to view the generated SVG document <a id="view"></a></h1>
 <p>The following code example illustrates how to view the SVG content generated by an <code>SVGGraphics2D</code> object.</p>
-<div class="codehilite"><pre><span class="nb">import</span> <span class="n">java</span><span class="o">.</span><span class="n">awt</span><span class="o">.*</span><span class="p">;</span>
-<span class="nb">import</span> <span class="n">java</span><span class="o">.</span><span class="n">awt</span><span class="o">.</span><span class="n">geom</span><span class="o">.*</span><span class="p">;</span>
+<div class="codehilite"><pre><span class="kn">import</span> <span class="nn">java.awt.*</span><span class="o">;</span>
+<span class="kn">import</span> <span class="nn">java.awt.geom.*</span><span class="o">;</span>
 
-<span class="nb">import</span> <span class="n">javax</span><span class="o">.</span><span class="n">swing</span><span class="o">.*</span><span class="p">;</span>
+<span class="kn">import</span> <span class="nn">javax.swing.*</span><span class="o">;</span>
 
-<span class="nb">import</span> <span class="n">org</span><span class="o">.</span><span class="n">apache</span><span class="o">.</span><span class="n">batik</span><span class="o">.</span><span class="n">swing</span><span class="o">.*</span><span class="p">;</span>
-<span class="nb">import</span> <span class="n">org</span><span class="o">.</span><span class="n">apache</span><span class="o">.</span><span class="n">batik</span><span class="o">.</span><span class="n">svggen</span><span class="o">.*</span><span class="p">;</span>
-<span class="nb">import</span> <span class="n">org</span><span class="o">.</span><span class="n">apache</span><span class="o">.</span><span class="n">batik</span><span class="o">.</span><span class="n">dom</span><span class="o">.</span><span class="n">svg</span><span class="o">.</span><span class="n">SVGDOMImplementation</span><span class="p">;</span>
-
-<span class="nb">import</span> <span class="n">org</span><span class="o">.</span><span class="n">w3c</span><span class="o">.</span><span class="n">dom</span><span class="o">.*</span><span class="p">;</span>
-<span class="nb">import</span> <span class="n">org</span><span class="o">.</span><span class="n">w3c</span><span class="o">.</span><span class="n">dom</span><span class="o">.</span><span class="n">svg</span><span class="o">.*</span><span class="p">;</span>
-
-<span class="n">public</span> <span class="n">class</span> <span class="n">ViewGeneratedSVGDemo</span> <span class="p">{</span>
-
-    <span class="n">public</span> <span class="n">static</span> <span class="n">void</span> <span class="n">main</span><span class="p">(</span><span class="n">String</span><span class="o">[]</span> <span class="n">args</span><span class="p">)</span> <span class="p">{</span>
-        <span class="sr">//</span> <span class="n">Create</span> <span class="n">an</span> <span class="n">SVG</span> <span class="n">document</span><span class="o">.</span>
-        <span class="n">DOMImplementation</span> <span class="n">impl</span> <span class="o">=</span> <span class="n">SVGDOMImplementation</span><span class="o">.</span><span class="n">getDOMImplementation</span><span class="p">();</span>
-        <span class="n">String</span> <span class="n">svgNS</span> <span class="o">=</span> <span class="n">SVGDOMImplementation</span><span class="o">.</span><span class="n">SVG_NAMESPACE_URI</span><span class="p">;</span>

[... 77 lines stripped ...]


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: commits-help@xmlgraphics.apache.org


Mime
View raw message