OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) Research In Motion Limited 2010. All rights reserved. | 2 * Copyright (C) Research In Motion Limited 2010. All rights reserved. |
3 * | 3 * |
4 * This library is free software; you can redistribute it and/or | 4 * This library is free software; you can redistribute it and/or |
5 * modify it under the terms of the GNU Library General Public | 5 * modify it under the terms of the GNU Library General Public |
6 * License as published by the Free Software Foundation; either | 6 * License as published by the Free Software Foundation; either |
7 * version 2 of the License, or (at your option) any later version. | 7 * version 2 of the License, or (at your option) any later version. |
8 * | 8 * |
9 * This library is distributed in the hope that it will be useful, | 9 * This library is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 * Library General Public License for more details. | 12 * Library General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU Library General Public License | 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 | 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, | 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
17 * Boston, MA 02110-1301, USA. | 17 * Boston, MA 02110-1301, USA. |
18 */ | 18 */ |
19 | 19 |
20 #include "config.h" | 20 #include "config.h" |
21 | 21 |
22 #include "core/rendering/svg/SVGTextLayoutEngineSpacing.h" | 22 #include "core/rendering/svg/SVGTextLayoutEngineSpacing.h" |
23 | 23 |
24 #include "core/svg/SVGLengthContext.h" | 24 #include "core/svg/SVGLengthContext.h" |
25 #include "platform/fonts/Character.h" | 25 #include "platform/fonts/Character.h" |
26 #include "platform/fonts/Font.h" | 26 #include "platform/fonts/Font.h" |
27 | 27 |
28 #if ENABLE(SVG_FONTS) | |
29 #include "core/svg/SVGFontData.h" | |
30 #include "core/svg/SVGFontElement.h" | |
31 #include "core/svg/SVGFontFaceElement.h" | |
32 #endif | |
33 | |
34 namespace blink { | 28 namespace blink { |
35 | 29 |
36 SVGTextLayoutEngineSpacing::SVGTextLayoutEngineSpacing(const Font& font, float e ffectiveZoom) | 30 SVGTextLayoutEngineSpacing::SVGTextLayoutEngineSpacing(const Font& font, float e ffectiveZoom) |
37 : m_font(font) | 31 : m_font(font) |
38 , m_lastCharacter(0) | 32 , m_lastCharacter(0) |
39 , m_effectiveZoom(effectiveZoom) | 33 , m_effectiveZoom(effectiveZoom) |
40 #if ENABLE(SVG_FONTS) | |
41 , m_lastGlyph(0) | |
42 #endif | |
43 { | 34 { |
44 ASSERT(m_effectiveZoom); | 35 ASSERT(m_effectiveZoom); |
45 } | 36 } |
46 | 37 |
47 float SVGTextLayoutEngineSpacing::calculateSVGKerning(bool isVerticalText, Glyph currentGlyph) | 38 float SVGTextLayoutEngineSpacing::calculateSVGKerning(bool /*isVerticalText*/, G lyph /*currentGlyph*/) |
eae
2014/10/23 22:02:34
Can we remove this method entirely now (or in the
pdr.
2014/10/23 22:15:34
Done.
| |
48 { | 39 { |
49 #if ENABLE(SVG_FONTS) | |
50 const SimpleFontData* fontData = m_font.primaryFont(); | |
51 if (!fontData->isSVGFont()) { | |
52 m_lastGlyph = 0; | |
53 return 0; | |
54 } | |
55 | |
56 ASSERT(fontData->isCustomFont()); | |
57 ASSERT(fontData->isSVGFont()); | |
58 | |
59 RefPtr<CustomFontData> customFontData = fontData->customFontData(); | |
60 SVGFontFaceElement* svgFontFace = toSVGFontData(customFontData)->svgFontFace Element(); | |
61 ASSERT(svgFontFace); | |
62 | |
63 SVGFontElement* svgFont = svgFontFace->associatedFontElement(); | |
64 if (!svgFont) { | |
65 m_lastGlyph = 0; | |
66 return 0; | |
67 } | |
68 | |
69 float kerning = 0; | |
70 if (m_lastGlyph) { | |
71 if (isVerticalText) | |
72 kerning = svgFont->verticalKerningForPairOfGlyphs(m_lastGlyph, curre ntGlyph); | |
73 else | |
74 kerning = svgFont->horizontalKerningForPairOfGlyphs(m_lastGlyph, cur rentGlyph); | |
75 | |
76 kerning *= m_font.fontDescription().computedSize() / m_font.fontMetrics( ).unitsPerEm(); | |
77 } | |
78 | |
79 m_lastGlyph = currentGlyph; | |
80 return kerning; | |
81 #else | |
82 return 0; | 40 return 0; |
83 #endif | |
84 } | 41 } |
85 | 42 |
86 float SVGTextLayoutEngineSpacing::calculateCSSSpacing(UChar currentCharacter) | 43 float SVGTextLayoutEngineSpacing::calculateCSSSpacing(UChar currentCharacter) |
87 { | 44 { |
88 UChar lastCharacter = m_lastCharacter; | 45 UChar lastCharacter = m_lastCharacter; |
89 m_lastCharacter = currentCharacter; | 46 m_lastCharacter = currentCharacter; |
90 | 47 |
91 if (!m_font.fontDescription().letterSpacing() && !m_font.fontDescription().w ordSpacing()) | 48 if (!m_font.fontDescription().letterSpacing() && !m_font.fontDescription().w ordSpacing()) |
92 return 0; | 49 return 0; |
93 | 50 |
94 float spacing = m_font.fontDescription().letterSpacing(); | 51 float spacing = m_font.fontDescription().letterSpacing(); |
95 if (currentCharacter && lastCharacter && m_font.fontDescription().wordSpacin g()) { | 52 if (currentCharacter && lastCharacter && m_font.fontDescription().wordSpacin g()) { |
96 if (Character::treatAsSpace(currentCharacter) && !Character::treatAsSpac e(lastCharacter)) | 53 if (Character::treatAsSpace(currentCharacter) && !Character::treatAsSpac e(lastCharacter)) |
97 spacing += m_font.fontDescription().wordSpacing(); | 54 spacing += m_font.fontDescription().wordSpacing(); |
98 } | 55 } |
99 | 56 |
100 if (m_effectiveZoom != 1) | 57 if (m_effectiveZoom != 1) |
101 spacing = spacing / m_effectiveZoom; | 58 spacing = spacing / m_effectiveZoom; |
102 | 59 |
103 return spacing; | 60 return spacing; |
104 } | 61 } |
105 | 62 |
106 } | 63 } |
OLD | NEW |