Back to index

lightning-sunbird  0.9+nobinonly
nsSVGPathDataParser.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is the Mozilla SVG project.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Crocodile Clips Ltd..
00019  * Portions created by the Initial Developer are Copyright (C) 2001
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Alex Fritze <alex.fritze@crocodile-clips.com> (original author)
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either of the GNU General Public License Version 2 or later (the "GPL"),
00027  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 #ifndef __NS_SVGPATHDATAPARSER_H__
00040 #define __NS_SVGPATHDATAPARSER_H__
00041 
00042 #include "nsCOMPtr.h"
00043 #include "nsVoidArray.h"
00044 #include "nsIDOMSVGPathSeg.h"
00045 
00047 // nsSVGPathDataParser: a simple recursive descent parser that builds
00048 // nsIDOMPathSegs from path data strings. The grammar for path data
00049 // can be found in SVG CR 20001102, chapter 8.
00050 
00051 class nsSVGPathDataParser
00052 {
00053 public:
00054   nsSVGPathDataParser(nsVoidArray* data);
00055   nsresult Parse(const char* str);
00056 
00057 protected:
00058   nsVoidArray *mData;
00059   
00060   const char* inputpos;
00061   
00062   char tokenval;
00063   const char* tokenpos;
00064   enum { DIGIT, WSP, COMMA, POINT, SIGN, OTHER, END } tokentype;
00065   
00066 
00067   // helpers
00068   nsresult AppendSegment(nsIDOMSVGPathSeg* seg);
00069   void getNextToken();
00070   void windBack(const char* pos);
00071   nsresult match(char tok);
00072 
00073 
00074   nsresult matchSvgPath();
00075   
00076   nsresult matchSubPaths();
00077   PRBool isTokenSubPathsStarter();
00078   
00079   nsresult matchSubPath();
00080   PRBool isTokenSubPathStarter();
00081   
00082   nsresult matchSubPathElements();
00083   PRBool isTokenSubPathElementsStarter();
00084 
00085   nsresult matchSubPathElement();
00086   PRBool isTokenSubPathElementStarter();
00087 
00088   nsresult matchMoveto();
00089   nsresult matchMovetoArgSeq(PRBool absCoords);
00090   
00091   nsresult matchClosePath();
00092   
00093   nsresult matchLineto();
00094   
00095   nsresult matchLinetoArgSeq(PRBool absCoords);
00096   PRBool isTokenLinetoArgSeqStarter();
00097   
00098   nsresult matchHorizontalLineto();
00099   nsresult matchHorizontalLinetoArgSeq(PRBool absCoords);
00100   
00101   nsresult matchVerticalLineto();
00102   nsresult matchVerticalLinetoArgSeq(PRBool absCoords);
00103   
00104   nsresult matchCurveto();
00105   nsresult matchCurvetoArgSeq(PRBool absCoords);
00106   nsresult matchCurvetoArg(float* x, float* y, float* x1,
00107                            float* y1, float* x2, float* y2);
00108   PRBool isTokenCurvetoArgStarter();
00109   
00110   nsresult matchSmoothCurveto();
00111   nsresult matchSmoothCurvetoArgSeq(PRBool absCoords);
00112   nsresult matchSmoothCurvetoArg(float* x, float* y, float* x2, float* y2);
00113   PRBool isTokenSmoothCurvetoArgStarter();
00114   
00115   nsresult matchQuadBezierCurveto();
00116   nsresult matchQuadBezierCurvetoArgSeq(PRBool absCoords);  
00117   nsresult matchQuadBezierCurvetoArg(float* x, float* y, float* x1, float* y1);
00118   PRBool isTokenQuadBezierCurvetoArgStarter();
00119   
00120   nsresult matchSmoothQuadBezierCurveto();  
00121   nsresult matchSmoothQuadBezierCurvetoArgSeq(PRBool absCoords);
00122   
00123   nsresult matchEllipticalArc();  
00124   nsresult matchEllipticalArcArgSeq(PRBool absCoords);
00125   nsresult matchEllipticalArcArg(float* x, float* y,
00126                                  float* r1, float* r2, float* angle,
00127                                  PRBool* largeArcFlag, PRBool* sweepFlag);
00128   PRBool isTokenEllipticalArcArgStarter();
00129   
00130   nsresult matchCoordPair(float* x, float* y);
00131   PRBool isTokenCoordPairStarter();
00132   
00133   nsresult matchCoord(float* x);
00134   PRBool isTokenCoordStarter();
00135   
00136   nsresult matchNonNegativeNumber(float* x);
00137   PRBool isTokenNonNegativeNumberStarter();
00138   
00139   nsresult matchNumber(float* x);
00140   PRBool isTokenNumberStarter();
00141   
00142   nsresult matchFlag(PRBool* f);
00143   
00144   nsresult matchCommaWsp();
00145   PRBool isTokenCommaWspStarter();
00146   
00147   nsresult matchIntegerConst();
00148   
00149   nsresult matchFloatingPointConst();
00150   
00151   nsresult matchFractConst();
00152   
00153   nsresult matchExponent();
00154   PRBool isTokenExponentStarter();
00155   
00156   nsresult matchDigitSeq();
00157   PRBool isTokenDigitSeqStarter();
00158   
00159   nsresult matchWsp();
00160   PRBool isTokenWspStarter();
00161   
00162 };
00163 
00164 #endif // __NS_SVGPATHDATAPARSER_H__