1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/skia/trunk/include/svg/SkSVGParser.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,74 @@ 1.4 + 1.5 +/* 1.6 + * Copyright 2006 The Android Open Source Project 1.7 + * 1.8 + * Use of this source code is governed by a BSD-style license that can be 1.9 + * found in the LICENSE file. 1.10 + */ 1.11 + 1.12 + 1.13 +#ifndef SkSVGParser_DEFINED 1.14 +#define SkSVGParser_DEFINED 1.15 + 1.16 +#include "SkMatrix.h" 1.17 +#include "SkTDict.h" 1.18 +#include "SkTDStack.h" 1.19 +#include "SkSVGPaintState.h" 1.20 +#include "SkSVGTypes.h" 1.21 +#include "SkStream.h" 1.22 +#include "SkString.h" 1.23 +#include "SkXMLParser.h" 1.24 +#include "SkXMLWriter.h" 1.25 + 1.26 +class SkSVGBase; 1.27 +class SkSVGElement; 1.28 + 1.29 +class SkSVGParser : public SkXMLParser { 1.30 +public: 1.31 + SkSVGParser(SkXMLParserError* err = NULL); 1.32 + virtual ~SkSVGParser(); 1.33 + void _addAttribute(const char* attrName, const char* attrValue) { 1.34 + fXMLWriter.addAttribute(attrName, attrValue); } 1.35 + void _addAttribute(const char* attrName, SkString& attrValue) { 1.36 + fXMLWriter.addAttribute(attrName, attrValue.c_str()); } 1.37 + void _addAttributeLen(const char* attrName, const char* attrValue, size_t len) { 1.38 + fXMLWriter.addAttributeLen(attrName, attrValue, len); } 1.39 + void _endElement() { fXMLWriter.endElement(); } 1.40 + int findAttribute(SkSVGBase* , const char* attrValue, size_t len, bool isPaint); 1.41 +// const char* getFinal(); 1.42 + SkTDict<SkSVGElement*>& getIDs() { return fIDs; } 1.43 + SkString& getPaintLast(SkSVGPaint::Field field); 1.44 + void _startElement(const char name[]) { fXMLWriter.startElement(name); } 1.45 + void translate(SkSVGElement*, bool isDef); 1.46 + void translateMatrix(SkString& , SkString* id); 1.47 + static void ConvertToArray(SkString& vals); 1.48 +protected: 1.49 + virtual bool onAddAttribute(const char name[], const char value[]); 1.50 + bool onAddAttributeLen(const char name[], const char value[], size_t len); 1.51 + virtual bool onEndElement(const char elem[]); 1.52 + virtual bool onStartElement(const char elem[]); 1.53 + bool onStartElementLen(const char elem[], size_t len); 1.54 + virtual bool onText(const char text[], int len); 1.55 +private: 1.56 + bool isStrokeAndFill(SkSVGPaint** stroke, SkSVGPaint** fill); 1.57 + static SkSVGElement* CreateElement(SkSVGTypes type, SkSVGElement* parent); 1.58 + static void Delete(SkTDArray<SkSVGElement*>& fChildren); 1.59 + static SkSVGTypes GetType(const char name[], size_t len); 1.60 + SkSVGPaint* fHead; 1.61 + SkSVGPaint fEmptyPaint; 1.62 + SkSVGPaint fLastFlush; 1.63 + SkString fLastColor; 1.64 + SkMatrix fLastTransform; 1.65 + SkTDArray<SkSVGElement*> fChildren; 1.66 + SkTDict<SkSVGElement*> fIDs; 1.67 + SkTDArray<SkSVGElement*> fParents; 1.68 + SkDynamicMemoryWStream fStream; 1.69 + SkXMLStreamWriter fXMLWriter; 1.70 + SkSVGElement* fCurrElement; 1.71 + SkBool8 fInSVG; 1.72 + SkBool8 fSuppressPaint; 1.73 + friend class SkSVGPaint; 1.74 + friend class SkSVGGradient; 1.75 +}; 1.76 + 1.77 +#endif // SkSVGParser_DEFINED