1 | /* |
2 | * Copyright (C) 2011 Leo Yang <leoyang@webkit.org> |
3 | * Copyright (C) 2018 Apple Inc. All rights reserved. |
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 | |
23 | #if ENABLE(SVG_FONTS) |
24 | #include "SVGGlyphRefElement.h" |
25 | |
26 | #include "SVGGlyphElement.h" |
27 | #include "SVGNames.h" |
28 | #include "SVGParserUtilities.h" |
29 | #include "XLinkNames.h" |
30 | #include <wtf/IsoMallocInlines.h> |
31 | #include <wtf/text/AtomicString.h> |
32 | |
33 | namespace WebCore { |
34 | |
35 | WTF_MAKE_ISO_ALLOCATED_IMPL(SVGGlyphRefElement); |
36 | |
37 | inline SVGGlyphRefElement::SVGGlyphRefElement(const QualifiedName& tagName, Document& document) |
38 | : SVGElement(tagName, document) |
39 | , SVGURIReference(this) |
40 | { |
41 | ASSERT(hasTagName(SVGNames::glyphRefTag)); |
42 | } |
43 | |
44 | Ref<SVGGlyphRefElement> SVGGlyphRefElement::create(const QualifiedName& tagName, Document& document) |
45 | { |
46 | return adoptRef(*new SVGGlyphRefElement(tagName, document)); |
47 | } |
48 | |
49 | bool SVGGlyphRefElement::hasValidGlyphElement(String& glyphName) const |
50 | { |
51 | // FIXME: We only support xlink:href so far. |
52 | // https://bugs.webkit.org/show_bug.cgi?id=64787 |
53 | // No need to support glyphRef referencing another node inside a shadow tree. |
54 | auto target = targetElementFromIRIString(getAttribute(SVGNames::hrefAttr, XLinkNames::hrefAttr), document()); |
55 | glyphName = target.identifier; |
56 | return is<SVGGlyphElement>(target.element); |
57 | } |
58 | |
59 | static float parseFloat(const AtomicString& value) |
60 | { |
61 | float result; |
62 | if (!parseNumberFromString(value, result)) |
63 | return 0; |
64 | return result; |
65 | } |
66 | |
67 | void SVGGlyphRefElement::parseAttribute(const QualifiedName& name, const AtomicString& value) |
68 | { |
69 | // FIXME: Is the error handling in parseFloat correct for these attributes? |
70 | if (name == SVGNames::xAttr) |
71 | m_x = parseFloat(value); |
72 | else if (name == SVGNames::yAttr) |
73 | m_y = parseFloat(value); |
74 | else if (name == SVGNames::dxAttr) |
75 | m_dx = parseFloat(value); |
76 | else if (name == SVGNames::dyAttr) |
77 | m_dy = parseFloat(value); |
78 | else { |
79 | SVGURIReference::parseAttribute(name, value); |
80 | SVGElement::parseAttribute(name, value); |
81 | } |
82 | } |
83 | |
84 | void SVGGlyphRefElement::setX(float x) |
85 | { |
86 | setAttribute(SVGNames::xAttr, AtomicString::number(x)); |
87 | } |
88 | |
89 | void SVGGlyphRefElement::setY(float y) |
90 | { |
91 | setAttribute(SVGNames::yAttr, AtomicString::number(y)); |
92 | } |
93 | |
94 | void SVGGlyphRefElement::setDx(float dx) |
95 | { |
96 | setAttribute(SVGNames::dxAttr, AtomicString::number(dx)); |
97 | } |
98 | |
99 | void SVGGlyphRefElement::setDy(float dy) |
100 | { |
101 | setAttribute(SVGNames::dyAttr, AtomicString::number(dy)); |
102 | } |
103 | |
104 | } |
105 | |
106 | #endif |
107 | |