180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru/*
380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Copyright 2006 The Android Open Source Project
480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru *
580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Use of this source code is governed by a BSD-style license that can be
680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * found in the LICENSE file.
780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */
880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
1080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#ifndef SkSVGParser_DEFINED
1180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#define SkSVGParser_DEFINED
1280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
1380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkMatrix.h"
1480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkTDict.h"
1580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkTDStack.h"
1680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkSVGPaintState.h"
1780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkSVGTypes.h"
1880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkStream.h"
1980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkString.h"
2080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkXMLParser.h"
2180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkXMLWriter.h"
2280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
2380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruclass SkSVGBase;
2480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruclass SkSVGElement;
2580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
2680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruclass SkSVGParser : public SkXMLParser {
2780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querupublic:
2880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkSVGParser(SkXMLParserError* err = NULL);
2980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    virtual ~SkSVGParser();
3080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    void _addAttribute(const char* attrName, const char* attrValue) {
3180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        fXMLWriter.addAttribute(attrName, attrValue); }
3280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    void _addAttribute(const char* attrName, SkString& attrValue) {
3380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        fXMLWriter.addAttribute(attrName, attrValue.c_str()); }
3480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    void _addAttributeLen(const char* attrName, const char* attrValue, size_t len) {
3580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        fXMLWriter.addAttributeLen(attrName, attrValue, len); }
3680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    void _endElement() { fXMLWriter.endElement(); }
3780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    int findAttribute(SkSVGBase* , const char* attrValue, size_t len, bool isPaint);
3880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru//    const char* getFinal();
3980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkTDict<SkSVGElement*>& getIDs() { return fIDs; }
4080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkString& getPaintLast(SkSVGPaint::Field field);
4180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    void _startElement(const char name[]) { fXMLWriter.startElement(name); }
4280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    void translate(SkSVGElement*, bool isDef);
4380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    void translateMatrix(SkString& , SkString* id);
4480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    static void ConvertToArray(SkString& vals);
4580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruprotected:
4680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    virtual bool onAddAttribute(const char name[], const char value[]);
4780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    bool onAddAttributeLen(const char name[], const char value[], size_t len);
4880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    virtual bool onEndElement(const char elem[]);
4980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    virtual bool onStartElement(const char elem[]);
5080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    bool onStartElementLen(const char elem[], size_t len);
5180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    virtual bool onText(const char text[], int len);
5280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruprivate:
5380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    bool isStrokeAndFill(SkSVGPaint** stroke, SkSVGPaint** fill);
5480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    static SkSVGElement* CreateElement(SkSVGTypes type, SkSVGElement* parent);
5580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    static void Delete(SkTDArray<SkSVGElement*>& fChildren);
5680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    static SkSVGTypes GetType(const char name[], size_t len);
5780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkSVGPaint* fHead;
5880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkSVGPaint fEmptyPaint;
5980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkSVGPaint fLastFlush;
6080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkString fLastColor;
6180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkMatrix fLastTransform;
6280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkTDArray<SkSVGElement*> fChildren;
6380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkTDict<SkSVGElement*> fIDs;
6480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkTDArray<SkSVGElement*> fParents;
6580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkDynamicMemoryWStream fStream;
6680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkXMLStreamWriter fXMLWriter;
6780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkSVGElement*   fCurrElement;
6880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkBool8 fInSVG;
6980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkBool8 fSuppressPaint;
7080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    friend class SkSVGPaint;
7180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    friend class SkSVGGradient;
7280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru};
7380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
7480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#endif // SkSVGParser_DEFINED
75