1 /* 2 Copyright (C) 2007 Nikolas Zimmermann <zimmermann (at) kde.org> 3 4 This library is free software; you can redistribute it and/or 5 modify it under the terms of the GNU Library General Public 6 License as published by the Free Software Foundation; either 7 version 2 of the License, or (at your option) any later version. 8 9 This library is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 Library General Public License for more details. 13 14 You should have received a copy of the GNU Library General Public License 15 along with this library; see the file COPYING.LIB. If not, write to 16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 Boston, MA 02110-1301, USA. 18 */ 19 20 #include "config.h" 21 22 #if ENABLE(SVG) 23 #include "SVGTextPathElement.h" 24 25 #include "AffineTransform.h" 26 #include "FloatRect.h" 27 #include "MappedAttribute.h" 28 #include "RenderSVGTextPath.h" 29 #include "SVGLengthList.h" 30 #include "SVGPathElement.h" 31 #include "SVGRenderStyle.h" 32 #include "SVGTransformList.h" 33 34 namespace WebCore { 35 36 SVGTextPathElement::SVGTextPathElement(const QualifiedName& tagName, Document* doc) 37 : SVGTextContentElement(tagName, doc) 38 , SVGURIReference() 39 , m_startOffset(LengthModeOther) 40 , m_method(SVG_TEXTPATH_METHODTYPE_ALIGN) 41 , m_spacing(SVG_TEXTPATH_SPACINGTYPE_EXACT) 42 { 43 } 44 45 SVGTextPathElement::~SVGTextPathElement() 46 { 47 } 48 49 void SVGTextPathElement::parseMappedAttribute(MappedAttribute* attr) 50 { 51 const String& value = attr->value(); 52 53 if (attr->name() == SVGNames::startOffsetAttr) 54 setStartOffsetBaseValue(SVGLength(LengthModeOther, value)); 55 else if (attr->name() == SVGNames::methodAttr) { 56 if (value == "align") 57 setSpacingBaseValue(SVG_TEXTPATH_METHODTYPE_ALIGN); 58 else if (value == "stretch") 59 setSpacingBaseValue(SVG_TEXTPATH_METHODTYPE_STRETCH); 60 } else if (attr->name() == SVGNames::spacingAttr) { 61 if (value == "auto") 62 setMethodBaseValue(SVG_TEXTPATH_SPACINGTYPE_AUTO); 63 else if (value == "exact") 64 setMethodBaseValue(SVG_TEXTPATH_SPACINGTYPE_EXACT); 65 } else { 66 if (SVGURIReference::parseMappedAttribute(attr)) 67 return; 68 SVGTextContentElement::parseMappedAttribute(attr); 69 } 70 } 71 72 void SVGTextPathElement::synchronizeProperty(const QualifiedName& attrName) 73 { 74 SVGTextContentElement::synchronizeProperty(attrName); 75 76 if (attrName == anyQName()) { 77 synchronizeStartOffset(); 78 synchronizeMethod(); 79 synchronizeSpacing(); 80 synchronizeHref(); 81 return; 82 } 83 84 if (attrName == SVGNames::startOffsetAttr) 85 synchronizeStartOffset(); 86 else if (attrName == SVGNames::methodAttr) 87 synchronizeMethod(); 88 else if (attrName == SVGNames::spacingAttr) 89 synchronizeSpacing(); 90 else if (SVGURIReference::isKnownAttribute(attrName)) 91 synchronizeHref(); 92 } 93 94 RenderObject* SVGTextPathElement::createRenderer(RenderArena* arena, RenderStyle*) 95 { 96 return new (arena) RenderSVGTextPath(this); 97 } 98 99 bool SVGTextPathElement::childShouldCreateRenderer(Node* child) const 100 { 101 if (child->isTextNode() 102 #if ENABLE(SVG_FONTS) 103 || child->hasTagName(SVGNames::altGlyphTag) 104 #endif 105 || child->hasTagName(SVGNames::trefTag) || child->hasTagName(SVGNames::tspanTag) || child->hasTagName(SVGNames::textPathTag)) 106 return true; 107 108 return false; 109 } 110 111 void SVGTextPathElement::insertedIntoDocument() 112 { 113 SVGElement::insertedIntoDocument(); 114 115 String id = SVGURIReference::getTarget(href()); 116 Element* targetElement = ownerDocument()->getElementById(id); 117 if (!targetElement) { 118 document()->accessSVGExtensions()->addPendingResource(id, this); 119 return; 120 } 121 } 122 123 } 124 125 #endif // ENABLE(SVG) 126