Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /*
 
    Licensed to the Apache Software Foundation (ASF) under one or more
    contributor license agreements.  See the NOTICE file distributed with
    this work for additional information regarding copyright ownership.
    The ASF licenses this file to You under the Apache License, Version 2.0
    (the "License"); you may not use this file except in compliance with
    the License.  You may obtain a copy of the License at
 
       http://www.apache.org/licenses/LICENSE-2.0
   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
 */
package org.apache.batik.svggen;
Utility class that converts a Shape object into the corresponding SVG element. Note that this class analyzes the input Shape class to generate the most appropriate corresponding SVG element: + Polygon is mapped to polygon + Rectangle2D and RoundRectangle2D are mapped to rect + Ellipse2D is mapped to circle or ellipse + Line2D is mapped to line + Arc2D, CubicCurve2D, Area, GeneralPath and QuadCurve2D are mapped to path. + Any custom Shape implementation is mapped to path as well.

Author(s):
Vincent Hardy
Version:
$Id: SVGShape.java 475477 2006-11-15 22:44:28Z cam $
public class SVGShape extends SVGGraphicObjectConverter {
    /*
     * Subconverts, for each type of Shape class
     */
    private SVGArc       svgArc;
    private SVGEllipse   svgEllipse;
    private SVGLine      svgLine;
    private SVGPath      svgPath;
    private SVGPolygon   svgPolygon;
    private SVGRectangle svgRectangle;

    

Parameters:
generatorContext used to build Elements
    public SVGShape(SVGGeneratorContext generatorContext) {
        super(generatorContext);
               = new SVGArc(generatorContext);
           = new SVGEllipse(generatorContext);
              = new SVGLine(generatorContext);
              = new SVGPath(generatorContext);
           = new SVGPolygon(generatorContext);
         = new SVGRectangle(generatorContext);
    }

    

Parameters:
shape Shape object to be converted
    public Element toSVG(Shape shape){
        if(shape instanceof Polygon)
            return .toSVG((Polygon)shape);
        else if(shape instanceof Rectangle2D)
            return .toSVG((Rectangle2D)shape);
        else if(shape instanceof RoundRectangle2D)
            return .toSVG((RoundRectangle2D)shape);
        else if(shape instanceof Ellipse2D)
            return .toSVG((Ellipse2D)shape);
        else if(shape instanceof Line2D)
            return .toSVG((Line2D)shape);
        else if(shape instanceof Arc2D)
            return .toSVG((Arc2D)shape);
        else
            return .toSVG(shape);
    }
New to GrepCode? Check out our FAQ X