2 * Copyright (C) Research In Motion Limited 2010. All rights reserved.
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.
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.
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.
23 #include "SVGTextLayoutEngineSpacing.h"
26 #include "SVGRenderStyle.h"
29 #include "SVGFontData.h"
30 #include "SVGFontElement.h"
31 #include "SVGFontFaceElement.h"
33 #include <wtf/UnusedParam.h>
38 SVGTextLayoutEngineSpacing::SVGTextLayoutEngineSpacing(const Font& font)
44 float SVGTextLayoutEngineSpacing::calculateSVGKerning(bool isVerticalText, const SVGTextMetrics::Glyph& currentGlyph)
47 const SimpleFontData* fontData = m_font.primaryFont();
48 if (!fontData->isSVGFont()) {
49 m_lastGlyph.isValid = false;
53 ASSERT(fontData->isCustomFont());
54 ASSERT(fontData->isSVGFont());
56 const SVGFontData* svgFontData = static_cast<const SVGFontData*>(fontData->fontData());
57 SVGFontFaceElement* svgFontFace = svgFontData->svgFontFaceElement();
60 SVGFontElement* svgFont = svgFontFace->associatedFontElement();
62 m_lastGlyph.isValid = false;
67 if (m_lastGlyph.isValid) {
69 kerning = svgFont->verticalKerningForPairOfStringsAndGlyphs(m_lastGlyph.unicodeString, m_lastGlyph.name, currentGlyph.unicodeString, currentGlyph.name);
71 kerning = svgFont->horizontalKerningForPairOfStringsAndGlyphs(m_lastGlyph.unicodeString, m_lastGlyph.name, currentGlyph.unicodeString, currentGlyph.name);
74 m_lastGlyph = currentGlyph;
75 m_lastGlyph.isValid = true;
76 kerning *= m_font.size() / m_font.fontMetrics().unitsPerEm();
79 UNUSED_PARAM(isVerticalText);
80 UNUSED_PARAM(currentGlyph);
85 float SVGTextLayoutEngineSpacing::calculateCSSKerningAndSpacing(const SVGRenderStyle* style, SVGElement* lengthContext, const UChar* currentCharacter)
88 SVGLength kerningLength = style->kerning();
89 if (kerningLength.unitType() == LengthTypePercentage)
90 kerning = kerningLength.valueAsPercentage() * m_font.pixelSize();
92 kerning = kerningLength.value(lengthContext);
94 const UChar* lastCharacter = m_lastCharacter;
95 m_lastCharacter = currentCharacter;
97 if (!kerning && !m_font.letterSpacing() && !m_font.wordSpacing())
100 float spacing = m_font.letterSpacing() + kerning;
101 if (currentCharacter && lastCharacter && m_font.wordSpacing()) {
102 if (Font::treatAsSpace(*currentCharacter) && !Font::treatAsSpace(*lastCharacter))
103 spacing += m_font.wordSpacing();
111 #endif // ENABLE(SVG)