michael@0: michael@0: /* michael@0: * Copyright 2006 The Android Open Source Project michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: michael@0: #ifndef SkSVGParser_DEFINED michael@0: #define SkSVGParser_DEFINED michael@0: michael@0: #include "SkMatrix.h" michael@0: #include "SkTDict.h" michael@0: #include "SkTDStack.h" michael@0: #include "SkSVGPaintState.h" michael@0: #include "SkSVGTypes.h" michael@0: #include "SkStream.h" michael@0: #include "SkString.h" michael@0: #include "SkXMLParser.h" michael@0: #include "SkXMLWriter.h" michael@0: michael@0: class SkSVGBase; michael@0: class SkSVGElement; michael@0: michael@0: class SkSVGParser : public SkXMLParser { michael@0: public: michael@0: SkSVGParser(SkXMLParserError* err = NULL); michael@0: virtual ~SkSVGParser(); michael@0: void _addAttribute(const char* attrName, const char* attrValue) { michael@0: fXMLWriter.addAttribute(attrName, attrValue); } michael@0: void _addAttribute(const char* attrName, SkString& attrValue) { michael@0: fXMLWriter.addAttribute(attrName, attrValue.c_str()); } michael@0: void _addAttributeLen(const char* attrName, const char* attrValue, size_t len) { michael@0: fXMLWriter.addAttributeLen(attrName, attrValue, len); } michael@0: void _endElement() { fXMLWriter.endElement(); } michael@0: int findAttribute(SkSVGBase* , const char* attrValue, size_t len, bool isPaint); michael@0: // const char* getFinal(); michael@0: SkTDict& getIDs() { return fIDs; } michael@0: SkString& getPaintLast(SkSVGPaint::Field field); michael@0: void _startElement(const char name[]) { fXMLWriter.startElement(name); } michael@0: void translate(SkSVGElement*, bool isDef); michael@0: void translateMatrix(SkString& , SkString* id); michael@0: static void ConvertToArray(SkString& vals); michael@0: protected: michael@0: virtual bool onAddAttribute(const char name[], const char value[]); michael@0: bool onAddAttributeLen(const char name[], const char value[], size_t len); michael@0: virtual bool onEndElement(const char elem[]); michael@0: virtual bool onStartElement(const char elem[]); michael@0: bool onStartElementLen(const char elem[], size_t len); michael@0: virtual bool onText(const char text[], int len); michael@0: private: michael@0: bool isStrokeAndFill(SkSVGPaint** stroke, SkSVGPaint** fill); michael@0: static SkSVGElement* CreateElement(SkSVGTypes type, SkSVGElement* parent); michael@0: static void Delete(SkTDArray& fChildren); michael@0: static SkSVGTypes GetType(const char name[], size_t len); michael@0: SkSVGPaint* fHead; michael@0: SkSVGPaint fEmptyPaint; michael@0: SkSVGPaint fLastFlush; michael@0: SkString fLastColor; michael@0: SkMatrix fLastTransform; michael@0: SkTDArray fChildren; michael@0: SkTDict fIDs; michael@0: SkTDArray fParents; michael@0: SkDynamicMemoryWStream fStream; michael@0: SkXMLStreamWriter fXMLWriter; michael@0: SkSVGElement* fCurrElement; michael@0: SkBool8 fInSVG; michael@0: SkBool8 fSuppressPaint; michael@0: friend class SkSVGPaint; michael@0: friend class SkSVGGradient; michael@0: }; michael@0: michael@0: #endif // SkSVGParser_DEFINED