|
1 |
|
2 /* |
|
3 * Copyright 2006 The Android Open Source Project |
|
4 * |
|
5 * Use of this source code is governed by a BSD-style license that can be |
|
6 * found in the LICENSE file. |
|
7 */ |
|
8 |
|
9 |
|
10 #ifndef SkSVGParser_DEFINED |
|
11 #define SkSVGParser_DEFINED |
|
12 |
|
13 #include "SkMatrix.h" |
|
14 #include "SkTDict.h" |
|
15 #include "SkTDStack.h" |
|
16 #include "SkSVGPaintState.h" |
|
17 #include "SkSVGTypes.h" |
|
18 #include "SkStream.h" |
|
19 #include "SkString.h" |
|
20 #include "SkXMLParser.h" |
|
21 #include "SkXMLWriter.h" |
|
22 |
|
23 class SkSVGBase; |
|
24 class SkSVGElement; |
|
25 |
|
26 class SkSVGParser : public SkXMLParser { |
|
27 public: |
|
28 SkSVGParser(SkXMLParserError* err = NULL); |
|
29 virtual ~SkSVGParser(); |
|
30 void _addAttribute(const char* attrName, const char* attrValue) { |
|
31 fXMLWriter.addAttribute(attrName, attrValue); } |
|
32 void _addAttribute(const char* attrName, SkString& attrValue) { |
|
33 fXMLWriter.addAttribute(attrName, attrValue.c_str()); } |
|
34 void _addAttributeLen(const char* attrName, const char* attrValue, size_t len) { |
|
35 fXMLWriter.addAttributeLen(attrName, attrValue, len); } |
|
36 void _endElement() { fXMLWriter.endElement(); } |
|
37 int findAttribute(SkSVGBase* , const char* attrValue, size_t len, bool isPaint); |
|
38 // const char* getFinal(); |
|
39 SkTDict<SkSVGElement*>& getIDs() { return fIDs; } |
|
40 SkString& getPaintLast(SkSVGPaint::Field field); |
|
41 void _startElement(const char name[]) { fXMLWriter.startElement(name); } |
|
42 void translate(SkSVGElement*, bool isDef); |
|
43 void translateMatrix(SkString& , SkString* id); |
|
44 static void ConvertToArray(SkString& vals); |
|
45 protected: |
|
46 virtual bool onAddAttribute(const char name[], const char value[]); |
|
47 bool onAddAttributeLen(const char name[], const char value[], size_t len); |
|
48 virtual bool onEndElement(const char elem[]); |
|
49 virtual bool onStartElement(const char elem[]); |
|
50 bool onStartElementLen(const char elem[], size_t len); |
|
51 virtual bool onText(const char text[], int len); |
|
52 private: |
|
53 bool isStrokeAndFill(SkSVGPaint** stroke, SkSVGPaint** fill); |
|
54 static SkSVGElement* CreateElement(SkSVGTypes type, SkSVGElement* parent); |
|
55 static void Delete(SkTDArray<SkSVGElement*>& fChildren); |
|
56 static SkSVGTypes GetType(const char name[], size_t len); |
|
57 SkSVGPaint* fHead; |
|
58 SkSVGPaint fEmptyPaint; |
|
59 SkSVGPaint fLastFlush; |
|
60 SkString fLastColor; |
|
61 SkMatrix fLastTransform; |
|
62 SkTDArray<SkSVGElement*> fChildren; |
|
63 SkTDict<SkSVGElement*> fIDs; |
|
64 SkTDArray<SkSVGElement*> fParents; |
|
65 SkDynamicMemoryWStream fStream; |
|
66 SkXMLStreamWriter fXMLWriter; |
|
67 SkSVGElement* fCurrElement; |
|
68 SkBool8 fInSVG; |
|
69 SkBool8 fSuppressPaint; |
|
70 friend class SkSVGPaint; |
|
71 friend class SkSVGGradient; |
|
72 }; |
|
73 |
|
74 #endif // SkSVGParser_DEFINED |