blob: 36d444e4c09cc4f4e970404c27e417d5d6ac0d7d [file] [log] [blame]
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +01001/*
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 "core/svg/SVGVKernElement.h"
24
25#include "SVGNames.h"
26#include "core/svg/SVGFontElement.h"
Ben Murdoche69819b2013-07-17 14:56:49 +010027#include "core/svg/SVGParserUtilities.h"
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010028
29namespace WebCore {
30
Torne (Richard Coles)51b29062013-11-28 11:56:03 +000031inline SVGVKernElement::SVGVKernElement(Document& document)
32 : SVGElement(SVGNames::vkernTag, document)
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010033{
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010034 ScriptWrappable::init(this);
35}
36
Torne (Richard Coles)51b29062013-11-28 11:56:03 +000037PassRefPtr<SVGVKernElement> SVGVKernElement::create(Document& document)
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010038{
Torne (Richard Coles)51b29062013-11-28 11:56:03 +000039 return adoptRef(new SVGVKernElement(document));
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010040}
41
42Node::InsertionNotificationRequest SVGVKernElement::insertedInto(ContainerNode* rootParent)
43{
44 if (rootParent->inDocument()) {
45 ContainerNode* fontNode = parentNode();
Ben Murdoche69819b2013-07-17 14:56:49 +010046 if (fontNode && fontNode->hasTagName(SVGNames::fontTag))
47 toSVGFontElement(fontNode)->invalidateGlyphCache();
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010048 }
49
50 return SVGElement::insertedInto(rootParent);
51}
52
53void SVGVKernElement::removedFrom(ContainerNode* rootParent)
54{
55 ContainerNode* fontNode = parentNode();
Ben Murdoche69819b2013-07-17 14:56:49 +010056 if (fontNode && fontNode->hasTagName(SVGNames::fontTag))
57 toSVGFontElement(fontNode)->invalidateGlyphCache();
58
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010059 SVGElement::removedFrom(rootParent);
60}
61
62void SVGVKernElement::buildVerticalKerningPair(KerningPairVector& kerningPairs)
63{
64 String u1 = fastGetAttribute(SVGNames::u1Attr);
65 String g1 = fastGetAttribute(SVGNames::g1Attr);
66 String u2 = fastGetAttribute(SVGNames::u2Attr);
67 String g2 = fastGetAttribute(SVGNames::g2Attr);
68 if ((u1.isEmpty() && g1.isEmpty()) || (u2.isEmpty() && g2.isEmpty()))
69 return;
70
71 SVGKerningPair kerningPair;
72 if (parseGlyphName(g1, kerningPair.glyphName1)
73 && parseGlyphName(g2, kerningPair.glyphName2)
74 && parseKerningUnicodeString(u1, kerningPair.unicodeRange1, kerningPair.unicodeName1)
75 && parseKerningUnicodeString(u2, kerningPair.unicodeRange2, kerningPair.unicodeName2)) {
76 kerningPair.kerning = fastGetAttribute(SVGNames::kAttr).string().toFloat();
77 kerningPairs.append(kerningPair);
78 }
79}
80
81}
82
83#endif // ENABLE(SVG_FONTS)