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 "SVGFontData.h" 26#include "SVGFontElement.h" 27#include "SVGFontFaceElement.h" 28#include "SVGNames.h" 29#include "SimpleFontData.h" 30#include "XMLNames.h" 31 32namespace WebCore { 33 34using namespace SVGNames; 35 36inline SVGVKernElement::SVGVKernElement(const QualifiedName& tagName, Document* document) 37 : SVGElement(tagName, document) 38{ 39} 40 41PassRefPtr<SVGVKernElement> SVGVKernElement::create(const QualifiedName& tagName, Document* document) 42{ 43 return adoptRef(new SVGVKernElement(tagName, document)); 44} 45 46void SVGVKernElement::insertedIntoDocument() 47{ 48 ContainerNode* fontNode = parentNode(); 49 if (fontNode && fontNode->hasTagName(SVGNames::fontTag)) { 50 if (SVGFontElement* element = static_cast<SVGFontElement*>(fontNode)) 51 element->invalidateGlyphCache(); 52 } 53 SVGElement::insertedIntoDocument(); 54} 55 56void SVGVKernElement::removedFromDocument() 57{ 58 ContainerNode* fontNode = parentNode(); 59 if (fontNode && fontNode->hasTagName(SVGNames::fontTag)) { 60 if (SVGFontElement* element = static_cast<SVGFontElement*>(fontNode)) 61 element->invalidateGlyphCache(); 62 } 63 SVGElement::removedFromDocument(); 64} 65 66void SVGVKernElement::buildVerticalKerningPair(KerningPairVector& kerningPairs) 67{ 68 String u1 = getAttribute(u1Attr); 69 String g1 = getAttribute(g1Attr); 70 String u2 = getAttribute(u2Attr); 71 String g2 = getAttribute(g2Attr); 72 if ((u1.isEmpty() && g1.isEmpty()) || (u2.isEmpty() && g2.isEmpty())) 73 return; 74 75 SVGKerningPair kerningPair; 76 if (parseGlyphName(g1, kerningPair.glyphName1) 77 && parseGlyphName(g2, kerningPair.glyphName2) 78 && parseKerningUnicodeString(u1, kerningPair.unicodeRange1, kerningPair.unicodeName1) 79 && parseKerningUnicodeString(u2, kerningPair.unicodeRange2, kerningPair.unicodeName2)) { 80 kerningPair.kerning = getAttribute(kAttr).string().toFloat(); 81 kerningPairs.append(kerningPair); 82 } 83} 84 85} 86 87#endif // ENABLE(SVG_FONTS) 88