Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 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 "core/svg/SVGVKernElement.h" |
| 24 | |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 25 | #include "core/svg/SVGParserUtilities.h" |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 26 | |
| 27 | namespace WebCore { |
| 28 | |
Torne (Richard Coles) | 5d92fed | 2014-06-20 14:52:37 +0100 | [diff] [blame] | 29 | inline SVGVKernElement::SVGVKernElement(Document& document) |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 30 | : SVGElement(SVGNames::vkernTag, document) |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 31 | { |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 32 | ScriptWrappable::init(this); |
| 33 | } |
| 34 | |
Torne (Richard Coles) | 5d92fed | 2014-06-20 14:52:37 +0100 | [diff] [blame] | 35 | DEFINE_NODE_FACTORY(SVGVKernElement) |
| 36 | |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 37 | Node::InsertionNotificationRequest SVGVKernElement::insertedInto(ContainerNode* rootParent) |
| 38 | { |
| 39 | if (rootParent->inDocument()) { |
| 40 | ContainerNode* fontNode = parentNode(); |
Torne (Richard Coles) | d5428f3 | 2014-03-18 10:21:16 +0000 | [diff] [blame] | 41 | if (isSVGFontElement(fontNode)) |
| 42 | toSVGFontElement(*fontNode).invalidateGlyphCache(); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | return SVGElement::insertedInto(rootParent); |
| 46 | } |
| 47 | |
| 48 | void SVGVKernElement::removedFrom(ContainerNode* rootParent) |
| 49 | { |
| 50 | ContainerNode* fontNode = parentNode(); |
Torne (Richard Coles) | d5428f3 | 2014-03-18 10:21:16 +0000 | [diff] [blame] | 51 | if (isSVGFontElement(fontNode)) |
| 52 | toSVGFontElement(*fontNode).invalidateGlyphCache(); |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 53 | |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 54 | SVGElement::removedFrom(rootParent); |
| 55 | } |
| 56 | |
| 57 | void SVGVKernElement::buildVerticalKerningPair(KerningPairVector& kerningPairs) |
| 58 | { |
| 59 | String u1 = fastGetAttribute(SVGNames::u1Attr); |
| 60 | String g1 = fastGetAttribute(SVGNames::g1Attr); |
| 61 | String u2 = fastGetAttribute(SVGNames::u2Attr); |
| 62 | String g2 = fastGetAttribute(SVGNames::g2Attr); |
| 63 | if ((u1.isEmpty() && g1.isEmpty()) || (u2.isEmpty() && g2.isEmpty())) |
| 64 | return; |
| 65 | |
| 66 | SVGKerningPair kerningPair; |
| 67 | if (parseGlyphName(g1, kerningPair.glyphName1) |
| 68 | && parseGlyphName(g2, kerningPair.glyphName2) |
| 69 | && parseKerningUnicodeString(u1, kerningPair.unicodeRange1, kerningPair.unicodeName1) |
| 70 | && parseKerningUnicodeString(u2, kerningPair.unicodeRange2, kerningPair.unicodeName2)) { |
| 71 | kerningPair.kerning = fastGetAttribute(SVGNames::kAttr).string().toFloat(); |
| 72 | kerningPairs.append(kerningPair); |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | } |
| 77 | |
| 78 | #endif // ENABLE(SVG_FONTS) |