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 #include "core/layout/svg/SVGTextLayoutEngineBaseline.h" | 21 #include "core/layout/svg/SVGTextLayoutEngineBaseline.h" |
22 | 22 |
23 #include "core/layout/LayoutObject.h" | 23 #include "core/layout/LayoutObject.h" |
24 #include "core/layout/style/SVGLayoutStyle.h" | 24 #include "core/layout/style/SVGComputedStyle.h" |
25 #include "core/layout/svg/SVGTextMetrics.h" | 25 #include "core/layout/svg/SVGTextMetrics.h" |
26 #include "core/svg/SVGLengthContext.h" | 26 #include "core/svg/SVGLengthContext.h" |
27 #include "platform/fonts/Font.h" | 27 #include "platform/fonts/Font.h" |
28 #include "platform/text/UnicodeRange.h" | 28 #include "platform/text/UnicodeRange.h" |
29 | 29 |
30 namespace blink { | 30 namespace blink { |
31 | 31 |
32 SVGTextLayoutEngineBaseline::SVGTextLayoutEngineBaseline(const Font& font) | 32 SVGTextLayoutEngineBaseline::SVGTextLayoutEngineBaseline(const Font& font) |
33 : m_font(font) | 33 : m_font(font) |
34 { | 34 { |
35 } | 35 } |
36 | 36 |
37 float SVGTextLayoutEngineBaseline::calculateBaselineShift(const LayoutStyle& sty
le) const | 37 float SVGTextLayoutEngineBaseline::calculateBaselineShift(const ComputedStyle& s
tyle) const |
38 { | 38 { |
39 const SVGLayoutStyle& svgStyle = style.svgStyle(); | 39 const SVGComputedStyle& svgStyle = style.svgStyle(); |
40 | 40 |
41 switch (svgStyle.baselineShift()) { | 41 switch (svgStyle.baselineShift()) { |
42 case BS_LENGTH: | 42 case BS_LENGTH: |
43 return SVGLengthContext::valueForLength(svgStyle.baselineShiftValue(), s
tyle, m_font.fontDescription().computedPixelSize()); | 43 return SVGLengthContext::valueForLength(svgStyle.baselineShiftValue(), s
tyle, m_font.fontDescription().computedPixelSize()); |
44 case BS_SUB: | 44 case BS_SUB: |
45 return -m_font.fontMetrics().floatHeight() / 2; | 45 return -m_font.fontMetrics().floatHeight() / 2; |
46 case BS_SUPER: | 46 case BS_SUPER: |
47 return m_font.fontMetrics().floatHeight() / 2; | 47 return m_font.fontMetrics().floatHeight() / 2; |
48 default: | 48 default: |
49 ASSERT_NOT_REACHED(); | 49 ASSERT_NOT_REACHED(); |
50 return 0; | 50 return 0; |
51 } | 51 } |
52 } | 52 } |
53 | 53 |
54 EAlignmentBaseline SVGTextLayoutEngineBaseline::dominantBaselineToAlignmentBasel
ine(bool isVerticalText, const LayoutObject* textRenderer) const | 54 EAlignmentBaseline SVGTextLayoutEngineBaseline::dominantBaselineToAlignmentBasel
ine(bool isVerticalText, const LayoutObject* textRenderer) const |
55 { | 55 { |
56 ASSERT(textRenderer); | 56 ASSERT(textRenderer); |
57 ASSERT(textRenderer->style()); | 57 ASSERT(textRenderer->style()); |
58 ASSERT(textRenderer->parent()); | 58 ASSERT(textRenderer->parent()); |
59 ASSERT(textRenderer->parent()->style()); | 59 ASSERT(textRenderer->parent()->style()); |
60 | 60 |
61 const SVGLayoutStyle& style = textRenderer->style()->svgStyle(); | 61 const SVGComputedStyle& style = textRenderer->style()->svgStyle(); |
62 | 62 |
63 EDominantBaseline baseline = style.dominantBaseline(); | 63 EDominantBaseline baseline = style.dominantBaseline(); |
64 if (baseline == DB_AUTO) { | 64 if (baseline == DB_AUTO) { |
65 if (isVerticalText) | 65 if (isVerticalText) |
66 baseline = DB_CENTRAL; | 66 baseline = DB_CENTRAL; |
67 else | 67 else |
68 baseline = DB_ALPHABETIC; | 68 baseline = DB_ALPHABETIC; |
69 } | 69 } |
70 | 70 |
71 switch (baseline) { | 71 switch (baseline) { |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 return fontMetrics.floatAscent() * 8 / 10.f; | 134 return fontMetrics.floatAscent() * 8 / 10.f; |
135 case AB_MATHEMATICAL: | 135 case AB_MATHEMATICAL: |
136 return fontMetrics.floatAscent() / 2; | 136 return fontMetrics.floatAscent() / 2; |
137 case AB_BASELINE: | 137 case AB_BASELINE: |
138 default: | 138 default: |
139 ASSERT_NOT_REACHED(); | 139 ASSERT_NOT_REACHED(); |
140 return 0; | 140 return 0; |
141 } | 141 } |
142 } | 142 } |
143 | 143 |
144 float SVGTextLayoutEngineBaseline::calculateGlyphOrientationAngle(bool isVertica
lText, const SVGLayoutStyle& style, const UChar& character) const | 144 float SVGTextLayoutEngineBaseline::calculateGlyphOrientationAngle(bool isVertica
lText, const SVGComputedStyle& style, const UChar& character) const |
145 { | 145 { |
146 switch (isVerticalText ? style.glyphOrientationVertical() : style.glyphOrien
tationHorizontal()) { | 146 switch (isVerticalText ? style.glyphOrientationVertical() : style.glyphOrien
tationHorizontal()) { |
147 case GO_AUTO: { | 147 case GO_AUTO: { |
148 // Spec: Fullwidth ideographic and fullwidth Latin text will be set with
a glyph-orientation of 0-degrees. | 148 // Spec: Fullwidth ideographic and fullwidth Latin text will be set with
a glyph-orientation of 0-degrees. |
149 // Text which is not fullwidth will be set with a glyph-orientation of 9
0-degrees. | 149 // Text which is not fullwidth will be set with a glyph-orientation of 9
0-degrees. |
150 unsigned unicodeRange = findCharUnicodeRange(character); | 150 unsigned unicodeRange = findCharUnicodeRange(character); |
151 if (unicodeRange == cRangeSetLatin || unicodeRange == cRangeArabic) | 151 if (unicodeRange == cRangeSetLatin || unicodeRange == cRangeArabic) |
152 return 90; | 152 return 90; |
153 | 153 |
154 return 0; | 154 return 0; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 } | 215 } |
216 | 216 |
217 // Horizontal advance calculation. | 217 // Horizontal advance calculation. |
218 if (angle && !orientationIsMultiplyOf180Degrees) | 218 if (angle && !orientationIsMultiplyOf180Degrees) |
219 return metrics.height(); | 219 return metrics.height(); |
220 | 220 |
221 return metrics.width(); | 221 return metrics.width(); |
222 } | 222 } |
223 | 223 |
224 } | 224 } |
OLD | NEW |