blob: 8e195c72b99a96dab58e8b61b264f1ded4a7a549 [file] [log] [blame]
reed@android.com8a1c16f2008-12-17 15:59:43 +00001/* libs/graphics/svg/SkSVGElements.cpp
2**
3** Copyright 2006, The Android Open Source Project
4**
5** Licensed under the Apache License, Version 2.0 (the "License");
6** you may not use this file except in compliance with the License.
7** You may obtain a copy of the License at
8**
9** http://www.apache.org/licenses/LICENSE-2.0
10**
11** Unless required by applicable law or agreed to in writing, software
12** distributed under the License is distributed on an "AS IS" BASIS,
13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14** See the License for the specific language governing permissions and
15** limitations under the License.
16*/
17
18#include "SkSVGElements.h"
19#include "SkSVGParser.h"
20
21SkSVGBase::~SkSVGBase() {
22}
23
24void SkSVGBase::addAttribute(SkSVGParser& parser, int attrIndex,
25 const char* attrValue, size_t attrLength) {
26 SkString* first = (SkString*) ((char*) this + sizeof(SkSVGElement));
27 first += attrIndex;
28 first->set(attrValue, attrLength);
29}
30
31
32SkSVGElement::SkSVGElement() : fParent(NULL), fIsDef(false), fIsNotDef(true) {
33}
34
35SkSVGElement::~SkSVGElement() {
36}
37
38SkSVGElement* SkSVGElement::getGradient() {
39 return NULL;
40}
41
42bool SkSVGElement::isGroupParent() {
43 SkSVGElement* parent = fParent;
44 while (parent) {
45 if (parent->getType() != SkSVGType_G)
46 return false;
47 parent = parent->fParent;
48 }
49 return true;
50}
51
52bool SkSVGElement::isDef() {
53 return isGroupParent() == false ? fParent->isDef() : fIsDef;
54}
55
56bool SkSVGElement::isFlushable() {
57 return true;
58}
59
60bool SkSVGElement::isGroup() {
61 return false;
62}
63
64bool SkSVGElement::isNotDef() {
65 return isGroupParent() == false ? fParent->isNotDef() : fIsNotDef;
66}
67
68bool SkSVGElement::onEndElement(SkSVGParser& parser) {
69 if (f_id.size() > 0)
70 parser.getIDs().set(f_id.c_str(), f_id.size(), this);
71 return false;
72}
73
74bool SkSVGElement::onStartElement(SkSVGElement* child) {
75 *fChildren.append() = child;
76 return false;
77}
78
79void SkSVGElement::translate(SkSVGParser& parser, bool) {
80 if (f_id.size() > 0)
81 SVG_ADD_ATTRIBUTE(id);
82}
83
84void SkSVGElement::setIsDef() {
85 fIsDef = isDef();
86}
87
88//void SkSVGElement::setIsNotDef() {
89// fIsNotDef = isNotDef();
90//}
91
92void SkSVGElement::write(SkSVGParser& , SkString& ) {
93 SkASSERT(0);
94}
95
96