1 18 package org.apache.batik.parser; 19 20 import java.io.*; 21 22 import org.apache.batik.test.*; 23 24 30 public class PathParserTest extends AbstractTest { 31 32 protected String sourcePath; 33 protected String destinationPath; 34 35 protected StringBuffer buffer; 36 protected String resultPath; 37 38 43 public PathParserTest(String spath, String dpath) { 44 sourcePath = spath; 45 destinationPath = dpath; 46 } 47 48 public TestReport runImpl() throws Exception { 49 PathParser pp = new PathParser(); 50 pp.setPathHandler(new TestHandler()); 51 52 try { 53 pp.parse(new StringReader(sourcePath)); 54 } catch (ParseException e) { 55 DefaultTestReport report = new DefaultTestReport(this); 56 report.setErrorCode("parse.error"); 57 report.addDescriptionEntry("exception.text", e.getMessage()); 58 report.setPassed(false); 59 return report; 60 } 61 62 if (!destinationPath.equals(resultPath)) { 63 DefaultTestReport report = new DefaultTestReport(this); 64 report.setErrorCode("invalid.parsing.events"); 65 report.addDescriptionEntry("expected.text", destinationPath); 66 report.addDescriptionEntry("generated.text", resultPath); 67 report.setPassed(false); 68 return report; 69 } 70 71 return reportSuccess(); 72 } 73 74 class TestHandler extends DefaultPathHandler { 75 public TestHandler() {} 76 77 public void startPath() throws ParseException { 78 buffer = new StringBuffer (); 79 } 80 81 public void movetoRel(float x, float y) throws ParseException { 82 buffer.append('m'); 83 buffer.append(x); 84 buffer.append(' '); 85 buffer.append(y); 86 } 87 88 public void movetoAbs(float x, float y) throws ParseException { 89 buffer.append('M'); 90 buffer.append(x); 91 buffer.append(' '); 92 buffer.append(y); 93 } 94 95 public void endPath() throws ParseException { 96 resultPath = buffer.toString(); 97 } 98 99 public void closePath() throws ParseException { 100 buffer.append('Z'); 101 } 102 103 public void linetoRel(float x, float y) throws ParseException { 104 buffer.append('l'); 105 buffer.append(x); 106 buffer.append(' '); 107 buffer.append(y); 108 } 109 110 public void linetoAbs(float x, float y) throws ParseException { 111 buffer.append('L'); 112 buffer.append(x); 113 buffer.append(' '); 114 buffer.append(y); 115 } 116 117 public void linetoHorizontalRel(float x) throws ParseException { 118 buffer.append('h'); 119 buffer.append(x); 120 } 121 122 public void linetoHorizontalAbs(float x) throws ParseException { 123 buffer.append('H'); 124 buffer.append(x); 125 } 126 127 public void linetoVerticalRel(float y) throws ParseException { 128 buffer.append('v'); 129 buffer.append(y); 130 } 131 132 public void linetoVerticalAbs(float y) throws ParseException { 133 buffer.append('V'); 134 buffer.append(y); 135 } 136 137 public void curvetoCubicRel(float x1, float y1, 138 float x2, float y2, 139 float x, float y) throws ParseException { 140 buffer.append('c'); 141 buffer.append(x1); 142 buffer.append(' '); 143 buffer.append(y1); 144 buffer.append(' '); 145 buffer.append(x2); 146 buffer.append(' '); 147 buffer.append(y2); 148 buffer.append(' '); 149 buffer.append(x); 150 buffer.append(' '); 151 buffer.append(y); 152 } 153 154 public void curvetoCubicAbs(float x1, float y1, 155 float x2, float y2, 156 float x, float y) throws ParseException { 157 buffer.append('C'); 158 buffer.append(x1); 159 buffer.append(' '); 160 buffer.append(y1); 161 buffer.append(' '); 162 buffer.append(x2); 163 buffer.append(' '); 164 buffer.append(y2); 165 buffer.append(' '); 166 buffer.append(x); 167 buffer.append(' '); 168 buffer.append(y); 169 } 170 171 public void curvetoCubicSmoothRel(float x2, float y2, 172 float x, float y) throws ParseException { 173 buffer.append('s'); 174 buffer.append(x2); 175 buffer.append(' '); 176 buffer.append(y2); 177 buffer.append(' '); 178 buffer.append(x); 179 buffer.append(' '); 180 buffer.append(y); 181 } 182 183 public void curvetoCubicSmoothAbs(float x2, float y2, 184 float x, float y) throws ParseException { 185 buffer.append('S'); 186 buffer.append(x2); 187 buffer.append(' '); 188 buffer.append(y2); 189 buffer.append(' '); 190 buffer.append(x); 191 buffer.append(' '); 192 buffer.append(y); 193 } 194 195 public void curvetoQuadraticRel(float x1, float y1, 196 float x, float y) throws ParseException { 197 buffer.append('q'); 198 buffer.append(x1); 199 buffer.append(' '); 200 buffer.append(y1); 201 buffer.append(' '); 202 buffer.append(x); 203 buffer.append(' '); 204 buffer.append(y); 205 } 206 207 public void curvetoQuadraticAbs(float x1, float y1, 208 float x, float y) throws ParseException { 209 buffer.append('Q'); 210 buffer.append(x1); 211 buffer.append(' '); 212 buffer.append(y1); 213 buffer.append(' '); 214 buffer.append(x); 215 buffer.append(' '); 216 buffer.append(y); 217 } 218 219 public void curvetoQuadraticSmoothRel(float x, float y) 220 throws ParseException { 221 buffer.append('t'); 222 buffer.append(x); 223 buffer.append(' '); 224 buffer.append(y); 225 } 226 227 public void curvetoQuadraticSmoothAbs(float x, float y) 228 throws ParseException { 229 buffer.append('T'); 230 buffer.append(x); 231 buffer.append(' '); 232 buffer.append(y); 233 } 234 235 public void arcRel(float rx, float ry, 236 float xAxisRotation, 237 boolean largeArcFlag, boolean sweepFlag, 238 float x, float y) throws ParseException { 239 buffer.append('a'); 240 buffer.append(rx); 241 buffer.append(' '); 242 buffer.append(ry); 243 buffer.append(' '); 244 buffer.append(xAxisRotation); 245 buffer.append(' '); 246 buffer.append(largeArcFlag ? '1' : '0'); 247 buffer.append(' '); 248 buffer.append(sweepFlag ? '1' : '0'); 249 buffer.append(' '); 250 buffer.append(x); 251 buffer.append(' '); 252 buffer.append(y); 253 } 254 255 public void arcAbs(float rx, float ry, 256 float xAxisRotation, 257 boolean largeArcFlag, boolean sweepFlag, 258 float x, float y) throws ParseException { 259 buffer.append('A'); 260 buffer.append(rx); 261 buffer.append(' '); 262 buffer.append(ry); 263 buffer.append(' '); 264 buffer.append(xAxisRotation); 265 buffer.append(' '); 266 buffer.append(largeArcFlag ? '1' : '0'); 267 buffer.append(' '); 268 buffer.append(sweepFlag ? '1' : '0'); 269 buffer.append(' '); 270 buffer.append(x); 271 buffer.append(' '); 272 buffer.append(y); 273 } 274 } 275 } 276 | Popular Tags |