1 18 package org.apache.batik.svggen; 19 20 import java.awt.geom.Arc2D ; 21 import java.awt.geom.Line2D ; 22 import java.awt.geom.Point2D ; 23 24 import org.w3c.dom.Element ; 25 26 34 public class SVGArc extends SVGGraphicObjectConverter { 35 38 private SVGLine svgLine; 39 40 43 public SVGArc(SVGGeneratorContext generatorContext) { 44 super(generatorContext); 45 } 46 47 50 public Element toSVG(Arc2D arc) { 51 if ((arc.getWidth() == 0) || (arc.getHeight() == 0)) { 52 Line2D line = new Line2D.Double 53 (arc.getX(), arc.getY(), 54 arc.getX() + arc.getWidth(), 55 arc.getY() + arc.getHeight()); 56 if (svgLine == null) 57 svgLine = new SVGLine(generatorContext); 58 return svgLine.toSVG(line); 59 } 60 61 Element svgPath = generatorContext.domFactory.createElementNS 62 (SVG_NAMESPACE_URI, SVG_PATH_TAG); 63 StringBuffer d = new StringBuffer (""); 64 65 Point2D startPt = arc.getStartPoint(); 66 Point2D endPt = arc.getEndPoint(); 67 double ext = arc.getAngleExtent(); 68 int type = arc.getArcType(); 69 70 d.append(PATH_MOVE); 71 d.append(doubleString(startPt.getX())); 72 d.append(SPACE); 73 d.append(doubleString(startPt.getY())); 74 d.append(SPACE); 75 76 d.append(PATH_ARC); 77 d.append(doubleString(arc.getWidth()/2)); 78 d.append(SPACE); 79 d.append(doubleString(arc.getHeight()/2)); 80 d.append(SPACE); 81 d.append("0"); d.append(SPACE); 83 if (ext > 180) d.append("1"); else d.append("0"); d.append(SPACE); 86 if (ext > 0) d.append("0"); else d.append("1"); 89 d.append(SPACE); 90 d.append(doubleString(endPt.getX())); 91 d.append(SPACE); 92 d.append(doubleString(endPt.getY())); 93 94 if (type == Arc2D.CHORD) { 95 d.append(PATH_CLOSE); 96 } else if (type == Arc2D.PIE) { 97 double cx = arc.getX()+arc.getWidth()/2; 98 double cy = arc.getY()+arc.getHeight()/2; 99 d.append(PATH_LINE_TO); 100 d.append(SPACE); 101 d.append(doubleString(cx)); 102 d.append(SPACE); 103 d.append(doubleString(cy)); 104 d.append(SPACE); 105 d.append(PATH_CLOSE); 106 } 107 svgPath.setAttributeNS(null, SVG_D_ATTRIBUTE, d.toString()); 108 return svgPath; 109 } 110 } 111 | Popular Tags |