1 18 package org.apache.batik.parser; 19 20 import java.awt.Shape ; 21 import java.awt.geom.Point2D ; 22 import java.io.IOException ; 23 import java.io.Reader ; 24 25 import org.apache.batik.ext.awt.geom.ExtendedGeneralPath; 26 27 34 public class AWTPathProducer implements PathHandler, ShapeProducer { 35 38 protected ExtendedGeneralPath path; 39 40 43 protected float currentX; 44 45 48 protected float currentY; 49 50 53 protected float xCenter; 54 55 58 protected float yCenter; 59 60 63 protected int windingRule; 64 65 70 public static Shape createShape(Reader r, int wr) 71 throws IOException , 72 ParseException { 73 PathParser p = new PathParser(); 74 AWTPathProducer ph = new AWTPathProducer(); 75 76 ph.setWindingRule(wr); 77 p.setPathHandler(ph); 78 p.parse(r); 79 80 return ph.getShape(); 81 } 82 83 86 public void setWindingRule(int i) { 87 windingRule = i; 88 } 89 90 93 public int getWindingRule() { 94 return windingRule; 95 } 96 97 102 public Shape getShape() { 103 return path; 104 } 105 106 109 public void startPath() throws ParseException { 110 currentX = 0; 111 currentY = 0; 112 xCenter = 0; 113 yCenter = 0; 114 path = new ExtendedGeneralPath(windingRule); 115 } 116 117 120 public void endPath() throws ParseException { 121 } 122 123 126 public void movetoRel(float x, float y) throws ParseException { 127 path.moveTo(xCenter = currentX += x, yCenter = currentY += y); 128 } 129 130 133 public void movetoAbs(float x, float y) throws ParseException { 134 path.moveTo(xCenter = currentX = x, yCenter = currentY = y); 135 } 136 137 140 public void closePath() throws ParseException { 141 path.closePath(); 142 Point2D pt = path.getCurrentPoint(); 143 currentX = (float)pt.getX(); 144 currentY = (float)pt.getY(); 145 } 146 147 150 public void linetoRel(float x, float y) throws ParseException { 151 path.lineTo(xCenter = currentX += x, yCenter = currentY += y); 152 } 153 154 157 public void linetoAbs(float x, float y) throws ParseException { 158 path.lineTo(xCenter = currentX = x, yCenter = currentY = y); 159 } 160 161 164 public void linetoHorizontalRel(float x) throws ParseException { 165 path.lineTo(xCenter = currentX += x, yCenter = currentY); 166 } 167 168 171 public void linetoHorizontalAbs(float x) throws ParseException { 172 path.lineTo(xCenter = currentX = x, yCenter = currentY); 173 } 174 175 178 public void linetoVerticalRel(float y) throws ParseException { 179 path.lineTo(xCenter = currentX, yCenter = currentY += y); 180 } 181 182 185 public void linetoVerticalAbs(float y) throws ParseException { 186 path.lineTo(xCenter = currentX, yCenter = currentY = y); 187 } 188 189 193 public void curvetoCubicRel(float x1, float y1, 194 float x2, float y2, 195 float x, float y) throws ParseException { 196 path.curveTo(currentX + x1, currentY + y1, 197 xCenter = currentX + x2, yCenter = currentY + y2, 198 currentX += x, currentY += y); 199 } 200 201 205 public void curvetoCubicAbs(float x1, float y1, 206 float x2, float y2, 207 float x, float y) throws ParseException { 208 path.curveTo(x1, y1, xCenter = x2, yCenter = y2, currentX = x, 209 currentY = y); 210 } 211 212 216 public void curvetoCubicSmoothRel(float x2, float y2, 217 float x, float y) throws ParseException { 218 path.curveTo(currentX * 2 - xCenter, 219 currentY * 2 - yCenter, 220 xCenter = currentX + x2, 221 yCenter = currentY + y2, 222 currentX += x, 223 currentY += y); 224 } 225 226 230 public void curvetoCubicSmoothAbs(float x2, float y2, 231 float x, float y) throws ParseException { 232 path.curveTo(currentX * 2 - xCenter, 233 currentY * 2 - yCenter, 234 xCenter = x2, 235 yCenter = y2, 236 currentX = x, 237 currentY = y); 238 } 239 240 244 public void curvetoQuadraticRel(float x1, float y1, 245 float x, float y) throws ParseException { 246 path.quadTo(xCenter = currentX + x1, yCenter = currentY + y1, 247 currentX += x, currentY += y); 248 } 249 250 254 public void curvetoQuadraticAbs(float x1, float y1, 255 float x, float y) throws ParseException { 256 path.quadTo(xCenter = x1, yCenter = y1, currentX = x, currentY = y); 257 } 258 259 262 public void curvetoQuadraticSmoothRel(float x, float y) 263 throws ParseException { 264 path.quadTo(xCenter = currentX * 2 - xCenter, 265 yCenter = currentY * 2 - yCenter, 266 currentX += x, 267 currentY += y); 268 } 269 270 273 public void curvetoQuadraticSmoothAbs(float x, float y) 274 throws ParseException { 275 path.quadTo(xCenter = currentX * 2 - xCenter, 276 yCenter = currentY * 2 - yCenter, 277 currentX = x, 278 currentY = y); 279 } 280 281 285 public void arcRel(float rx, float ry, 286 float xAxisRotation, 287 boolean largeArcFlag, boolean sweepFlag, 288 float x, float y) throws ParseException { 289 path.arcTo(rx, ry, xAxisRotation, largeArcFlag, sweepFlag, 290 xCenter = currentX += x, yCenter = currentY += y); 291 } 292 293 297 public void arcAbs(float rx, float ry, 298 float xAxisRotation, 299 boolean largeArcFlag, boolean sweepFlag, 300 float x, float y) throws ParseException { 301 path.arcTo(rx, ry, xAxisRotation, largeArcFlag, sweepFlag, 302 xCenter = currentX = x, yCenter = currentY = y); 303 } 304 } 305 | Popular Tags |