1 18 package org.apache.batik.parser; 19 20 import java.awt.geom.AffineTransform ; 21 import java.io.Reader ; 22 23 30 public class AWTTransformProducer implements TransformListHandler { 31 34 protected AffineTransform affineTransform; 35 36 40 public static AffineTransform createAffineTransform(Reader r) 41 throws ParseException { 42 TransformListParser p = new TransformListParser(); 43 AWTTransformProducer th = new AWTTransformProducer(); 44 45 p.setTransformListHandler(th); 46 p.parse(r); 47 48 return th.getAffineTransform(); 49 } 50 51 55 public static AffineTransform createAffineTransform(String s) 56 throws ParseException { 57 TransformListParser p = new TransformListParser(); 58 AWTTransformProducer th = new AWTTransformProducer(); 59 60 p.setTransformListHandler(th); 61 p.parse(s); 62 63 return th.getAffineTransform(); 64 } 65 66 71 public AffineTransform getAffineTransform() { 72 return affineTransform; 73 } 74 75 78 public void startTransformList() throws ParseException { 79 affineTransform = new AffineTransform (); 80 } 81 82 86 public void matrix(float a, float b, float c, float d, float e, float f) 87 throws ParseException { 88 affineTransform.concatenate(new AffineTransform (a, b, c, d, e, f)); 89 } 90 91 94 public void rotate(float theta) throws ParseException { 95 affineTransform.concatenate 96 (AffineTransform.getRotateInstance(Math.PI * theta / 180)); 97 } 98 99 102 public void rotate(float theta, float cx, float cy) throws ParseException { 103 AffineTransform at 104 = AffineTransform.getRotateInstance(Math.PI * theta / 180, cx, cy); 105 affineTransform.concatenate(at); 106 } 107 108 111 public void translate(float tx) throws ParseException { 112 AffineTransform at = AffineTransform.getTranslateInstance(tx, 0); 113 affineTransform.concatenate(at); 114 } 115 116 119 public void translate(float tx, float ty) throws ParseException { 120 AffineTransform at = AffineTransform.getTranslateInstance(tx, ty); 121 affineTransform.concatenate(at); 122 } 123 124 127 public void scale(float sx) throws ParseException { 128 affineTransform.concatenate(AffineTransform.getScaleInstance(sx, sx)); 129 } 130 131 134 public void scale(float sx, float sy) throws ParseException { 135 affineTransform.concatenate(AffineTransform.getScaleInstance(sx, sy)); 136 } 137 138 141 public void skewX(float skx) throws ParseException { 142 affineTransform.concatenate 143 (AffineTransform.getShearInstance(Math.tan(Math.PI * skx / 180), 144 0)); 145 } 146 147 150 public void skewY(float sky) throws ParseException { 151 affineTransform.concatenate 152 (AffineTransform.getShearInstance(0, 153 Math.tan(Math.PI * sky / 180))); 154 } 155 156 159 public void endTransformList() throws ParseException { 160 } 161 } 162 | Popular Tags |