You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-dev@xmlgraphics.apache.org by vh...@apache.org on 2002/06/18 10:05:24 UTC

cvs commit: xml-batik/test-resources/org/apache/batik/svggen regsvggen.xml

vhardy      2002/06/18 01:05:23

  Modified:    sources/org/apache/batik/svggen DOMTreeManager.java
                        SVGGraphics2D.java
               test-resources/org/apache/batik/svggen regsvggen.xml
  Added:       test-sources/org/apache/batik/svggen GetRootTest.java
  Log:
  Fixed bug/RFE #9520. Added new version of getRoot on SVGGraphics2D
  
  Revision  Changes    Path
  1.1                  xml-batik/test-sources/org/apache/batik/svggen/GetRootTest.java
  
  Index: GetRootTest.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) The Apache Software Foundation. All rights reserved.        *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1, a copy of which has been included with this distribution in  *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  
  package org.apache.batik.svggen;
  
  import org.apache.batik.svggen.SVGGeneratorContext.GraphicContextDefaults;
  
  import java.awt.Dimension;
  import java.awt.Font;
  
  import java.net.URL;
  
  import java.io.BufferedInputStream;
  import java.io.BufferedReader;
  import java.io.InputStreamReader;
  import java.io.File;
  import java.io.FileOutputStream;
  import java.io.InputStream;
  import java.io.IOException;
  import java.io.ByteArrayInputStream;
  import java.io.ByteArrayOutputStream;
  import java.io.OutputStreamWriter;
  import java.io.StringWriter;
  import java.io.PrintWriter;
  
  import org.apache.batik.util.SVGConstants;
  import org.apache.batik.test.AbstractTest;
  import org.apache.batik.test.DefaultTestReport;
  import org.apache.batik.test.TestReport;
  
  import org.apache.batik.svggen.SVGGraphics2D;
  import org.apache.batik.dom.GenericDOMImplementation;
  import org.w3c.dom.Document;
  import org.w3c.dom.DOMImplementation;
  
  /**
   * This test validates that the SVGGraphics2D generates the same result 
   * with the two versions of its getRoot method.
   *
   * @author <a href="mailto:vhardy@apache.org">Vincent Hardy</a>
   * @version $Id: GetRootTest.java,v 1.1 2002/06/18 08:05:23 vhardy Exp $
   */
  public class GetRootTest extends AbstractTest implements SVGConstants {
      public static final Dimension CANVAS_SIZE
          = new Dimension(300, 400);
  
      public static final String ERROR_DIFFERENT_SVG_OUTPUT
          = "GetRootTest.error.different.svg.output";
  
      public static final String ENTRY_KEY_NO_ARG_OUTPUT 
          = "GetRootTest.entry.key.no.arg.output";
  
      public static final String ENTRY_KEY_SVG_ARG_OUTPUT
          = "GetRootTest.entry.key.svg.arg.output";
  
      public TestReport runImpl() throws Exception {
          // First, use the no-argument getRoot
  
          DOMImplementation impl = GenericDOMImplementation.getDOMImplementation();
          String namespaceURI = SVGConstants.SVG_NAMESPACE_URI;
          Document domFactory = impl.createDocument(namespaceURI, SVG_SVG_TAG, null);
          SVGGeneratorContext ctx = SVGGeneratorContext.createDefault(domFactory);
          GraphicContextDefaults defaults 
              = new GraphicContextDefaults();
          defaults.font = new Font("Arial", Font.PLAIN, 12);
          ctx.setGraphicContextDefaults(defaults);
          SVGGraphics2D g2d = new SVGGraphics2D(ctx, false);
  
          g2d.setSVGCanvasSize(CANVAS_SIZE);
  
          Painter painter = new BasicShapes();
          painter.paint(g2d);
  
          StringWriter swA = new StringWriter();
          g2d.stream(g2d.getRoot(), swA);
  
          // Now, use the getRoot with argument
          domFactory = impl.createDocument(namespaceURI, SVG_SVG_TAG, null);
          ctx = SVGGeneratorContext.createDefault(domFactory);
          ctx.setGraphicContextDefaults(defaults);
          g2d = new SVGGraphics2D(ctx, false);
  
          g2d.setSVGCanvasSize(CANVAS_SIZE);
  
          painter.paint(g2d);
  
          StringWriter swB = new StringWriter();
          g2d.stream(g2d.getRoot(domFactory.getDocumentElement()),
                     swB);
  
          // Compare the two output: they should be identical
          if (swA.toString().equals(swB.toString())) {
              return reportSuccess();
          } else {
              TestReport report = reportError(ERROR_DIFFERENT_SVG_OUTPUT);
              report.addDescriptionEntry(ENTRY_KEY_NO_ARG_OUTPUT,
                                         swA.toString());
              report.addDescriptionEntry(ENTRY_KEY_SVG_ARG_OUTPUT,
                                         swB.toString());
              return report;
          }
      }
  }
  
  
  
  1.16      +15 -3     xml-batik/sources/org/apache/batik/svggen/DOMTreeManager.java
  
  Index: DOMTreeManager.java
  ===================================================================
  RCS file: /home/cvs/xml-batik/sources/org/apache/batik/svggen/DOMTreeManager.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- DOMTreeManager.java	2 Nov 2001 12:58:30 -0000	1.15
  +++ DOMTreeManager.java	18 Jun 2002 08:05:23 -0000	1.16
  @@ -220,8 +220,20 @@
        * the topLevelGroup.
        */
       public Element getRoot(){
  -        Element svg = generatorContext.domFactory.
  -            createElementNS(SVG_NAMESPACE_URI, SVG_SVG_TAG);
  +        return getRoot(null);
  +    }
  +
  +    /**
  +     * Returns the root element with the generic definitions and
  +     * the topLevelGroup.
  +     */
  +    public Element getRoot(Element svgElement){
  +        Element svg = svgElement;
  +
  +        if (svg == null) {
  +            svg = generatorContext.domFactory.
  +                createElementNS(SVG_NAMESPACE_URI, SVG_SVG_TAG);
  +        } 
   
           // Enable background if required by AlphaComposite convertion
           if (gcConverter.getCompositeConverter().
  
  
  
  1.33      +15 -2     xml-batik/sources/org/apache/batik/svggen/SVGGraphics2D.java
  
  Index: SVGGraphics2D.java
  ===================================================================
  RCS file: /home/cvs/xml-batik/sources/org/apache/batik/svggen/SVGGraphics2D.java,v
  retrieving revision 1.32
  retrieving revision 1.33
  diff -u -r1.32 -r1.33
  --- SVGGraphics2D.java	17 Jun 2002 17:06:53 -0000	1.32
  +++ SVGGraphics2D.java	18 Jun 2002 08:05:23 -0000	1.33
  @@ -469,7 +469,20 @@
        *         object
        */
       public Element getRoot(){
  -        Element svgRoot = domTreeManager.getRoot();
  +        return getRoot(null);
  +    }
  +
  +    /**
  +     * This version of the getRoot method will append the input svgRoot
  +     * and set its attributes.
  +     *
  +     * @param svgRoot an SVG element underwhich the content should 
  +     *        be appended.
  +     * @returns the svg root node of the SVG document associated with 
  +     *          this object.
  +     */
  +    public Element getRoot(Element svgRoot) {
  +        svgRoot = domTreeManager.getRoot(svgRoot);
           if (svgCanvasSize != null){
               svgRoot.setAttributeNS(null, SVG_WIDTH_ATTRIBUTE,
                                      "" + svgCanvasSize.width);
  
  
  
  1.16      +3 -1      xml-batik/test-resources/org/apache/batik/svggen/regsvggen.xml
  
  Index: regsvggen.xml
  ===================================================================
  RCS file: /home/cvs/xml-batik/test-resources/org/apache/batik/svggen/regsvggen.xml,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- regsvggen.xml	19 Feb 2002 16:48:23 -0000	1.15
  +++ regsvggen.xml	18 Jun 2002 08:05:23 -0000	1.16
  @@ -38,4 +38,6 @@
       <test id="Texture" />
       <test id="TextSpacePreserve" />    
       <test id="TransformCollapse" />
  +
  +    <test id="GetRootTest" class="org.apache.batik.svggen.GetRootTest" />
   </testSuite>
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-dev-help@xml.apache.org