epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 3 | * Copyright 2006 The Android Open Source Project |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 4 | * |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 9 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 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: |
reed@android.com | 5ee64ad | 2010-05-17 14:34:13 +0000 | [diff] [blame] | 28 | SkSVGParser(SkXMLParserError* err = NULL); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 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); |
reed@google.com | 8a85d0c | 2011-06-24 19:12:12 +0000 | [diff] [blame] | 38 | // const char* getFinal(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 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 |