KHTML
SVGGlyphElement.cpp
Go to the documentation of this file.
00001 /* 00002 Copyright (C) 2007 Eric Seidel <eric@webkit.org> 00003 Copyright (C) 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org> 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Library General Public 00007 License as published by the Free Software Foundation; either 00008 version 2 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Library General Public License for more details. 00014 00015 You should have received a copy of the GNU Library General Public License 00016 along with this library; see the file COPYING.LIB. If not, write to 00017 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00018 Boston, MA 02110-1301, USA. 00019 */ 00020 00021 #include "config.h" 00022 #include "wtf/Platform.h" 00023 00024 #if ENABLE(SVG_FONTS) 00025 #include "SVGGlyphElement.h" 00026 00027 #include "SVGFontElement.h" 00028 //FIXME khtml #include "SVGFontFaceElement.h" 00029 #include "SVGFontData.h" 00030 #include "SVGNames.h" 00031 #include "SVGParserUtilities.h" 00032 //FIXME khtml #include "SimpleFontData.h" 00033 00034 namespace WebCore { 00035 00036 using namespace SVGNames; 00037 00038 SVGGlyphElement::SVGGlyphElement(const QualifiedName& tagName, Document* doc) 00039 : SVGStyledElement(tagName, doc) 00040 { 00041 } 00042 00043 SVGGlyphElement::~SVGGlyphElement() 00044 { 00045 } 00046 00047 void SVGGlyphElement::insertedIntoDocument() 00048 { 00049 Node* fontNode = parentNode(); 00050 if (fontNode && fontNode->hasTagName(fontTag)) { 00051 if (SVGFontElement* element = static_cast<SVGFontElement*>(fontNode)) 00052 element->invalidateGlyphCache(); 00053 } 00054 SVGStyledElement::insertedIntoDocument(); 00055 } 00056 00057 void SVGGlyphElement::removedFromDocument() 00058 { 00059 Node* fontNode = parentNode(); 00060 if (fontNode && fontNode->hasTagName(fontTag)) { 00061 if (SVGFontElement* element = static_cast<SVGFontElement*>(fontNode)) 00062 element->invalidateGlyphCache(); 00063 } 00064 SVGStyledElement::removedFromDocument(); 00065 } 00066 00067 static inline SVGGlyphIdentifier::ArabicForm parseArabicForm(const AtomicString& value) 00068 { 00069 if (value == "medial") 00070 return SVGGlyphIdentifier::Medial; 00071 else if (value == "terminal") 00072 return SVGGlyphIdentifier::Terminal; 00073 else if (value == "isolated") 00074 return SVGGlyphIdentifier::Isolated; 00075 else if (value == "initial") 00076 return SVGGlyphIdentifier::Initial; 00077 00078 return SVGGlyphIdentifier::None; 00079 } 00080 00081 static inline SVGGlyphIdentifier::Orientation parseOrientation(const AtomicString& value) 00082 { 00083 if (value == "h") 00084 return SVGGlyphIdentifier::Horizontal; 00085 else if (value == "v") 00086 return SVGGlyphIdentifier::Vertical; 00087 00088 return SVGGlyphIdentifier::Both; 00089 } 00090 00091 static inline Path parsePathData(const AtomicString& value) 00092 { 00093 Path result; 00094 pathFromSVGData(result, value); 00095 00096 return result; 00097 } 00098 00099 void SVGGlyphElement::inheritUnspecifiedAttributes(SVGGlyphIdentifier& identifier, const SVGFontData* svgFontData) 00100 { 00101 if (identifier.horizontalAdvanceX == SVGGlyphIdentifier::inheritedValue()) 00102 identifier.horizontalAdvanceX = svgFontData->horizontalAdvanceX(); 00103 00104 if (identifier.verticalOriginX == SVGGlyphIdentifier::inheritedValue()) 00105 identifier.verticalOriginX = svgFontData->verticalOriginX(); 00106 00107 if (identifier.verticalOriginY == SVGGlyphIdentifier::inheritedValue()) 00108 identifier.verticalOriginY = svgFontData->verticalOriginY(); 00109 00110 if (identifier.verticalAdvanceY == SVGGlyphIdentifier::inheritedValue()) 00111 identifier.verticalAdvanceY = svgFontData->verticalAdvanceY(); 00112 } 00113 00114 static inline float parseSVGGlyphAttribute(const SVGElement* element, const WebCore::QualifiedName& name) 00115 { 00116 AtomicString value(element->getAttribute(name)); 00117 if (value.isEmpty()) 00118 return SVGGlyphIdentifier::inheritedValue(); 00119 00120 return value.string().string().toFloat(); 00121 } 00122 00123 SVGGlyphIdentifier SVGGlyphElement::buildGenericGlyphIdentifier(const SVGElement* element) 00124 { 00125 SVGGlyphIdentifier identifier; 00126 identifier.pathData = parsePathData(element->getAttribute(dAttr)); 00127 00128 // Spec: The horizontal advance after rendering the glyph in horizontal orientation. 00129 // If the attribute is not specified, the effect is as if the attribute were set to the 00130 // value of the font's horiz-adv-x attribute. Glyph widths are required to be non-negative, 00131 // even if the glyph is typically rendered right-to-left, as in Hebrew and Arabic scripts. 00132 identifier.horizontalAdvanceX = parseSVGGlyphAttribute(element, horiz_adv_xAttr); 00133 00134 // Spec: The X-coordinate in the font coordinate system of the origin of the glyph to be 00135 // used when drawing vertically oriented text. If the attribute is not specified, the effect 00136 // is as if the attribute were set to the value of the font's vert-origin-x attribute. 00137 identifier.verticalOriginX = parseSVGGlyphAttribute(element, vert_origin_xAttr); 00138 00139 // Spec: The Y-coordinate in the font coordinate system of the origin of a glyph to be 00140 // used when drawing vertically oriented text. If the attribute is not specified, the effect 00141 // is as if the attribute were set to the value of the font's vert-origin-y attribute. 00142 identifier.verticalOriginY = parseSVGGlyphAttribute(element, vert_origin_yAttr); 00143 00144 // Spec: The vertical advance after rendering a glyph in vertical orientation. 00145 // If the attribute is not specified, the effect is as if the attribute were set to the 00146 // value of the font's vert-adv-y attribute. 00147 identifier.verticalAdvanceY = parseSVGGlyphAttribute(element, vert_adv_yAttr); 00148 00149 return identifier; 00150 } 00151 00152 SVGGlyphIdentifier SVGGlyphElement::buildGlyphIdentifier() const 00153 { 00154 SVGGlyphIdentifier identifier(buildGenericGlyphIdentifier(this)); 00155 identifier.glyphName = getAttribute(glyph_nameAttr); 00156 identifier.orientation = parseOrientation(getAttribute(orientationAttr)); 00157 identifier.arabicForm = parseArabicForm(getAttribute(arabic_formAttr)); 00158 00159 String language = getAttribute(langAttr); 00160 if (!language.isEmpty()) 00161 identifier.languages = parseDelimitedString(language, ','); 00162 00163 return identifier; 00164 } 00165 00166 } 00167 00168 #endif // ENABLE(SVG_FONTS)
KDE 4.6 API Reference