Hi,

I am new to Batik and I am trying to use Batik in order to convert svg content to some custom vector file format. So, it is a task somewhat similar to a PDFTranscoder.

I would like to work with the SVG Dom as this is nicely documented and standard. Most things work nicely, but I seem to be missing something. Here is a test program and two input files that show the problems I encounter.



<java src="UnitTest.java>
import org.apache.batik.dom.svg.SAXSVGDocumentFactory;
import org.apache.batik.util.XMLResourceDescriptor;
import org.w3c.dom.svg.*;
import java.io.IOException;

public class UnitTest {
  public static void main(String[] args) {
    try {
      String parser = XMLResourceDescriptor.getXMLParserClassName();
      SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser);
      SVGDocument doc = f.createSVGDocument(args[0]);
      SVGSVGElement root = doc.getRootElement();
      SVGRectElement rect = (SVGRectElement)
               root.getElementsByTagName("rect").item(0);
      SVGLength l =  rect.getWidth().getBaseVal();
      l.getValue();  // 1
      // root.getPixelUnitToMillimeterX();  // 2
      // root.getViewport();   // 3
    } catch (IOException ex) {
      System.err.println("Program was ended by an exception:");
      System.err.println(ex.getMessage());
      System.exit(1);
    }
  }
};
</java>

I use the following input file

<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
  "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd";>
<svg width="400px" height="200px" viewBox="0 0 4000 2000"
     xmlns="http://www.w3.org/2000/svg"; version="1.1">
      <rect x="0" y="400" width="4in" height="2in"/>
</svg>

Line (1) throws the following exception:
Exception in thread "main" java.lang.NullPointerException
at org.apache.batik.dom.svg.AbstractSVGLength$DefaultContext.getPixelUnitToMillimeter(Unknown Source) at org.apache.batik.parser.UnitProcessor.svgToUserSpace(Unknown Source) at org.apache.batik.dom.svg.AbstractSVGLength.getValue(Unknown Source)
        at UnitTest.main(UnitTest.java:16)

This does not occur if I replace the width and height attribute of the rect element as follows:
    <rect x="0" y="400" width="800" height="400"/>

Furthermore, if I uncomment line (2), I wil get an error:
Exception in thread "main" java.lang.NullPointerException
at org.apache.batik.dom.svg.SVGOMSVGElement.getPixelUnitToMillimeterX(Unknown Source)
        at UnitTest.main(UnitTest.java:17)

At line (3), I will get:
Exception in thread "main" java.lang.NullPointerException
at org.apache.batik.dom.svg.SVGOMSVGElement.getViewport(Unknown Source)
        at UnitTest.main(UnitTest.java:18)




Those problems seem to be related with this sentence from the SVG spec:
The SVG user agent negotiates with its parent user agent to determine the 
viewport into which the SVG user agent can render the document.

The main problem seems to be that I should somehow specify a user agent, but I don't know how. What should I do to get this to work?


Geert-Jan Giezeman


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to