xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Litterst, Edwin" <Edwin.Litte...@fiz-karlsruhe.de>
Subject setting viewbox attribute
Date Thu, 07 Apr 2016 11:50:06 GMT

I already asked about this some time ago (http://batik.2283329.n4.nabble.com/problem-setting-viewbox-td4656184.html).

I am not able to set the viewbox attribute in the svg (as attribute viewbox in the XML element

      DOMImplementation impl = SVGDOMImplementation.getDOMImplementation();
      String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
      SVGDocument document = (SVGDocument) impl.createDocument(svgNS, "svg", null);
      SVGGraphics2D svgGenerator = new SVGGraphics2D(document);
      Dimension dimension = new Dimension();
      dimension.setSize(imageWidth, imageHeight);
      final SVGSVGElement rootElement = document.getRootElement();
      rootElement.setAttribute("viewBox", "0 0 " + Integer.toString(imageWidth) + " " + Integer.toString(imageHeight));

Debugging through the code I found out that the attribute is added to the attribute list (in
the firstChild of SVGDocument) as expected. It gets lost when creating the image with

      Writer out = new OutputStreamWriter(outputStream, "UTF-8");
      ((SVGGraphics2D) graphics2D).stream(out, useCSS);

In this method the following statement:

Element svgRoot = getRoot();

Creates a new Element which is missing the viewBox attribute. When I add it again manually
(in the debugger), the expected svg is created.

Otherwise, SVGGraphics.stream creates a DocumentFragment svgDocument whose child contains
an SVGOMAnimatedRect viewBox. But this doesn't seem to be used (at least I couldn't find it).

Do I have to do anything else except adding the viewbox attribute (e.g. configuring something)
or is batik not able to handle this?


View raw message