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#include "SkSVGElements.h"
1180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkSVGParser.h"
1280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
1380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruSkSVGBase::~SkSVGBase() {
1480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}
1580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
1680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruvoid SkSVGBase::addAttribute(SkSVGParser& parser, int attrIndex,
1780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        const char* attrValue, size_t attrLength) {
1880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkString* first = (SkString*) ((char*) this + sizeof(SkSVGElement));
1980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    first += attrIndex;
2080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    first->set(attrValue, attrLength);
2180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}
2280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
2380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
2480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruSkSVGElement::SkSVGElement() : fParent(NULL), fIsDef(false), fIsNotDef(true) {
2580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}
2680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
2780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruSkSVGElement::~SkSVGElement() {
2880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}
2980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
3080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruSkSVGElement* SkSVGElement::getGradient() {
3180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    return NULL;
3280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}
3380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
3480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querubool SkSVGElement::isGroupParent() {
3580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkSVGElement* parent = fParent;
3680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    while (parent) {
3780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        if (parent->getType() != SkSVGType_G)
3880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            return false;
3980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        parent = parent->fParent;
4080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
4180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    return true;
4280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}
4380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
4480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querubool SkSVGElement::isDef() {
4580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    return isGroupParent() == false ? fParent->isDef() : fIsDef;
4680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}
4780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
4880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querubool SkSVGElement::isFlushable() {
4980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    return true;
5080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}
5180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
5280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querubool SkSVGElement::isGroup() {
5380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    return false;
5480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}
5580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
5680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querubool SkSVGElement::isNotDef() {
5780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    return isGroupParent() == false ? fParent->isNotDef() : fIsNotDef;
5880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}
5980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
6080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querubool SkSVGElement::onEndElement(SkSVGParser& parser) {
6180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    if (f_id.size() > 0)
6280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        parser.getIDs().set(f_id.c_str(), f_id.size(), this);
6380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    return false;
6480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}
6580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
6680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querubool SkSVGElement::onStartElement(SkSVGElement* child) {
6780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    *fChildren.append() = child;
6880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    return false;
6980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}
7080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
7180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruvoid SkSVGElement::translate(SkSVGParser& parser, bool) {
7280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    if (f_id.size() > 0)
7380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        SVG_ADD_ATTRIBUTE(id);
7480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}
7580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
7680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruvoid SkSVGElement::setIsDef() {
7780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    fIsDef = isDef();
7880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}
7980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
8080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru//void SkSVGElement::setIsNotDef() {
8180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru//  fIsNotDef = isNotDef();
8280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru//}
8380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
8480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruvoid SkSVGElement::write(SkSVGParser& , SkString& ) {
8580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkASSERT(0);
8680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}
87