1/*
2 * Copyright (C) 2007 Eric Seidel <eric@webkit.org>
3 * Copyright (C) 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org>
4 * Copyright (C) 2008 Eric Seidel <eric@webkit.org>
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 * Library General Public License for more details.
15 *
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
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 */
21
22#include "config.h"
23
24#if ENABLE(SVG_FONTS)
25#include "SVGHKernElement.h"
26
27#include "SVGFontData.h"
28#include "SVGFontElement.h"
29#include "SVGFontFaceElement.h"
30#include "SVGNames.h"
31#include "SimpleFontData.h"
32#include "XMLNames.h"
33
34namespace WebCore {
35
36using namespace SVGNames;
37
38inline SVGHKernElement::SVGHKernElement(const QualifiedName& tagName, Document* document)
39    : SVGElement(tagName, document)
40{
41}
42
43PassRefPtr<SVGHKernElement> SVGHKernElement::create(const QualifiedName& tagName, Document* document)
44{
45    return adoptRef(new SVGHKernElement(tagName, document));
46}
47
48void SVGHKernElement::insertedIntoDocument()
49{
50    ContainerNode* fontNode = parentNode();
51    if (fontNode && fontNode->hasTagName(SVGNames::fontTag)) {
52        if (SVGFontElement* element = static_cast<SVGFontElement*>(fontNode))
53            element->invalidateGlyphCache();
54    }
55    SVGElement::insertedIntoDocument();
56}
57
58void SVGHKernElement::removedFromDocument()
59{
60    ContainerNode* fontNode = parentNode();
61    if (fontNode && fontNode->hasTagName(SVGNames::fontTag)) {
62        if (SVGFontElement* element = static_cast<SVGFontElement*>(fontNode))
63            element->invalidateGlyphCache();
64    }
65    SVGElement::removedFromDocument();
66}
67
68void SVGHKernElement::buildHorizontalKerningPair(KerningPairVector& kerningPairs)
69{
70    String u1 = getAttribute(u1Attr);
71    String g1 = getAttribute(g1Attr);
72    String u2 = getAttribute(u2Attr);
73    String g2 = getAttribute(g2Attr);
74    if ((u1.isEmpty() && g1.isEmpty()) || (u2.isEmpty() && g2.isEmpty()))
75        return;
76
77    SVGKerningPair kerningPair;
78    if (parseGlyphName(g1, kerningPair.glyphName1)
79        && parseGlyphName(g2, kerningPair.glyphName2)
80        && parseKerningUnicodeString(u1, kerningPair.unicodeRange1, kerningPair.unicodeName1)
81        && parseKerningUnicodeString(u2, kerningPair.unicodeRange2, kerningPair.unicodeName2)) {
82        kerningPair.kerning = getAttribute(kAttr).string().toFloat();
83        kerningPairs.append(kerningPair);
84    }
85}
86
87}
88
89#endif // ENABLE(SVG_FONTS)
90