From 8a1c16ff38322f0210116fa7293eb8817c7e477e Mon Sep 17 00:00:00 2001 From: "reed@android.com" Date: Wed, 17 Dec 2008 15:59:43 +0000 Subject: grab from latest android git-svn-id: http://skia.googlecode.com/svn/trunk@27 2bbb7eff-a529-9590-31e7-b0007b416f81 --- include/svg/SkSVGAttribute.h | 49 ++++++++++++++++++++++ include/svg/SkSVGBase.h | 33 +++++++++++++++ include/svg/SkSVGPaintState.h | 96 +++++++++++++++++++++++++++++++++++++++++++ include/svg/SkSVGParser.h | 81 ++++++++++++++++++++++++++++++++++++ include/svg/SkSVGTypes.h | 46 +++++++++++++++++++++ 5 files changed, 305 insertions(+) create mode 100644 include/svg/SkSVGAttribute.h create mode 100644 include/svg/SkSVGBase.h create mode 100644 include/svg/SkSVGPaintState.h create mode 100644 include/svg/SkSVGParser.h create mode 100644 include/svg/SkSVGTypes.h (limited to 'include/svg') diff --git a/include/svg/SkSVGAttribute.h b/include/svg/SkSVGAttribute.h new file mode 100644 index 0000000000..810d11c68e --- /dev/null +++ b/include/svg/SkSVGAttribute.h @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2006 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef SkSVGAttribute_DEFINED +#define SkSVGAttribute_DEFINED + +#include "SkTypes.h" + +struct SkSVGAttribute { + const char* fName; +#ifdef SK_DEBUG + size_t fOffset; +#endif +}; + +#ifndef SK_OFFSETOF +#define SK_OFFSETOF(a, b) (((size_t) (&(((a*) 1)->b)))-1) +#endif + +#ifdef SK_DEBUG +#define SVG_ATTRIBUTE(attr) { #attr, SK_OFFSETOF(BASE_CLASS, f_##attr) } +#define SVG_LITERAL_ATTRIBUTE(svgAttr, cAttr) { #svgAttr, SK_OFFSETOF(BASE_CLASS, cAttr) } +#else +#define SVG_ATTRIBUTE(attr) { #attr } +#define SVG_LITERAL_ATTRIBUTE(svgAttr, cAttr) { #svgAttr } +#endif + +#define SVG_ADD_ATTRIBUTE(attr) \ + if (f_##attr.size() > 0) \ + parser._addAttributeLen(#attr, f_##attr.c_str(), f_##attr.size()) + +#define SVG_ADD_ATTRIBUTE_ALIAS(attr, alias) \ + if (f_##alias.size() > 0) \ + parser._addAttributeLen(#attr, f_##alias.c_str(), f_##alias.size()) + +#endif // SkSVGAttribute_DEFINED diff --git a/include/svg/SkSVGBase.h b/include/svg/SkSVGBase.h new file mode 100644 index 0000000000..4d24aed4ab --- /dev/null +++ b/include/svg/SkSVGBase.h @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2006 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef SkSVGBase_DEFINED +#define SkSVGBase_DEFINED + +#include "SkSVGAttribute.h" + +class SkSVGParser; + +class SkSVGBase { +public: + virtual ~SkSVGBase(); + virtual void addAttribute(SkSVGParser& parser, int attrIndex, + const char* attrValue, size_t attrLength); + virtual int getAttributes(const SkSVGAttribute** attrPtr) = 0; +}; + +#endif // SkSVGBase_DEFINEDes(const SkSVGAttribute** attrPtr) = 0; + diff --git a/include/svg/SkSVGPaintState.h b/include/svg/SkSVGPaintState.h new file mode 100644 index 0000000000..f3f74e1753 --- /dev/null +++ b/include/svg/SkSVGPaintState.h @@ -0,0 +1,96 @@ +/* + * Copyright (C) 2006 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef SkSVGPaintState_DEFINED +#define SkSVGPaintState_DEFINED + +#include "SkSVGBase.h" +#include "SkString.h" + +class SkSVGPaint : public SkSVGBase { +public: + enum Field { + kInitial = -1, + kClipPath, + kClipRule, + kEnableBackground, + kFill, + kFillRule, + kFilter, + kFontFamily, + kFontSize, + kLetterSpacing, + kMask, + kOpacity, + kStopColor, + kStopOpacity, + kStroke, + kStroke_Dasharray, + kStroke_Linecap, + kStroke_Linejoin, + kStroke_Miterlimit, + kStroke_Width, + kStyle, + kTransform, + kTerminal + }; + + SkSVGPaint(); + virtual void addAttribute(SkSVGParser& parser, int attrIndex, + const char* attrValue, size_t attrLength); + bool flush(SkSVGParser& , bool isFlushable, bool isDef); + virtual int getAttributes(const SkSVGAttribute** attrPtr); + static void Push(SkSVGPaint** head, SkSVGPaint* add); + static void Pop(SkSVGPaint** head); + SkString* operator[](int index); + SkString fInitial; + SkString f_clipPath; + SkString f_clipRule; + SkString f_enableBackground; + SkString f_fill; + SkString f_fillRule; + SkString f_filter; + SkString f_fontFamily; + SkString f_fontSize; + SkString f_letterSpacing; + SkString f_mask; + SkString f_opacity; + SkString f_stopColor; + SkString f_stopOpacity; + SkString f_stroke; + SkString f_strokeDasharray; + SkString f_strokeLinecap; + SkString f_strokeLinejoin; + SkString f_strokeMiterlimit; + SkString f_strokeWidth; + SkString f_style; // unused, but allows array access to the rest + SkString f_transform; +#ifdef SK_DEBUG + SkString fTerminal; +#endif + SkString fTransformID; + static SkSVGAttribute gAttributes[]; + static const int kAttributesSize; +private: + void setSave(SkSVGParser& ); + bool writeChangedAttributes(SkSVGParser& , SkSVGPaint& , bool* changed); + bool writeChangedElements(SkSVGParser& , SkSVGPaint& , bool* changed); + SkSVGPaint* fNext; + friend class SkSVGParser; + typedef SkSVGPaint BASE_CLASS; +}; + +#endif // SkSVGPaintState_DEFINED diff --git a/include/svg/SkSVGParser.h b/include/svg/SkSVGParser.h new file mode 100644 index 0000000000..86ae4c28d9 --- /dev/null +++ b/include/svg/SkSVGParser.h @@ -0,0 +1,81 @@ +/* + * Copyright (C) 2006 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef SkSVGParser_DEFINED +#define SkSVGParser_DEFINED + +#include "SkMatrix.h" +#include "SkTDict.h" +#include "SkTDStack.h" +#include "SkSVGPaintState.h" +#include "SkSVGTypes.h" +#include "SkStream.h" +#include "SkString.h" +#include "SkXMLParser.h" +#include "SkXMLWriter.h" + +class SkSVGBase; +class SkSVGElement; + +class SkSVGParser : public SkXMLParser { +public: + SkSVGParser(); + virtual ~SkSVGParser(); + void _addAttribute(const char* attrName, const char* attrValue) { + fXMLWriter.addAttribute(attrName, attrValue); } + void _addAttribute(const char* attrName, SkString& attrValue) { + fXMLWriter.addAttribute(attrName, attrValue.c_str()); } + void _addAttributeLen(const char* attrName, const char* attrValue, size_t len) { + fXMLWriter.addAttributeLen(attrName, attrValue, len); } + void _endElement() { fXMLWriter.endElement(); } + int findAttribute(SkSVGBase* , const char* attrValue, size_t len, bool isPaint); + const char* getFinal(); + SkTDict& getIDs() { return fIDs; } + SkString& getPaintLast(SkSVGPaint::Field field); + void _startElement(const char name[]) { fXMLWriter.startElement(name); } + void translate(SkSVGElement*, bool isDef); + void translateMatrix(SkString& , SkString* id); + static void ConvertToArray(SkString& vals); +protected: + virtual bool onAddAttribute(const char name[], const char value[]); + bool onAddAttributeLen(const char name[], const char value[], size_t len); + virtual bool onEndElement(const char elem[]); + virtual bool onStartElement(const char elem[]); + bool onStartElementLen(const char elem[], size_t len); + virtual bool onText(const char text[], int len); +private: + bool isStrokeAndFill(SkSVGPaint** stroke, SkSVGPaint** fill); + static SkSVGElement* CreateElement(SkSVGTypes type, SkSVGElement* parent); + static void Delete(SkTDArray& fChildren); + static SkSVGTypes GetType(const char name[], size_t len); + SkSVGPaint* fHead; + SkSVGPaint fEmptyPaint; + SkSVGPaint fLastFlush; + SkString fLastColor; + SkMatrix fLastTransform; + SkTDArray fChildren; + SkTDict fIDs; + SkTDArray fParents; + SkDynamicMemoryWStream fStream; + SkXMLStreamWriter fXMLWriter; + SkSVGElement* fCurrElement; + SkBool8 fInSVG; + SkBool8 fSuppressPaint; + friend class SkSVGPaint; + friend class SkSVGGradient; +}; + +#endif // SkSVGParser_DEFINED diff --git a/include/svg/SkSVGTypes.h b/include/svg/SkSVGTypes.h new file mode 100644 index 0000000000..38d63cec1c --- /dev/null +++ b/include/svg/SkSVGTypes.h @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2006 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef SkSVGTypes_DEFINED +#define SkSVGTypes_DEFINED + +enum SkSVGTypes { + SkSVGType_Circle, + SkSVGType_ClipPath, + SkSVGType_Defs, + SkSVGType_Ellipse, + SkSVGType_FeColorMatrix, + SkSVGType_Filter, + SkSVGType_G, + SkSVGType_Image, + SkSVGType_Line, + SkSVGType_LinearGradient, + SkSVGType_Mask, + SkSVGType_Metadata, + SkSVGType_Path, + SkSVGType_Polygon, + SkSVGType_Polyline, + SkSVGType_RadialGradient, + SkSVGType_Rect, + SkSVGType_SVG, + SkSVGType_Stop, + SkSVGType_Symbol, + SkSVGType_Text, + SkSVGType_Tspan, + SkSVGType_Use +}; + +#endif // SkSVGTypes_DEFINED -- cgit v1.2.3