Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(88)

Side by Side Diff: Source/core/svg/SVGAltGlyphDefElement.cpp

Issue 656913006: Remove SVG fonts (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Update tests for landing Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2011 Leo Yang <leoyang@webkit.org>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20 #include "config.h"
21
22 #if ENABLE(SVG_FONTS)
23 #include "core/svg/SVGAltGlyphDefElement.h"
24
25 #include "core/SVGNames.h"
26 #include "core/dom/ElementTraversal.h"
27 #include "core/svg/SVGAltGlyphItemElement.h"
28 #include "core/svg/SVGGlyphRefElement.h"
29
30 namespace blink {
31
32 inline SVGAltGlyphDefElement::SVGAltGlyphDefElement(Document& document)
33 : SVGElement(SVGNames::altGlyphDefTag, document)
34 {
35 }
36
37 DEFINE_NODE_FACTORY(SVGAltGlyphDefElement)
38
39 bool SVGAltGlyphDefElement::hasValidGlyphElements(Vector<AtomicString>& glyphNam es) const
40 {
41 // Spec: http://www.w3.org/TR/SVG/text.html#AltGlyphDefElement
42 // An 'altGlyphDef' can contain either of the following:
43 //
44 // 1. In the simplest case, an 'altGlyphDef' contains one or more 'glyphRef' elements.
45 // Each 'glyphRef' element references a single glyph within a particular fon t.
46 // If all of the referenced glyphs are available, then these glyphs are rend ered
47 // instead of the character(s) inside of the referencing 'altGlyph' element.
48 // If any of the referenced glyphs are unavailable, then the character(s) th at are
49 // inside of the 'altGlyph' element are rendered as if there were not an 'al tGlyph'
50 // element surrounding those characters.
51 //
52 // 2. In the more complex case, an 'altGlyphDef' contains one or more 'altGl yphItem' elements.
53 // Each 'altGlyphItem' represents a candidate set of substitute glyphs. Each 'altGlyphItem'
54 // contains one or more 'glyphRef' elements. Each 'glyphRef' element referen ces a single
55 // glyph within a particular font. The first 'altGlyphItem' in which all ref erenced glyphs
56 // are available is chosen. The glyphs referenced from this 'altGlyphItem' a re rendered
57 // instead of the character(s) that are inside of the referencing 'altGlyph' element.
58 // If none of the 'altGlyphItem' elements result in a successful match (i.e. , none of the
59 // 'altGlyphItem' elements has all of its referenced glyphs available), then the character(s)
60 // that are inside of the 'altGlyph' element are rendered as if there were n ot an 'altGlyph'
61 // element surrounding those characters.
62 //
63 // The spec doesn't tell how to deal with the mixing of <glyphRef> and <altG lyItem>.
64 // However, we determine content model by the the type of the first appearin g element
65 // just like Opera 11 does. After the content model is determined we skip el ements
66 // which don't comform to it. For example:
67 // a. <altGlyphDef>
68 // <glyphRef id="g1" />
69 // <altGlyphItem id="i1"> ... </altGlyphItem>
70 // <glyphRef id="g2" />
71 // </altGlyphDef>
72 //
73 // b. <altGlyphDef>
74 // <altGlyphItem id="i1"> ... </altGlyphItem>
75 // <altGlyphItem id="i2"> ... </altGlyphItem>
76 // <glyphRef id="g1" />
77 // <glyphRef id="g2" />
78 // </altGlyphDef>
79 // For a), the content model is 1), so we will use "g1" and "g2" if they are all valid
80 // and "i1" is skipped.
81 // For b), the content model is 2), so we will use <glyphRef> elements conta ined in
82 // "i1" if they are valid and "g1" and "g2" are skipped.
83
84 // These 2 variables are used to determine content model.
85 bool fountFirstGlyphRef = false;
86 bool foundFirstAltGlyphItem = false;
87
88 for (SVGElement* child = Traversal<SVGElement>::firstChild(*this); child; ch ild = Traversal<SVGElement>::nextSibling(*child)) {
89 if (!foundFirstAltGlyphItem && isSVGGlyphRefElement(*child)) {
90 fountFirstGlyphRef = true;
91 AtomicString referredGlyphName;
92
93 if (toSVGGlyphRefElement(child)->hasValidGlyphElement(referredGlyphN ame))
94 glyphNames.append(referredGlyphName);
95 else {
96 // As the spec says "If any of the referenced glyphs are unavail able,
97 // then the character(s) that are inside of the 'altGlyph' eleme nt are
98 // rendered as if there were not an 'altGlyph' element surroundi ng
99 // those characters.".
100 glyphNames.clear();
101 return false;
102 }
103 } else if (!fountFirstGlyphRef && isSVGAltGlyphItemElement(*child)) {
104 foundFirstAltGlyphItem = true;
105 Vector<AtomicString> referredGlyphNames;
106
107 // As the spec says "The first 'altGlyphItem' in which all reference d glyphs
108 // are available is chosen."
109 if (toSVGAltGlyphItemElement(child)->hasValidGlyphElements(glyphName s) && !glyphNames.isEmpty())
110 return true;
111 }
112 }
113 return !glyphNames.isEmpty();
114 }
115
116 }
117
118 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698