1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* ***** BEGIN LICENSE BLOCK *****
3 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License. You may obtain a copy of the License at
8 : * http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * The Original Code is the Mozilla SVG project.
16 : *
17 : * The Initial Developer of the Original Code is
18 : * Crocodile Clips Ltd..
19 : * Portions created by the Initial Developer are Copyright (C) 2001
20 : * the Initial Developer. All Rights Reserved.
21 : *
22 : * Contributor(s):
23 : * Alex Fritze <alex.fritze@crocodile-clips.com> (original author)
24 : *
25 : * Alternatively, the contents of this file may be used under the terms of
26 : * either of the GNU General Public License Version 2 or later (the "GPL"),
27 : * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 : * in which case the provisions of the GPL or the LGPL are applicable instead
29 : * of those above. If you wish to allow use of your version of this file only
30 : * under the terms of either the GPL or the LGPL, and not to allow others to
31 : * use your version of this file under the terms of the MPL, indicate your
32 : * decision by deleting the provisions above and replace them with the notice
33 : * and other provisions required by the GPL or the LGPL. If you do not delete
34 : * the provisions above, a recipient may use your version of this file under
35 : * the terms of any one of the MPL, the GPL or the LGPL.
36 : *
37 : * ***** END LICENSE BLOCK ***** */
38 :
39 : #ifndef __NS_SVGPATHDATAPARSER_H__
40 : #define __NS_SVGPATHDATAPARSER_H__
41 :
42 : #include "gfxPoint.h"
43 : #include "nsSVGDataParser.h"
44 :
45 : namespace mozilla {
46 : class SVGPathData;
47 : }
48 :
49 : ////////////////////////////////////////////////////////////////////////
50 : // nsSVGPathDataParser: a simple recursive descent parser that builds
51 : // nsIDOMSVGPathSegs from path data strings. The grammar for path data
52 : // can be found in SVG CR 20001102, chapter 8.
53 :
54 : class nsSVGPathDataParser : public nsSVGDataParser
55 0 : {
56 : protected:
57 : // Path data storage
58 : virtual nsresult StoreMoveTo(bool absCoords, float x, float y) = 0;
59 : virtual nsresult StoreClosePath() = 0;
60 : virtual nsresult StoreLineTo(bool absCoords, float x, float y) = 0;
61 : virtual nsresult StoreHLineTo(bool absCoords, float x) = 0;
62 : virtual nsresult StoreVLineTo(bool absCoords, float y) = 0;
63 : virtual nsresult StoreCurveTo(bool absCoords, float x, float y,
64 : float x1, float y1, float x2, float y2) = 0;
65 : virtual nsresult StoreSmoothCurveTo(bool absCoords, float x, float y,
66 : float x2, float y2) = 0;
67 : virtual nsresult StoreQuadCurveTo(bool absCoords, float x, float y,
68 : float x1, float y1) = 0;
69 : virtual nsresult StoreSmoothQuadCurveTo(bool absCoords,
70 : float x, float y) = 0;
71 : virtual nsresult StoreEllipticalArc(bool absCoords, float x, float y,
72 : float r1, float r2, float angle,
73 : bool largeArcFlag, bool sweepFlag) = 0;
74 : virtual nsresult Match();
75 :
76 : nsresult MatchCoordPair(float* aX, float* aY);
77 : bool IsTokenCoordPairStarter();
78 :
79 : nsresult MatchCoord(float* aX);
80 : bool IsTokenCoordStarter();
81 :
82 : nsresult MatchFlag(bool* f);
83 :
84 : nsresult MatchSvgPath();
85 :
86 : nsresult MatchSubPaths();
87 : bool IsTokenSubPathsStarter();
88 :
89 : nsresult MatchSubPath();
90 : bool IsTokenSubPathStarter();
91 :
92 : nsresult MatchSubPathElements();
93 : bool IsTokenSubPathElementsStarter();
94 :
95 : nsresult MatchSubPathElement();
96 : bool IsTokenSubPathElementStarter();
97 :
98 : nsresult MatchMoveto();
99 : nsresult MatchMovetoArgSeq(bool absCoords);
100 :
101 : nsresult MatchClosePath();
102 :
103 : nsresult MatchLineto();
104 :
105 : nsresult MatchLinetoArgSeq(bool absCoords);
106 : bool IsTokenLinetoArgSeqStarter();
107 :
108 : nsresult MatchHorizontalLineto();
109 : nsresult MatchHorizontalLinetoArgSeq(bool absCoords);
110 :
111 : nsresult MatchVerticalLineto();
112 : nsresult MatchVerticalLinetoArgSeq(bool absCoords);
113 :
114 : nsresult MatchCurveto();
115 : nsresult MatchCurvetoArgSeq(bool absCoords);
116 : nsresult MatchCurvetoArg(float* x, float* y, float* x1,
117 : float* y1, float* x2, float* y2);
118 : bool IsTokenCurvetoArgStarter();
119 :
120 : nsresult MatchSmoothCurveto();
121 : nsresult MatchSmoothCurvetoArgSeq(bool absCoords);
122 : nsresult MatchSmoothCurvetoArg(float* x, float* y, float* x2, float* y2);
123 : bool IsTokenSmoothCurvetoArgStarter();
124 :
125 : nsresult MatchQuadBezierCurveto();
126 : nsresult MatchQuadBezierCurvetoArgSeq(bool absCoords);
127 : nsresult MatchQuadBezierCurvetoArg(float* x, float* y, float* x1, float* y1);
128 : bool IsTokenQuadBezierCurvetoArgStarter();
129 :
130 : nsresult MatchSmoothQuadBezierCurveto();
131 : nsresult MatchSmoothQuadBezierCurvetoArgSeq(bool absCoords);
132 :
133 : nsresult MatchEllipticalArc();
134 : nsresult MatchEllipticalArcArgSeq(bool absCoords);
135 : nsresult MatchEllipticalArcArg(float* x, float* y,
136 : float* r1, float* r2, float* angle,
137 : bool* largeArcFlag, bool* sweepFlag);
138 : bool IsTokenEllipticalArcArgStarter();
139 :
140 : };
141 :
142 : class nsSVGArcConverter
143 : {
144 : public:
145 : nsSVGArcConverter(const gfxPoint &from,
146 : const gfxPoint &to,
147 : const gfxPoint &radii,
148 : double angle,
149 : bool largeArcFlag,
150 : bool sweepFlag);
151 : bool GetNextSegment(gfxPoint *cp1, gfxPoint *cp2, gfxPoint *to);
152 : protected:
153 : PRInt32 mNumSegs, mSegIndex;
154 : double mTheta, mDelta, mT;
155 : double mSinPhi, mCosPhi;
156 : double mRx, mRy;
157 : gfxPoint mFrom, mC;
158 : };
159 :
160 : class nsSVGPathDataParserToInternal : public nsSVGPathDataParser
161 : {
162 : public:
163 0 : nsSVGPathDataParserToInternal(mozilla::SVGPathData *aList)
164 0 : : mPathSegList(aList)
165 0 : {}
166 : nsresult Parse(const nsAString &aValue);
167 :
168 : protected:
169 : virtual nsresult StoreMoveTo(bool absCoords, float x, float y);
170 : virtual nsresult StoreClosePath();
171 : virtual nsresult StoreLineTo(bool absCoords, float x, float y);
172 : virtual nsresult StoreHLineTo(bool absCoords, float x);
173 : virtual nsresult StoreVLineTo(bool absCoords, float y);
174 : virtual nsresult StoreCurveTo(bool absCoords, float x, float y,
175 : float x1, float y1, float x2, float y2);
176 : virtual nsresult StoreSmoothCurveTo(bool absCoords, float x, float y,
177 : float x2, float y2);
178 : virtual nsresult StoreQuadCurveTo(bool absCoords, float x, float y,
179 : float x1, float y1);
180 : virtual nsresult StoreSmoothQuadCurveTo(bool absCoords,
181 : float x, float y);
182 : virtual nsresult StoreEllipticalArc(bool absCoords, float x, float y,
183 : float r1, float r2, float angle,
184 : bool largeArcFlag, bool sweepFlag);
185 :
186 : private:
187 : mozilla::SVGPathData *mPathSegList;
188 : };
189 :
190 : #endif // __NS_SVGPATHDATAPARSER_H__
|