blob: a58729de806db5771db15cb50ad5c1052a15384b [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
reed@android.com8a1c16f2008-12-17 15:59:43 +00002/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00003 * Copyright 2006 The Android Open Source Project
reed@android.com8a1c16f2008-12-17 15:59:43 +00004 *
epoger@google.comec3ed6a2011-07-28 14:26:00 +00005 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
reed@android.com8a1c16f2008-12-17 15:59:43 +00007 */
8
epoger@google.comec3ed6a2011-07-28 14:26:00 +00009
reed@android.com8a1c16f2008-12-17 15:59:43 +000010#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
23class SkSVGBase;
24class SkSVGElement;
25
26class SkSVGParser : public SkXMLParser {
27public:
reed@android.com5ee64ad2010-05-17 14:34:13 +000028 SkSVGParser(SkXMLParserError* err = NULL);
reed@android.com8a1c16f2008-12-17 15:59:43 +000029 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.com8a85d0c2011-06-24 19:12:12 +000038// const char* getFinal();
reed@android.com8a1c16f2008-12-17 15:59:43 +000039 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);
45protected:
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);
52private:
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