OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2007 Eric Seidel <eric@webkit.org> | 2 * Copyright (C) 2007 Eric Seidel <eric@webkit.org> |
3 * Copyright (C) 2007 Nikolas Zimmermann <zimmermann@kde.org> | 3 * Copyright (C) 2007 Nikolas Zimmermann <zimmermann@kde.org> |
4 * Copyright (C) Research In Motion Limited 2010. All rights reserved. | 4 * Copyright (C) Research In Motion Limited 2010. All rights reserved. |
5 * | 5 * |
6 * This library is free software; you can redistribute it and/or | 6 * This library is free software; you can redistribute it and/or |
7 * modify it under the terms of the GNU Library General Public | 7 * modify it under the terms of the GNU Library General Public |
8 * License as published by the Free Software Foundation; either | 8 * License as published by the Free Software Foundation; either |
9 * version 2 of the License, or (at your option) any later version. | 9 * version 2 of the License, or (at your option) any later version. |
10 * | 10 * |
11 * This library is distributed in the hope that it will be useful, | 11 * This library is distributed in the hope that it will be useful, |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 * Library General Public License for more details. | 14 * Library General Public License for more details. |
15 * | 15 * |
16 * You should have received a copy of the GNU Library General Public License | 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 | 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, | 18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
19 * Boston, MA 02110-1301, USA. | 19 * Boston, MA 02110-1301, USA. |
20 */ | 20 */ |
21 | 21 |
22 #include "config.h" | 22 #include "config.h" |
23 | 23 |
24 #if ENABLE(SVG_FONTS) | 24 #if ENABLE(SVG_FONTS) |
25 #include "core/svg/SVGFontElement.h" | 25 #include "core/svg/SVGFontElement.h" |
26 | 26 |
| 27 #include "core/dom/ElementTraversal.h" |
27 #include "core/frame/UseCounter.h" | 28 #include "core/frame/UseCounter.h" |
28 #include "core/svg/SVGGlyphElement.h" | 29 #include "core/svg/SVGGlyphElement.h" |
29 #include "core/svg/SVGHKernElement.h" | 30 #include "core/svg/SVGHKernElement.h" |
30 #include "core/svg/SVGMissingGlyphElement.h" | 31 #include "core/svg/SVGMissingGlyphElement.h" |
31 #include "core/svg/SVGVKernElement.h" | 32 #include "core/svg/SVGVKernElement.h" |
32 #include "wtf/ASCIICType.h" | 33 #include "wtf/ASCIICType.h" |
33 | 34 |
34 namespace WebCore { | 35 namespace WebCore { |
35 | 36 |
36 inline SVGFontElement::SVGFontElement(Document& document) | 37 inline SVGFontElement::SVGFontElement(Document& document) |
(...skipping 16 matching lines...) Expand all Loading... |
53 if (m_isGlyphCacheValid) { | 54 if (m_isGlyphCacheValid) { |
54 m_glyphMap.clear(); | 55 m_glyphMap.clear(); |
55 m_horizontalKerningTable.clear(); | 56 m_horizontalKerningTable.clear(); |
56 m_verticalKerningTable.clear(); | 57 m_verticalKerningTable.clear(); |
57 } | 58 } |
58 m_isGlyphCacheValid = false; | 59 m_isGlyphCacheValid = false; |
59 } | 60 } |
60 | 61 |
61 SVGMissingGlyphElement* SVGFontElement::firstMissingGlyphElement() const | 62 SVGMissingGlyphElement* SVGFontElement::firstMissingGlyphElement() const |
62 { | 63 { |
63 for (Node* child = firstChild(); child; child = child->nextSibling()) { | 64 return Traversal<SVGMissingGlyphElement>::firstChild(*this); |
64 if (child->hasTagName(SVGNames::missing_glyphTag)) | |
65 return toSVGMissingGlyphElement(child); | |
66 } | |
67 | |
68 return 0; | |
69 } | 65 } |
70 | 66 |
71 void SVGFontElement::registerLigaturesInGlyphCache(Vector<String>& ligatures) | 67 void SVGFontElement::registerLigaturesInGlyphCache(Vector<String>& ligatures) |
72 { | 68 { |
73 ASSERT(!ligatures.isEmpty()); | 69 ASSERT(!ligatures.isEmpty()); |
74 | 70 |
75 // Register each character of a ligature in the map, if not present. | 71 // Register each character of a ligature in the map, if not present. |
76 // Eg. If only a "fi" ligature is present, but not "f" and "i", the | 72 // Eg. If only a "fi" ligature is present, but not "f" and "i", the |
77 // GlyphPage will not contain any entries for "f" and "i", so the | 73 // GlyphPage will not contain any entries for "f" and "i", so the |
78 // SVGFont is not used to render the text "fi1234". Register an | 74 // SVGFont is not used to render the text "fi1234". Register an |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 void SVGFontElement::ensureGlyphCache() | 158 void SVGFontElement::ensureGlyphCache() |
163 { | 159 { |
164 if (m_isGlyphCacheValid) | 160 if (m_isGlyphCacheValid) |
165 return; | 161 return; |
166 | 162 |
167 KerningPairVector horizontalKerningPairs; | 163 KerningPairVector horizontalKerningPairs; |
168 KerningPairVector verticalKerningPairs; | 164 KerningPairVector verticalKerningPairs; |
169 | 165 |
170 SVGMissingGlyphElement* firstMissingGlyphElement = 0; | 166 SVGMissingGlyphElement* firstMissingGlyphElement = 0; |
171 Vector<String> ligatures; | 167 Vector<String> ligatures; |
172 for (Node* child = firstChild(); child; child = child->nextSibling()) { | 168 for (SVGElement* element = Traversal<SVGElement>::firstChild(*this); element
; element = Traversal<SVGElement>::nextSibling(*element)) { |
173 if (child->hasTagName(SVGNames::glyphTag)) { | 169 if (isSVGGlyphElement(*element)) { |
174 SVGGlyphElement* glyph = toSVGGlyphElement(child); | 170 SVGGlyphElement& glyph = toSVGGlyphElement(*element); |
175 AtomicString unicode = glyph->fastGetAttribute(SVGNames::unicodeAttr
); | 171 AtomicString unicode = glyph.fastGetAttribute(SVGNames::unicodeAttr)
; |
176 AtomicString glyphId = glyph->getIdAttribute(); | 172 AtomicString glyphId = glyph.getIdAttribute(); |
177 if (glyphId.isEmpty() && unicode.isEmpty()) | 173 if (glyphId.isEmpty() && unicode.isEmpty()) |
178 continue; | 174 continue; |
179 | 175 |
180 m_glyphMap.addGlyph(glyphId, unicode, glyph->buildGlyphIdentifier())
; | 176 m_glyphMap.addGlyph(glyphId, unicode, glyph.buildGlyphIdentifier()); |
181 | 177 |
182 // Register ligatures, if needed, don't mix up with surrogate pairs
though! | 178 // Register ligatures, if needed, don't mix up with surrogate pairs
though! |
183 if (unicode.length() > 1 && !U16_IS_SURROGATE(unicode[0])) | 179 if (unicode.length() > 1 && !U16_IS_SURROGATE(unicode[0])) |
184 ligatures.append(unicode.string()); | 180 ligatures.append(unicode.string()); |
185 } else if (child->hasTagName(SVGNames::hkernTag)) { | 181 } else if (isSVGHKernElement(*element)) { |
186 toSVGHKernElement(child)->buildHorizontalKerningPair(horizontalKerni
ngPairs); | 182 toSVGHKernElement(*element).buildHorizontalKerningPair(horizontalKer
ningPairs); |
187 } else if (child->hasTagName(SVGNames::vkernTag)) { | 183 } else if (isSVGVKernElement(*element)) { |
188 toSVGVKernElement(child)->buildVerticalKerningPair(verticalKerningPa
irs); | 184 toSVGVKernElement(*element).buildVerticalKerningPair(verticalKerning
Pairs); |
189 } else if (child->hasTagName(SVGNames::missing_glyphTag) && !firstMissin
gGlyphElement) { | 185 } else if (isSVGMissingGlyphElement(*element) && !firstMissingGlyphEleme
nt) { |
190 firstMissingGlyphElement = toSVGMissingGlyphElement(child); | 186 firstMissingGlyphElement = toSVGMissingGlyphElement(element); |
191 } | 187 } |
192 } | 188 } |
193 | 189 |
194 // Build the kerning tables. | 190 // Build the kerning tables. |
195 buildKerningTable(horizontalKerningPairs, m_horizontalKerningTable); | 191 buildKerningTable(horizontalKerningPairs, m_horizontalKerningTable); |
196 buildKerningTable(verticalKerningPairs, m_verticalKerningTable); | 192 buildKerningTable(verticalKerningPairs, m_verticalKerningTable); |
197 | 193 |
198 // The glyph-name->glyph-id map won't be needed/used after having built the
kerning table(s). | 194 // The glyph-name->glyph-id map won't be needed/used after having built the
kerning table(s). |
199 m_glyphMap.dropNamedGlyphMap(); | 195 m_glyphMap.dropNamedGlyphMap(); |
200 | 196 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 | 255 |
260 Glyph SVGFontElement::missingGlyph() | 256 Glyph SVGFontElement::missingGlyph() |
261 { | 257 { |
262 ensureGlyphCache(); | 258 ensureGlyphCache(); |
263 return m_missingGlyph; | 259 return m_missingGlyph; |
264 } | 260 } |
265 | 261 |
266 } | 262 } |
267 | 263 |
268 #endif // ENABLE(SVG_FONTS) | 264 #endif // ENABLE(SVG_FONTS) |
OLD | NEW |