src/main/java/org/jfree/graphics2d/svg/SVGGraphics2D.java
public String getSVGElement(String id, boolean includeDimensions, 
            ViewBox viewBox, PreserveAspectRatio preserveAspectRatio,
            MeetOrSlice meetOrSlice) {
        StringBuilder svg = new StringBuilder("<svg ");
        if (id != null) {
            svg.append("id=\"").append(id).append("\" ");
        }
        String unitStr = this.units != null ? this.units.toString() : "";
        svg.append("xmlns=\"http://www.w3.org/2000/svg\" ")
           .append("xmlns:xlink=\"http://www.w3.org/1999/xlink\" ")
           .append("xmlns:jfreesvg=\"http://www.jfree.org/jfreesvg/svg\" ");
        if (includeDimensions) {
            svg.append("width=\"").append(this.width).append(unitStr)
               .append("\" height=\"").append(this.height).append(unitStr)
               .append("\" ");
        }
        if (viewBox != null) {
            svg.append("viewBox=\"").append(viewBox.valueStr()).append("\" ");
            if (preserveAspectRatio != null) {
                svg.append("preserveAspectRatio=\"")
                        .append(preserveAspectRatio.toString());
                if (meetOrSlice != null) {
                    svg.append(" ").append(meetOrSlice.toString());
                }
                svg.append("\" ");                    
            }
        }
        svg.append("text-rendering=\"").append(this.textRendering)
           .append("\" shape-rendering=\"").append(this.shapeRendering)
           .append("\">\n");
        StringBuilder defs = new StringBuilder("<defs>");
        for (GradientPaintKey key : this.gradientPaints.keySet()) {
            defs.append(getLinearGradientElement(this.gradientPaints.get(key), 
                    key.getPaint()));
            defs.append("\n");
        }
        for (LinearGradientPaintKey key : this.linearGradientPaints.keySet()) {
            defs.append(getLinearGradientElement(
                    this.linearGradientPaints.get(key), key.getPaint()));
            defs.append("\n");            
        }
        for (RadialGradientPaintKey key : this.radialGradientPaints.keySet()) {
            defs.append(getRadialGradientElement(
                    this.radialGradientPaints.get(key), key.getPaint()));
            defs.append("\n");
        }
        for (int i = 0; i < this.clipPaths.size(); i++) {
            StringBuilder b = new StringBuilder("<clipPath id=\"")
                    .append(this.defsKeyPrefix).append(CLIP_KEY_PREFIX).append(i)
                    .append("\">");
            b.append("<path ").append(this.clipPaths.get(i)).append("/>");
            b.append("</clipPath>").append("\n");
            defs.append(b.toString());
        }
        defs.append("</defs>\n");
        svg.append(defs);
        svg.append(this.sb);
        svg.append("</svg>");        
        return svg.toString();
    }
public String getSVGElement(String id, boolean includeDimensions, 
            ViewBox viewBox, PreserveAspectRatio preserveAspectRatio,
            MeetOrSlice meetOrSlice) {
        StringBuilder svg = new StringBuilder("<svg ");
        if (id != null) {
            svg.append("id=\"").append(id).append("\" ");
        }
        String unitStr = this.units != null ? this.units.toString() : "";
        svg.append("xmlns=\"http://www.w3.org/2000/svg\" ")
           .append("xmlns:xlink=\"http://www.w3.org/1999/xlink\" ")
           .append("xmlns:jfreesvg=\"http://www.jfree.org/jfreesvg/svg\" ");
        if (includeDimensions) {
            svg.append("width=\"").append(this.width).append(unitStr)
               .append("\" height=\"").append(this.height).append(unitStr)
               .append("\" ");
        }
        if (viewBox != null) {
            svg.append("viewBox=\"").append(viewBox.valueStr()).append("\" ");
            if (preserveAspectRatio != null) {
                svg.append("preserveAspectRatio=\"")
                        .append(preserveAspectRatio.toString());
                if (meetOrSlice != null) {
                    svg.append(" ").append(meetOrSlice.toString());
                }
                svg.append("\" ");                    
            }
        }
        svg.append("text-rendering=\"").append(this.textRendering)
           .append("\" shape-rendering=\"").append(this.shapeRendering)
           .append("\">\n");
        StringBuilder defs = new StringBuilder("<defs>");
        for (GradientPaintKey key : this.gradientPaints.keySet()) {
            defs.append(getLinearGradientElement(this.gradientPaints.get(key), 
                    key.getPaint()));
            defs.append("\n");
        }
        for (LinearGradientPaintKey key : this.linearGradientPaints.keySet()) {
            defs.append(getLinearGradientElement(
                    this.linearGradientPaints.get(key), key.getPaint()));
            defs.append("\n");            
        }
        for (RadialGradientPaintKey key : this.radialGradientPaints.keySet()) {
            defs.append(getRadialGradientElement(
                    this.radialGradientPaints.get(key), key.getPaint()));
            defs.append("\n");
        }
        for (int i = 0; i < this.clipPaths.size(); i++) {
            StringBuilder b = new StringBuilder("<clipPath id=\"")
                    .append(this.defsKeyPrefix).append(CLIP_KEY_PREFIX).append(i)
                    .append("\">");
            b.append("<path ").append(this.clipPaths.get(i)).append("/>");
            b.append("</clipPath>").append("\n");
            defs.append(b.toString());
        }
        defs.append("</defs>\n");
        svg.append(defs);
        svg.append(this.sb);
        svg.append("</svg>");        
        return svg.toString();
    }
public String getSVGElement ( String id , boolean includeDimensions , ViewBox viewBox , PreserveAspectRatio preserveAspectRatio , MeetOrSlice meetOrSlice ) { StringBuilder svg = new StringBuilder ( "<svg " ) ; if ( id != null ) { svg . append ( "id=\"" ) . append ( id ) . append ( "\" " ) ; } String unitStr = this . units != null ? this . units . toString ( ) : "" ; svg . append ( "xmlns=\"http://www.w3.org/2000/svg\" " ) . append ( "xmlns:xlink=\"http://www.w3.org/1999/xlink\" " ) . append ( "xmlns:jfreesvg=\"http://www.jfree.org/jfreesvg/svg\" " ) ; if ( includeDimensions ) { svg . append ( "width=\"" ) . append ( this . width ) . append ( unitStr ) . append ( "\" height=\"" ) . append ( this . height ) . append ( unitStr ) . append ( "\" " ) ; } if ( viewBox != null ) { svg . append ( "viewBox=\"" ) . append ( viewBox . valueStr ( ) ) . append ( "\" " ) ; if ( preserveAspectRatio != null ) { svg . append ( "preserveAspectRatio=\"" ) . append ( preserveAspectRatio . toString ( ) ) ; if ( meetOrSlice != null ) { svg . append ( " " ) . append ( meetOrSlice . toString ( ) ) ; } svg . append ( "\" " ) ; } } svg . append ( "text-rendering=\"" ) . append ( this . textRendering ) . append ( "\" shape-rendering=\"" ) . append ( this . shapeRendering ) . append ( "\">\n" ) ; StringBuilder defs = new StringBuilder ( "<defs>" ) ; for ( GradientPaintKey key : this . gradientPaints . keySet ( ) ) { defs . append ( getLinearGradientElement ( this . gradientPaints . get ( key ) , key . getPaint ( ) ) ) ; defs . append ( "\n" ) ; } for ( LinearGradientPaintKey key : this . linearGradientPaints . keySet ( ) ) { defs . append ( getLinearGradientElement ( this . linearGradientPaints . get ( key ) , key . getPaint ( ) ) ) ; defs . append ( "\n" ) ; } for ( RadialGradientPaintKey key : this . radialGradientPaints . keySet ( ) ) { defs . append ( getRadialGradientElement ( this . radialGradientPaints . get ( key ) , key . getPaint ( ) ) ) ; defs . append ( "\n" ) ; } for ( int i = 0 ; i < this . clipPaths . size ( ) ; i ++ ) { StringBuilder b = new StringBuilder ( "<clipPath id=\"" ) . append ( this . defsKeyPrefix ) . append ( CLIP_KEY_PREFIX ) . append ( i ) . append ( "\">" ) ; b . append ( "<path " ) . append ( this . clipPaths . get ( i ) ) . append ( "/>" ) ; b . append ( "</clipPath>" ) . append ( "\n" ) ; defs . append ( b . toString ( ) ) ; } defs . append ( "</defs>\n" ) ; svg . append ( defs ) ; svg . append ( this . sb ) ; svg . append ( "</svg>" ) ; return svg . toString ( ) ; }
Returns the SVG element that has been generated by calls to this
{@code Graphics2D} implementation, giving it the specified {@code id}.
If {@code id} is {@code null}, the element will have no {@code id}
attribute.  This method also allows for a {@code viewBox} to be defined,
along with the settings that handle scaling.

@param id  the element id ({@code null} permitted).
@param includeDimensions  include the width and height attributes?
@param viewBox  the view box specification (if {@code null} then no
{@code viewBox} attribute will be defined).
@param preserveAspectRatio  the value of the {@code preserveAspectRatio}
attribute (if {@code null} then not attribute will be defined).
@param meetOrSlice  the value of the meetOrSlice attribute.

@return A string containing the SVG element.

@since 3.2
Returns the SVG element that has been generated by calls to this { @code Graphics2D } implementation giving it the specified { @code id } . If { @code id } is { @code null } the element will have no { @code id } attribute . This method also allows for a { @code viewBox } to be defined along with the settings that handle scaling .