1ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com
28a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/*
3ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Copyright 2006 The Android Open Source Project
48a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com *
5ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Use of this source code is governed by a BSD-style license that can be
6ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * found in the LICENSE file.
78a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */
88a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
9ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com
108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#ifndef SkSVGParser_DEFINED
118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#define SkSVGParser_DEFINED
128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkMatrix.h"
148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkTDict.h"
158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkTDStack.h"
168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkSVGPaintState.h"
178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkSVGTypes.h"
188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkStream.h"
198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkString.h"
208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkXMLParser.h"
218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkXMLWriter.h"
228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkSVGBase;
248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkSVGElement;
258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkSVGParser : public SkXMLParser {
278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic:
285ee64ad6b54edc07849fa04681801802b7102590reed@android.com    SkSVGParser(SkXMLParserError* err = NULL);
298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual ~SkSVGParser();
308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void _addAttribute(const char* attrName, const char* attrValue) {
318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        fXMLWriter.addAttribute(attrName, attrValue); }
328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void _addAttribute(const char* attrName, SkString& attrValue) {
338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        fXMLWriter.addAttribute(attrName, attrValue.c_str()); }
348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void _addAttributeLen(const char* attrName, const char* attrValue, size_t len) {
358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        fXMLWriter.addAttributeLen(attrName, attrValue, len); }
368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void _endElement() { fXMLWriter.endElement(); }
378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    int findAttribute(SkSVGBase* , const char* attrValue, size_t len, bool isPaint);
388a85d0c4938173476d037d7af0ee3b9436a1234ereed@google.com//    const char* getFinal();
398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkTDict<SkSVGElement*>& getIDs() { return fIDs; }
408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkString& getPaintLast(SkSVGPaint::Field field);
418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void _startElement(const char name[]) { fXMLWriter.startElement(name); }
428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void translate(SkSVGElement*, bool isDef);
438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void translateMatrix(SkString& , SkString* id);
448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    static void ConvertToArray(SkString& vals);
458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprotected:
468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual bool onAddAttribute(const char name[], const char value[]);
478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    bool onAddAttributeLen(const char name[], const char value[], size_t len);
488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual bool onEndElement(const char elem[]);
498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual bool onStartElement(const char elem[]);
508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    bool onStartElementLen(const char elem[], size_t len);
518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual bool onText(const char text[], int len);
528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate:
538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    bool isStrokeAndFill(SkSVGPaint** stroke, SkSVGPaint** fill);
548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    static SkSVGElement* CreateElement(SkSVGTypes type, SkSVGElement* parent);
558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    static void Delete(SkTDArray<SkSVGElement*>& fChildren);
568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    static SkSVGTypes GetType(const char name[], size_t len);
578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkSVGPaint* fHead;
58fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com    SkSVGPaint fEmptyPaint;
598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkSVGPaint fLastFlush;
608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkString fLastColor;
618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkMatrix fLastTransform;
628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkTDArray<SkSVGElement*> fChildren;
638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkTDict<SkSVGElement*> fIDs;
648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkTDArray<SkSVGElement*> fParents;
658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkDynamicMemoryWStream fStream;
668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkXMLStreamWriter fXMLWriter;
678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkSVGElement*   fCurrElement;
688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkBool8 fInSVG;
698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkBool8 fSuppressPaint;
708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    friend class SkSVGPaint;
718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    friend class SkSVGGradient;
728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com};
738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif // SkSVGParser_DEFINED
75