1 18 19 package org.apache.batik.dom.svg; 20 21 import java.awt.geom.Point2D ; 22 23 import org.w3c.dom.svg.SVGPoint; 24 import org.w3c.dom.svg.SVGMatrix; 25 import org.w3c.dom.DOMException ; 26 27 33 public class SVGPathSupport { 34 35 38 public static float getTotalLength(SVGOMPathElement path) { 39 SVGPathContext pathCtx = (SVGPathContext)path.getSVGContext(); 40 return pathCtx.getTotalLength(); 41 } 42 43 44 47 public static SVGPoint getPointAtLength(final SVGOMPathElement path, 48 final float distance) { 49 final SVGPathContext pathCtx = (SVGPathContext)path.getSVGContext(); 50 if (pathCtx == null) return null; 51 52 return new SVGPoint() { 53 public float getX() { 54 Point2D pt = pathCtx.getPointAtLength(distance); 55 return (float)pt.getX(); 56 } 57 public float getY() { 58 Point2D pt = pathCtx.getPointAtLength(distance); 59 return (float)pt.getY(); 60 } 61 public void setX(float x) throws DOMException { 62 throw path.createDOMException 63 (DOMException.NO_MODIFICATION_ALLOWED_ERR, 64 "readonly.point", null); 65 } 66 public void setY(float y) throws DOMException { 67 throw path.createDOMException 68 (DOMException.NO_MODIFICATION_ALLOWED_ERR, 69 "readonly.point", null); 70 } 71 public SVGPoint matrixTransform ( SVGMatrix matrix ) { 72 throw path.createDOMException 73 (DOMException.NO_MODIFICATION_ALLOWED_ERR, 74 "readonly.point", null); 75 } 76 }; 77 } 78 }; 79 | Popular Tags |