1/*
2 * Copyright (C) Research In Motion Limited 2010. All rights reserved.
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 "SVGVKernElement.h"
24
25#include "SVGFontElement.h"
26#include "SVGFontFaceElement.h"
27#include "SVGNames.h"
28#include "SVGParserUtilities.h"
29#include <wtf/IsoMallocInlines.h>
30
31namespace WebCore {
32
33WTF_MAKE_ISO_ALLOCATED_IMPL(SVGVKernElement);
34
35inline SVGVKernElement::SVGVKernElement(const QualifiedName& tagName, Document& document)
36 : SVGElement(tagName, document)
37{
38 ASSERT(hasTagName(SVGNames::vkernTag));
39}
40
41Ref<SVGVKernElement> SVGVKernElement::create(const QualifiedName& tagName, Document& document)
42{
43 return adoptRef(*new SVGVKernElement(tagName, document));
44}
45
46bool SVGVKernElement::buildVerticalKerningPair(SVGKerningPair& kerningPair) const
47{
48 auto& u1 = attributeWithoutSynchronization(SVGNames::u1Attr);
49 auto& g1 = attributeWithoutSynchronization(SVGNames::g1Attr);
50 auto& u2 = attributeWithoutSynchronization(SVGNames::u2Attr);
51 auto& g2 = attributeWithoutSynchronization(SVGNames::g2Attr);
52 if ((u1.isEmpty() && g1.isEmpty()) || (u2.isEmpty() && g2.isEmpty()))
53 return false;
54
55 if (parseGlyphName(g1, kerningPair.glyphName1)
56 && parseGlyphName(g2, kerningPair.glyphName2)
57 && parseKerningUnicodeString(u1, kerningPair.unicodeRange1, kerningPair.unicodeName1)
58 && parseKerningUnicodeString(u2, kerningPair.unicodeRange2, kerningPair.unicodeName2)) {
59 bool ok = false;
60 kerningPair.kerning = attributeWithoutSynchronization(SVGNames::kAttr).string().toFloat(&ok);
61 return ok;
62 }
63 return false;
64}
65
66}
67
68#endif // ENABLE(SVG_FONTS)
69