• Skip to content
  • Skip to link menu
KDE 4.3 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

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 //FIXME khtml #include "XMLNames.h"
00034 
00035 namespace WebCore {
00036 
00037 using namespace SVGNames;
00038 
00039 SVGGlyphElement::SVGGlyphElement(const QualifiedName& tagName, Document* doc)
00040     : SVGStyledElement(tagName, doc)
00041 {
00042 }
00043 
00044 SVGGlyphElement::~SVGGlyphElement()
00045 {
00046 }
00047 
00048 void SVGGlyphElement::insertedIntoDocument()
00049 {
00050     Node* fontNode = parentNode();
00051     if (fontNode && fontNode->hasTagName(fontTag)) {
00052         if (SVGFontElement* element = static_cast<SVGFontElement*>(fontNode))
00053             element->invalidateGlyphCache();
00054     }
00055     SVGStyledElement::insertedIntoDocument();
00056 }
00057 
00058 void SVGGlyphElement::removedFromDocument()
00059 {
00060     Node* fontNode = parentNode();
00061     if (fontNode && fontNode->hasTagName(fontTag)) {
00062         if (SVGFontElement* element = static_cast<SVGFontElement*>(fontNode))
00063             element->invalidateGlyphCache();
00064     }
00065     SVGStyledElement::removedFromDocument();
00066 }
00067 
00068 static inline SVGGlyphIdentifier::ArabicForm parseArabicForm(const AtomicString& value)
00069 {
00070     if (value == "medial")
00071         return SVGGlyphIdentifier::Medial;
00072     else if (value == "terminal")
00073         return SVGGlyphIdentifier::Terminal;
00074     else if (value == "isolated")
00075         return SVGGlyphIdentifier::Isolated;
00076     else if (value == "initial")
00077         return SVGGlyphIdentifier::Initial;
00078 
00079     return SVGGlyphIdentifier::None;
00080 }
00081 
00082 static inline SVGGlyphIdentifier::Orientation parseOrientation(const AtomicString& value)
00083 {
00084     if (value == "h")
00085         return SVGGlyphIdentifier::Horizontal;
00086     else if (value == "v")
00087         return SVGGlyphIdentifier::Vertical;
00088 
00089     return SVGGlyphIdentifier::Both;
00090 }
00091 
00092 static inline Path parsePathData(const AtomicString& value)
00093 {
00094     Path result;
00095     pathFromSVGData(result, value);
00096 
00097     return result;
00098 }
00099 
00100 void SVGGlyphElement::inheritUnspecifiedAttributes(SVGGlyphIdentifier& identifier, const SVGFontData* svgFontData)
00101 {
00102     if (identifier.horizontalAdvanceX == SVGGlyphIdentifier::inheritedValue())
00103         identifier.horizontalAdvanceX = svgFontData->horizontalAdvanceX();
00104 
00105     if (identifier.verticalOriginX == SVGGlyphIdentifier::inheritedValue())
00106         identifier.verticalOriginX = svgFontData->verticalOriginX();
00107 
00108     if (identifier.verticalOriginY == SVGGlyphIdentifier::inheritedValue())
00109         identifier.verticalOriginY = svgFontData->verticalOriginY();
00110 
00111     if (identifier.verticalAdvanceY == SVGGlyphIdentifier::inheritedValue())
00112         identifier.verticalAdvanceY = svgFontData->verticalAdvanceY();
00113 }
00114 
00115 static inline float parseSVGGlyphAttribute(const SVGElement* element, const WebCore::QualifiedName& name)
00116 {
00117     AtomicString value(element->getAttribute(name));
00118     if (value.isEmpty())
00119         return SVGGlyphIdentifier::inheritedValue();
00120 
00121     return value.string().string().toFloat();
00122 }
00123 
00124 SVGGlyphIdentifier SVGGlyphElement::buildGenericGlyphIdentifier(const SVGElement* element)
00125 {
00126     SVGGlyphIdentifier identifier;
00127     identifier.pathData = parsePathData(element->getAttribute(dAttr));
00128  
00129     // Spec: The horizontal advance after rendering the glyph in horizontal orientation.
00130     // If the attribute is not specified, the effect is as if the attribute were set to the
00131     // value of the font's horiz-adv-x attribute. Glyph widths are required to be non-negative,
00132     // even if the glyph is typically rendered right-to-left, as in Hebrew and Arabic scripts.
00133     identifier.horizontalAdvanceX = parseSVGGlyphAttribute(element, horiz_adv_xAttr);
00134 
00135     // Spec: The X-coordinate in the font coordinate system of the origin of the glyph to be
00136     // used when drawing vertically oriented text. If the attribute is not specified, the effect
00137     // is as if the attribute were set to the value of the font's vert-origin-x attribute.
00138     identifier.verticalOriginX = parseSVGGlyphAttribute(element, vert_origin_xAttr);
00139 
00140     // Spec: The Y-coordinate in the font coordinate system of the origin of a glyph to be
00141     // used when drawing vertically oriented text. If the attribute is not specified, the effect
00142     // is as if the attribute were set to the value of the font's vert-origin-y attribute.
00143     identifier.verticalOriginY = parseSVGGlyphAttribute(element, vert_origin_yAttr);
00144 
00145     // Spec: The vertical advance after rendering a glyph in vertical orientation.
00146     // If the attribute is not specified, the effect is as if the attribute were set to the
00147     // value of the font's vert-adv-y attribute.
00148     identifier.verticalAdvanceY = parseSVGGlyphAttribute(element, vert_adv_yAttr);
00149 
00150     return identifier;
00151 }
00152 
00153 SVGGlyphIdentifier SVGGlyphElement::buildGlyphIdentifier() const
00154 {
00155     SVGGlyphIdentifier identifier(buildGenericGlyphIdentifier(this));
00156     identifier.glyphName = getAttribute(glyph_nameAttr);
00157     identifier.orientation = parseOrientation(getAttribute(orientationAttr));
00158     identifier.arabicForm = parseArabicForm(getAttribute(arabic_formAttr));
00159 
00160     String language = getAttribute(langAttr);
00161     if (!language.isEmpty())
00162         identifier.languages = parseDelimitedString(language, ',');
00163 
00164     return identifier;
00165 }
00166 
00167 }
00168 
00169 #endif // ENABLE(SVG_FONTS)

KHTML

Skip menu "KHTML"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.6.1
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal