2 * Copyright (C) 2007 Eric Seidel <eric@webkit.org>
3 * Copyright (C) 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org>
4 * Copyright (C) 2008 Rob Buis <buis@kde.org>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
25 #include "core/svg/SVGGlyphElement.h"
27 #include "core/svg/SVGFontData.h"
28 #include "core/svg/SVGFontElement.h"
29 #include "core/svg/SVGPathUtilities.h"
33 inline SVGGlyphElement::SVGGlyphElement(Document& document)
34 : SVGElement(SVGNames::glyphTag, document)
38 DEFINE_NODE_FACTORY(SVGGlyphElement)
40 void SVGGlyphElement::invalidateGlyphCache()
42 ContainerNode* fontNode = parentNode();
43 if (isSVGFontElement(fontNode))
44 toSVGFontElement(*fontNode).invalidateGlyphCache();
47 void SVGGlyphElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
49 if (name == SVGNames::dAttr)
50 invalidateGlyphCache();
52 SVGElement::parseAttribute(name, value);
55 Node::InsertionNotificationRequest SVGGlyphElement::insertedInto(ContainerNode* rootParent)
57 invalidateGlyphCache();
58 return SVGElement::insertedInto(rootParent);
61 void SVGGlyphElement::removedFrom(ContainerNode* rootParent)
63 if (rootParent->inDocument())
64 invalidateGlyphCache();
65 SVGElement::removedFrom(rootParent);
68 static inline SVGGlyph::ArabicForm parseArabicForm(const AtomicString& value)
70 if (value == "medial")
71 return SVGGlyph::Medial;
72 if (value == "terminal")
73 return SVGGlyph::Terminal;
74 if (value == "isolated")
75 return SVGGlyph::Isolated;
76 if (value == "initial")
77 return SVGGlyph::Initial;
79 return SVGGlyph::None;
82 static inline SVGGlyph::Orientation parseOrientation(const AtomicString& value)
85 return SVGGlyph::Horizontal;
87 return SVGGlyph::Vertical;
89 return SVGGlyph::Both;
92 void SVGGlyphElement::inheritUnspecifiedAttributes(SVGGlyph& identifier, const SVGFontData* svgFontData)
94 if (identifier.horizontalAdvanceX == SVGGlyph::inheritedValue())
95 identifier.horizontalAdvanceX = svgFontData->horizontalAdvanceX();
97 if (identifier.verticalOriginX == SVGGlyph::inheritedValue())
98 identifier.verticalOriginX = svgFontData->verticalOriginX();
100 if (identifier.verticalOriginY == SVGGlyph::inheritedValue())
101 identifier.verticalOriginY = svgFontData->verticalOriginY();
103 if (identifier.verticalAdvanceY == SVGGlyph::inheritedValue())
104 identifier.verticalAdvanceY = svgFontData->verticalAdvanceY();
107 static inline float parseSVGGlyphAttribute(const SVGElement* element, const blink::QualifiedName& name)
109 AtomicString value(element->fastGetAttribute(name));
111 return SVGGlyph::inheritedValue();
113 return value.toFloat();
116 SVGGlyph SVGGlyphElement::buildGenericGlyphIdentifier(const SVGElement* element)
119 buildPathFromString(element->fastGetAttribute(SVGNames::dAttr), identifier.pathData);
121 // Spec: The horizontal advance after rendering the glyph in horizontal orientation.
122 // If the attribute is not specified, the effect is as if the attribute were set to the
123 // value of the font's horiz-adv-x attribute. Glyph widths are required to be non-negative,
124 // even if the glyph is typically rendered right-to-left, as in Hebrew and Arabic scripts.
125 identifier.horizontalAdvanceX = parseSVGGlyphAttribute(element, SVGNames::horiz_adv_xAttr);
127 // Spec: The X-coordinate in the font coordinate system of the origin of the glyph to be
128 // used when drawing vertically oriented text. If the attribute is not specified, the effect
129 // is as if the attribute were set to the value of the font's vert-origin-x attribute.
130 identifier.verticalOriginX = parseSVGGlyphAttribute(element, SVGNames::vert_origin_xAttr);
132 // Spec: The Y-coordinate in the font coordinate system of the origin of a glyph to be
133 // used when drawing vertically oriented text. If the attribute is not specified, the effect
134 // is as if the attribute were set to the value of the font's vert-origin-y attribute.
135 identifier.verticalOriginY = parseSVGGlyphAttribute(element, SVGNames::vert_origin_yAttr);
137 // Spec: The vertical advance after rendering a glyph in vertical orientation.
138 // If the attribute is not specified, the effect is as if the attribute were set to the
139 // value of the font's vert-adv-y attribute.
140 identifier.verticalAdvanceY = parseSVGGlyphAttribute(element, SVGNames::vert_adv_yAttr);
145 SVGGlyph SVGGlyphElement::buildGlyphIdentifier() const
147 SVGGlyph identifier(buildGenericGlyphIdentifier(this));
148 identifier.glyphName = fastGetAttribute(SVGNames::glyph_nameAttr);
149 identifier.orientation = parseOrientation(fastGetAttribute(SVGNames::orientationAttr));
150 identifier.arabicForm = parseArabicForm(fastGetAttribute(SVGNames::arabic_formAttr));
152 String language = fastGetAttribute(SVGNames::langAttr);
153 if (!language.isEmpty())
154 identifier.languages = parseDelimitedString(language, ',');
161 #endif // ENABLE(SVG_FONTS)