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

KHTML

  • sources
  • kde-4.12
  • kdelibs
  • khtml
  • svg
SVGGlyphElement.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2007 Eric Seidel <eric@webkit.org>
3  Copyright (C) 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org>
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License as published by the Free Software Foundation; either
8  version 2 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Library General Public License for more details.
14 
15  You should have received a copy of the GNU Library General Public License
16  along with this library; see the file COPYING.LIB. If not, write to
17  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  Boston, MA 02110-1301, USA.
19 */
20 
21 #include "config.h"
22 #include "wtf/Platform.h"
23 
24 #if ENABLE(SVG_FONTS)
25 #include "SVGGlyphElement.h"
26 
27 #include "SVGFontElement.h"
28 //FIXME khtml #include "SVGFontFaceElement.h"
29 #include "SVGFontData.h"
30 #include "SVGNames.h"
31 #include "SVGParserUtilities.h"
32 //FIXME khtml #include "SimpleFontData.h"
33 
34 namespace WebCore {
35 
36 using namespace SVGNames;
37 
38 SVGGlyphElement::SVGGlyphElement(const QualifiedName& tagName, Document* doc)
39  : SVGStyledElement(tagName, doc)
40 {
41 }
42 
43 SVGGlyphElement::~SVGGlyphElement()
44 {
45 }
46 
47 void SVGGlyphElement::insertedIntoDocument()
48 {
49  Node* fontNode = parentNode();
50  if (fontNode && fontNode->hasTagName(fontTag)) {
51  if (SVGFontElement* element = static_cast<SVGFontElement*>(fontNode))
52  element->invalidateGlyphCache();
53  }
54  SVGStyledElement::insertedIntoDocument();
55 }
56 
57 void SVGGlyphElement::removedFromDocument()
58 {
59  Node* fontNode = parentNode();
60  if (fontNode && fontNode->hasTagName(fontTag)) {
61  if (SVGFontElement* element = static_cast<SVGFontElement*>(fontNode))
62  element->invalidateGlyphCache();
63  }
64  SVGStyledElement::removedFromDocument();
65 }
66 
67 static inline SVGGlyphIdentifier::ArabicForm parseArabicForm(const AtomicString& value)
68 {
69  if (value == "medial")
70  return SVGGlyphIdentifier::Medial;
71  else if (value == "terminal")
72  return SVGGlyphIdentifier::Terminal;
73  else if (value == "isolated")
74  return SVGGlyphIdentifier::Isolated;
75  else if (value == "initial")
76  return SVGGlyphIdentifier::Initial;
77 
78  return SVGGlyphIdentifier::None;
79 }
80 
81 static inline SVGGlyphIdentifier::Orientation parseOrientation(const AtomicString& value)
82 {
83  if (value == "h")
84  return SVGGlyphIdentifier::Horizontal;
85  else if (value == "v")
86  return SVGGlyphIdentifier::Vertical;
87 
88  return SVGGlyphIdentifier::Both;
89 }
90 
91 static inline Path parsePathData(const AtomicString& value)
92 {
93  Path result;
94  pathFromSVGData(result, value);
95 
96  return result;
97 }
98 
99 void SVGGlyphElement::inheritUnspecifiedAttributes(SVGGlyphIdentifier& identifier, const SVGFontData* svgFontData)
100 {
101  if (identifier.horizontalAdvanceX == SVGGlyphIdentifier::inheritedValue())
102  identifier.horizontalAdvanceX = svgFontData->horizontalAdvanceX();
103 
104  if (identifier.verticalOriginX == SVGGlyphIdentifier::inheritedValue())
105  identifier.verticalOriginX = svgFontData->verticalOriginX();
106 
107  if (identifier.verticalOriginY == SVGGlyphIdentifier::inheritedValue())
108  identifier.verticalOriginY = svgFontData->verticalOriginY();
109 
110  if (identifier.verticalAdvanceY == SVGGlyphIdentifier::inheritedValue())
111  identifier.verticalAdvanceY = svgFontData->verticalAdvanceY();
112 }
113 
114 static inline float parseSVGGlyphAttribute(const SVGElement* element, const WebCore::QualifiedName& name)
115 {
116  AtomicString value(element->getAttribute(name));
117  if (value.isEmpty())
118  return SVGGlyphIdentifier::inheritedValue();
119 
120  return value.string().string().toFloat();
121 }
122 
123 SVGGlyphIdentifier SVGGlyphElement::buildGenericGlyphIdentifier(const SVGElement* element)
124 {
125  SVGGlyphIdentifier identifier;
126  identifier.pathData = parsePathData(element->getAttribute(dAttr));
127 
128  // Spec: The horizontal advance after rendering the glyph in horizontal orientation.
129  // If the attribute is not specified, the effect is as if the attribute were set to the
130  // value of the font's horiz-adv-x attribute. Glyph widths are required to be non-negative,
131  // even if the glyph is typically rendered right-to-left, as in Hebrew and Arabic scripts.
132  identifier.horizontalAdvanceX = parseSVGGlyphAttribute(element, horiz_adv_xAttr);
133 
134  // Spec: The X-coordinate in the font coordinate system of the origin of the glyph to be
135  // used when drawing vertically oriented text. If the attribute is not specified, the effect
136  // is as if the attribute were set to the value of the font's vert-origin-x attribute.
137  identifier.verticalOriginX = parseSVGGlyphAttribute(element, vert_origin_xAttr);
138 
139  // Spec: The Y-coordinate in the font coordinate system of the origin of a glyph to be
140  // used when drawing vertically oriented text. If the attribute is not specified, the effect
141  // is as if the attribute were set to the value of the font's vert-origin-y attribute.
142  identifier.verticalOriginY = parseSVGGlyphAttribute(element, vert_origin_yAttr);
143 
144  // Spec: The vertical advance after rendering a glyph in vertical orientation.
145  // If the attribute is not specified, the effect is as if the attribute were set to the
146  // value of the font's vert-adv-y attribute.
147  identifier.verticalAdvanceY = parseSVGGlyphAttribute(element, vert_adv_yAttr);
148 
149  return identifier;
150 }
151 
152 SVGGlyphIdentifier SVGGlyphElement::buildGlyphIdentifier() const
153 {
154  SVGGlyphIdentifier identifier(buildGenericGlyphIdentifier(this));
155  identifier.glyphName = getAttribute(glyph_nameAttr);
156  identifier.orientation = parseOrientation(getAttribute(orientationAttr));
157  identifier.arabicForm = parseArabicForm(getAttribute(arabic_formAttr));
158 
159  String language = getAttribute(langAttr);
160  if (!language.isEmpty())
161  identifier.languages = parseDelimitedString(language, ',');
162 
163  return identifier;
164 }
165 
166 }
167 
168 #endif // ENABLE(SVG_FONTS)
WebCore::SVGNames::horiz_adv_xAttr
DOM::QualifiedName horiz_adv_xAttr
Definition: SVGNames.cpp:187
WebCore::SVGNames::fontTag
DOM::QualifiedName fontTag
Definition: SVGNames.cpp:63
SVGParserUtilities.h
SVGFontElement.h
WebCore::SVGNames::orientationAttr
DOM::QualifiedName orientationAttr
Definition: SVGNames.cpp:241
WebCore::SVGNames::dAttr
DOM::QualifiedName dAttr
Definition: SVGNames.cpp:137
WebCore::SVGNames::arabic_formAttr
DOM::QualifiedName arabic_formAttr
Definition: SVGNames.cpp:109
WebCore::Path
khtml::Path Path
Definition: PathTraversalState.h:37
WebCore::SVGNames::vert_origin_xAttr
DOM::QualifiedName vert_origin_xAttr
Definition: SVGNames.cpp:329
SVGFontData.h
WebCore::SVGNames::glyph_nameAttr
DOM::QualifiedName glyph_nameAttr
Definition: SVGNames.cpp:179
SVGNames.h
WebCore::SVGNames::langAttr
DOM::QualifiedName langAttr
Definition: SVGNames.cpp:206
WebCore::SVGNames::vert_adv_yAttr
DOM::QualifiedName vert_adv_yAttr
Definition: SVGNames.cpp:328
SVGGlyphElement.h
WebCore::String
DOM::DOMString String
Definition: PlatformString.h:8
WebCore::SVGNames::vert_origin_yAttr
DOM::QualifiedName vert_origin_yAttr
Definition: SVGNames.cpp:330
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:51:22 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KHTML

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

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal