blob: 86ae4c28d9dcdbd90b6199d0c398f5b4d5bb5889 [file] [log] [blame]
reed@android.com8a1c16f2008-12-17 15:59:43 +00001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef SkSVGParser_DEFINED
18#define SkSVGParser_DEFINED
19
20#include "SkMatrix.h"
21#include "SkTDict.h"
22#include "SkTDStack.h"
23#include "SkSVGPaintState.h"
24#include "SkSVGTypes.h"
25#include "SkStream.h"
26#include "SkString.h"
27#include "SkXMLParser.h"
28#include "SkXMLWriter.h"
29
30class SkSVGBase;
31class SkSVGElement;
32
33class SkSVGParser : public SkXMLParser {
34public:
35 SkSVGParser();
36 virtual ~SkSVGParser();
37 void _addAttribute(const char* attrName, const char* attrValue) {
38 fXMLWriter.addAttribute(attrName, attrValue); }
39 void _addAttribute(const char* attrName, SkString& attrValue) {
40 fXMLWriter.addAttribute(attrName, attrValue.c_str()); }
41 void _addAttributeLen(const char* attrName, const char* attrValue, size_t len) {
42 fXMLWriter.addAttributeLen(attrName, attrValue, len); }
43 void _endElement() { fXMLWriter.endElement(); }
44 int findAttribute(SkSVGBase* , const char* attrValue, size_t len, bool isPaint);
45 const char* getFinal();
46 SkTDict<SkSVGElement*>& getIDs() { return fIDs; }
47 SkString& getPaintLast(SkSVGPaint::Field field);
48 void _startElement(const char name[]) { fXMLWriter.startElement(name); }
49 void translate(SkSVGElement*, bool isDef);
50 void translateMatrix(SkString& , SkString* id);
51 static void ConvertToArray(SkString& vals);
52protected:
53 virtual bool onAddAttribute(const char name[], const char value[]);
54 bool onAddAttributeLen(const char name[], const char value[], size_t len);
55 virtual bool onEndElement(const char elem[]);
56 virtual bool onStartElement(const char elem[]);
57 bool onStartElementLen(const char elem[], size_t len);
58 virtual bool onText(const char text[], int len);
59private:
60 bool isStrokeAndFill(SkSVGPaint** stroke, SkSVGPaint** fill);
61 static SkSVGElement* CreateElement(SkSVGTypes type, SkSVGElement* parent);
62 static void Delete(SkTDArray<SkSVGElement*>& fChildren);
63 static SkSVGTypes GetType(const char name[], size_t len);
64 SkSVGPaint* fHead;
65 SkSVGPaint fEmptyPaint;
66 SkSVGPaint fLastFlush;
67 SkString fLastColor;
68 SkMatrix fLastTransform;
69 SkTDArray<SkSVGElement*> fChildren;
70 SkTDict<SkSVGElement*> fIDs;
71 SkTDArray<SkSVGElement*> fParents;
72 SkDynamicMemoryWStream fStream;
73 SkXMLStreamWriter fXMLWriter;
74 SkSVGElement* fCurrElement;
75 SkBool8 fInSVG;
76 SkBool8 fSuppressPaint;
77 friend class SkSVGPaint;
78 friend class SkSVGGradient;
79};
80
81#endif // SkSVGParser_DEFINED