001: /*
002:
003: Licensed to the Apache Software Foundation (ASF) under one or more
004: contributor license agreements. See the NOTICE file distributed with
005: this work for additional information regarding copyright ownership.
006: The ASF licenses this file to You under the Apache License, Version 2.0
007: (the "License"); you may not use this file except in compliance with
008: the License. You may obtain a copy of the License at
009:
010: http://www.apache.org/licenses/LICENSE-2.0
011:
012: Unless required by applicable law or agreed to in writing, software
013: distributed under the License is distributed on an "AS IS" BASIS,
014: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: See the License for the specific language governing permissions and
016: limitations under the License.
017:
018: */
019: package org.apache.batik.dom.svg;
020:
021: import org.apache.batik.parser.PathHandler;
022:
023: import org.w3c.dom.svg.SVGPathSeg;
024: import org.w3c.dom.svg.SVGPathSegArcAbs;
025: import org.w3c.dom.svg.SVGPathSegArcRel;
026: import org.w3c.dom.svg.SVGPathSegCurvetoCubicAbs;
027: import org.w3c.dom.svg.SVGPathSegCurvetoCubicRel;
028: import org.w3c.dom.svg.SVGPathSegCurvetoCubicSmoothAbs;
029: import org.w3c.dom.svg.SVGPathSegCurvetoCubicSmoothRel;
030: import org.w3c.dom.svg.SVGPathSegCurvetoQuadraticAbs;
031: import org.w3c.dom.svg.SVGPathSegCurvetoQuadraticRel;
032: import org.w3c.dom.svg.SVGPathSegCurvetoQuadraticSmoothAbs;
033: import org.w3c.dom.svg.SVGPathSegCurvetoQuadraticSmoothRel;
034: import org.w3c.dom.svg.SVGPathSegLinetoAbs;
035: import org.w3c.dom.svg.SVGPathSegLinetoHorizontalAbs;
036: import org.w3c.dom.svg.SVGPathSegLinetoHorizontalRel;
037: import org.w3c.dom.svg.SVGPathSegLinetoRel;
038: import org.w3c.dom.svg.SVGPathSegLinetoVerticalAbs;
039: import org.w3c.dom.svg.SVGPathSegLinetoVerticalRel;
040: import org.w3c.dom.svg.SVGPathSegList;
041: import org.w3c.dom.svg.SVGPathSegMovetoAbs;
042: import org.w3c.dom.svg.SVGPathSegMovetoRel;
043:
044: /**
045: * This class provide support for the SVGAnimatedPathData
046: * interface.
047: *
048: * @author <a href="mailto:nicolas.socheleau@bitflash.com">Nicolas Socheleau</a>
049: * @version $Id: SVGAnimatedPathDataSupport.java 489964 2006-12-24 01:30:23Z cam $
050: */
051: public abstract class SVGAnimatedPathDataSupport {
052:
053: /**
054: * Uses the given {@link PathHandler} to handle the path segments from the
055: * given {@link SVGPathSegList}.
056: */
057: public static void handlePathSegList(SVGPathSegList p, PathHandler h) {
058: int n = p.getNumberOfItems();
059: h.startPath();
060: for (int i = 0; i < n; i++) {
061: SVGPathSeg seg = p.getItem(i);
062: switch (seg.getPathSegType()) {
063: case SVGPathSeg.PATHSEG_CLOSEPATH:
064: h.closePath();
065: break;
066: case SVGPathSeg.PATHSEG_MOVETO_ABS: {
067: SVGPathSegMovetoAbs s = (SVGPathSegMovetoAbs) seg;
068: h.movetoAbs(s.getX(), s.getY());
069: break;
070: }
071: case SVGPathSeg.PATHSEG_MOVETO_REL: {
072: SVGPathSegMovetoRel s = (SVGPathSegMovetoRel) seg;
073: h.movetoRel(s.getX(), s.getY());
074: break;
075: }
076: case SVGPathSeg.PATHSEG_LINETO_ABS: {
077: SVGPathSegLinetoAbs s = (SVGPathSegLinetoAbs) seg;
078: h.linetoAbs(s.getX(), s.getY());
079: break;
080: }
081: case SVGPathSeg.PATHSEG_LINETO_REL: {
082: SVGPathSegLinetoRel s = (SVGPathSegLinetoRel) seg;
083: h.linetoRel(s.getX(), s.getY());
084: break;
085: }
086: case SVGPathSeg.PATHSEG_CURVETO_CUBIC_ABS: {
087: SVGPathSegCurvetoCubicAbs s = (SVGPathSegCurvetoCubicAbs) seg;
088: h.curvetoCubicAbs(s.getX1(), s.getY1(), s.getX2(), s
089: .getY2(), s.getX(), s.getY());
090: break;
091: }
092: case SVGPathSeg.PATHSEG_CURVETO_CUBIC_REL: {
093: SVGPathSegCurvetoCubicRel s = (SVGPathSegCurvetoCubicRel) seg;
094: h.curvetoCubicRel(s.getX1(), s.getY1(), s.getX2(), s
095: .getY2(), s.getX(), s.getY());
096: break;
097: }
098: case SVGPathSeg.PATHSEG_CURVETO_QUADRATIC_ABS: {
099: SVGPathSegCurvetoQuadraticAbs s = (SVGPathSegCurvetoQuadraticAbs) seg;
100: h.curvetoQuadraticAbs(s.getX1(), s.getY1(), s.getX(), s
101: .getY());
102: break;
103: }
104: case SVGPathSeg.PATHSEG_CURVETO_QUADRATIC_REL: {
105: SVGPathSegCurvetoQuadraticRel s = (SVGPathSegCurvetoQuadraticRel) seg;
106: h.curvetoQuadraticRel(s.getX1(), s.getY1(), s.getX(), s
107: .getY());
108: break;
109: }
110: case SVGPathSeg.PATHSEG_ARC_ABS: {
111: SVGPathSegArcAbs s = (SVGPathSegArcAbs) seg;
112: h.arcAbs(s.getR1(), s.getR2(), s.getAngle(), s
113: .getLargeArcFlag(), s.getSweepFlag(), s.getX(),
114: s.getY());
115: break;
116: }
117: case SVGPathSeg.PATHSEG_ARC_REL: {
118: SVGPathSegArcRel s = (SVGPathSegArcRel) seg;
119: h.arcRel(s.getR1(), s.getR2(), s.getAngle(), s
120: .getLargeArcFlag(), s.getSweepFlag(), s.getX(),
121: s.getY());
122: break;
123: }
124: case SVGPathSeg.PATHSEG_LINETO_HORIZONTAL_ABS: {
125: SVGPathSegLinetoHorizontalAbs s = (SVGPathSegLinetoHorizontalAbs) seg;
126: h.linetoHorizontalAbs(s.getX());
127: break;
128: }
129: case SVGPathSeg.PATHSEG_LINETO_HORIZONTAL_REL: {
130: SVGPathSegLinetoHorizontalRel s = (SVGPathSegLinetoHorizontalRel) seg;
131: h.linetoHorizontalRel(s.getX());
132: break;
133: }
134: case SVGPathSeg.PATHSEG_LINETO_VERTICAL_ABS: {
135: SVGPathSegLinetoVerticalAbs s = (SVGPathSegLinetoVerticalAbs) seg;
136: h.linetoVerticalAbs(s.getY());
137: break;
138: }
139: case SVGPathSeg.PATHSEG_LINETO_VERTICAL_REL: {
140: SVGPathSegLinetoVerticalRel s = (SVGPathSegLinetoVerticalRel) seg;
141: h.linetoVerticalRel(s.getY());
142: break;
143: }
144: case SVGPathSeg.PATHSEG_CURVETO_CUBIC_SMOOTH_ABS: {
145: SVGPathSegCurvetoCubicSmoothAbs s = (SVGPathSegCurvetoCubicSmoothAbs) seg;
146: h.curvetoCubicSmoothAbs(s.getX2(), s.getY2(), s.getX(),
147: s.getY());
148: break;
149: }
150: case SVGPathSeg.PATHSEG_CURVETO_CUBIC_SMOOTH_REL: {
151: SVGPathSegCurvetoCubicSmoothRel s = (SVGPathSegCurvetoCubicSmoothRel) seg;
152: h.curvetoCubicSmoothRel(s.getX2(), s.getY2(), s.getX(),
153: s.getY());
154: break;
155: }
156: case SVGPathSeg.PATHSEG_CURVETO_QUADRATIC_SMOOTH_ABS: {
157: SVGPathSegCurvetoQuadraticSmoothAbs s = (SVGPathSegCurvetoQuadraticSmoothAbs) seg;
158: h.curvetoQuadraticSmoothAbs(s.getX(), s.getY());
159: break;
160: }
161: case SVGPathSeg.PATHSEG_CURVETO_QUADRATIC_SMOOTH_REL: {
162: SVGPathSegCurvetoQuadraticSmoothRel s = (SVGPathSegCurvetoQuadraticSmoothRel) seg;
163: h.curvetoQuadraticSmoothRel(s.getX(), s.getY());
164: break;
165: }
166: }
167: }
168: h.endPath();
169: }
170: }
|