1 18 package org.apache.batik.dom.svg; 19 20 import java.awt.geom.AffineTransform ; 21 22 import org.w3c.dom.svg.SVGMatrix; 23 import org.w3c.dom.svg.SVGTransform; 24 25 33 public abstract class AbstractSVGTransform implements SVGTransform { 34 35 40 protected short type = SVG_TRANSFORM_UNKNOWN; 41 42 47 protected AffineTransform affineTransform; 48 49 55 protected float angle; 56 57 protected float x; 58 59 protected float y; 60 61 66 protected abstract SVGMatrix createMatrix(); 67 68 71 protected AbstractSVGTransform(){ 72 } 73 74 76 protected void setType(short type){ 77 this.type = type; 78 } 79 80 protected float getX(){ 81 return x; 82 } 83 84 protected float getY(){ 85 return y; 86 } 87 88 90 public short getType( ){ 91 return type; 92 } 93 94 96 public SVGMatrix getMatrix( ){ 97 return createMatrix(); 98 } 99 101 public float getAngle( ){ 102 return angle; 103 } 104 106 public void setMatrix ( SVGMatrix matrix ){ 107 type = SVG_TRANSFORM_MATRIX; 108 affineTransform = new AffineTransform (matrix.getA(),matrix.getB(),matrix.getC(), 109 matrix.getD(),matrix.getE(),matrix.getF()); 110 } 111 113 public void setTranslate ( float tx, float ty ){ 114 type = SVG_TRANSFORM_TRANSLATE; 115 affineTransform = AffineTransform.getTranslateInstance(tx,ty); 116 } 117 119 public void setScale ( float sx, float sy ){ 120 type = SVG_TRANSFORM_SCALE; 121 affineTransform = AffineTransform.getScaleInstance(sx,sy); 122 } 123 125 public void setRotate ( float angle, float cx, float cy ){ 126 type = SVG_TRANSFORM_ROTATE; 127 affineTransform = AffineTransform.getRotateInstance(Math.toRadians(angle),cx,cy); 128 this.angle = angle; 129 this.x = cx; 130 this.y = cy; 131 } 132 134 public void setSkewX ( float angle ){ 135 type = SVG_TRANSFORM_SKEWX; 136 affineTransform = new AffineTransform (1.0,Math.tan(Math.toRadians(angle)),0.0, 137 1.0,0.0,0.0); 138 this.angle = angle; 139 } 140 142 public void setSkewY ( float angle ){ 143 type = SVG_TRANSFORM_SKEWY; 144 this.angle = angle; 145 affineTransform = new AffineTransform (1.0,0.0,Math.tan(Math.toRadians(angle)), 146 1.0,0.0,0.0); 147 } 148 149 } 150 151 | Popular Tags |