Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(366)

Side by Side Diff: Source/core/layout/svg/SVGTextLayoutEngineBaseline.cpp

Issue 1081813003: Remove effective zoom from font metrics before SVG text layout. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Added tests Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/core/layout/svg/SVGTextLayoutEngineBaseline.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
(...skipping 11 matching lines...) Expand all
22 22
23 #include "core/layout/LayoutObject.h" 23 #include "core/layout/LayoutObject.h"
24 #include "core/style/SVGComputedStyle.h" 24 #include "core/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, float effectiveZoom)
33 : m_font(font) 33 : m_font(font)
34 , m_effectiveZoom(effectiveZoom)
34 { 35 {
36 ASSERT(m_effectiveZoom);
35 } 37 }
36 38
37 float SVGTextLayoutEngineBaseline::calculateBaselineShift(const ComputedStyle& s tyle) const 39 float SVGTextLayoutEngineBaseline::calculateBaselineShift(const ComputedStyle& s tyle) const
38 { 40 {
39 const SVGComputedStyle& svgStyle = style.svgStyle(); 41 const SVGComputedStyle& svgStyle = style.svgStyle();
40 42
41 switch (svgStyle.baselineShift()) { 43 switch (svgStyle.baselineShift()) {
42 case BS_LENGTH: 44 case BS_LENGTH:
43 return SVGLengthContext::valueForLength(svgStyle.baselineShiftValue(), s tyle, m_font.fontDescription().computedPixelSize()); 45 return SVGLengthContext::valueForLength(svgStyle.baselineShiftValue(), s tyle, m_font.fontDescription().computedPixelSize() / m_effectiveZoom);
44 case BS_SUB: 46 case BS_SUB:
45 return -m_font.fontMetrics().floatHeight() / 2; 47 return -m_font.fontMetrics().floatHeight() / 2 / m_effectiveZoom;
46 case BS_SUPER: 48 case BS_SUPER:
47 return m_font.fontMetrics().floatHeight() / 2; 49 return m_font.fontMetrics().floatHeight() / 2 / m_effectiveZoom;
48 default: 50 default:
49 ASSERT_NOT_REACHED(); 51 ASSERT_NOT_REACHED();
50 return 0; 52 return 0;
51 } 53 }
52 } 54 }
53 55
54 EAlignmentBaseline SVGTextLayoutEngineBaseline::dominantBaselineToAlignmentBasel ine(bool isVerticalText, const LayoutObject* textRenderer) const 56 EAlignmentBaseline SVGTextLayoutEngineBaseline::dominantBaselineToAlignmentBasel ine(bool isVerticalText, const LayoutObject* textRenderer) const
55 { 57 {
56 ASSERT(textRenderer); 58 ASSERT(textRenderer);
57 ASSERT(textRenderer->style()); 59 ASSERT(textRenderer->style());
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 ASSERT(textRendererParent); 110 ASSERT(textRendererParent);
109 111
110 EAlignmentBaseline baseline = textRenderer->style()->svgStyle().alignmentBas eline(); 112 EAlignmentBaseline baseline = textRenderer->style()->svgStyle().alignmentBas eline();
111 if (baseline == AB_AUTO || baseline == AB_BASELINE) { 113 if (baseline == AB_AUTO || baseline == AB_BASELINE) {
112 baseline = dominantBaselineToAlignmentBaseline(isVerticalText, textRende rerParent); 114 baseline = dominantBaselineToAlignmentBaseline(isVerticalText, textRende rerParent);
113 ASSERT(baseline != AB_AUTO && baseline != AB_BASELINE); 115 ASSERT(baseline != AB_AUTO && baseline != AB_BASELINE);
114 } 116 }
115 117
116 const FontMetrics& fontMetrics = m_font.fontMetrics(); 118 const FontMetrics& fontMetrics = m_font.fontMetrics();
117 119
120 float alignementBaselineShift = 0;
Erik Dahlström (inactive) 2015/04/14 09:13:08 s/alignement/alignment/
121
118 // Note: http://wiki.apache.org/xmlgraphics-fop/LineLayout/AlignmentHandling 122 // Note: http://wiki.apache.org/xmlgraphics-fop/LineLayout/AlignmentHandling
119 switch (baseline) { 123 switch (baseline) {
120 case AB_BEFORE_EDGE: 124 case AB_BEFORE_EDGE:
121 case AB_TEXT_BEFORE_EDGE: 125 case AB_TEXT_BEFORE_EDGE:
122 return fontMetrics.floatAscent(); 126 alignementBaselineShift = fontMetrics.floatAscent();
127 break;
123 case AB_MIDDLE: 128 case AB_MIDDLE:
124 return fontMetrics.xHeight() / 2; 129 alignementBaselineShift = fontMetrics.xHeight() / 2;
130 break;
125 case AB_CENTRAL: 131 case AB_CENTRAL:
126 return (fontMetrics.floatAscent() - fontMetrics.floatDescent()) / 2; 132 alignementBaselineShift = (fontMetrics.floatAscent() - fontMetrics.float Descent()) / 2;
133 break;
127 case AB_AFTER_EDGE: 134 case AB_AFTER_EDGE:
128 case AB_TEXT_AFTER_EDGE: 135 case AB_TEXT_AFTER_EDGE:
129 case AB_IDEOGRAPHIC: 136 case AB_IDEOGRAPHIC:
130 return -fontMetrics.floatDescent(); 137 alignementBaselineShift = -fontMetrics.floatDescent();
138 break;
131 case AB_ALPHABETIC: 139 case AB_ALPHABETIC:
132 return 0; 140 alignementBaselineShift = 0;
141 break;
133 case AB_HANGING: 142 case AB_HANGING:
134 return fontMetrics.floatAscent() * 8 / 10.f; 143 alignementBaselineShift = fontMetrics.floatAscent() * 8 / 10.f;
144 break;
135 case AB_MATHEMATICAL: 145 case AB_MATHEMATICAL:
136 return fontMetrics.floatAscent() / 2; 146 alignementBaselineShift = fontMetrics.floatAscent() / 2;
147 break;
137 case AB_BASELINE: 148 case AB_BASELINE:
138 default: 149 default:
139 ASSERT_NOT_REACHED(); 150 ASSERT_NOT_REACHED();
140 return 0;
141 } 151 }
152
153 if (m_effectiveZoom != 1)
154 alignementBaselineShift = alignementBaselineShift / m_effectiveZoom;
fs 2015/04/14 09:21:21 Since we have a nit in effect already... I'd prefe
155
156 return alignementBaselineShift;
142 } 157 }
143 158
144 float SVGTextLayoutEngineBaseline::calculateGlyphOrientationAngle(bool isVertica lText, const SVGComputedStyle& style, const UChar& character) const 159 float SVGTextLayoutEngineBaseline::calculateGlyphOrientationAngle(bool isVertica lText, const SVGComputedStyle& style, const UChar& character) const
145 { 160 {
146 switch (isVerticalText ? style.glyphOrientationVertical() : style.glyphOrien tationHorizontal()) { 161 switch (isVerticalText ? style.glyphOrientationVertical() : style.glyphOrien tationHorizontal()) {
147 case GO_AUTO: { 162 case GO_AUTO: {
148 // Spec: Fullwidth ideographic and fullwidth Latin text will be set with a glyph-orientation of 0-degrees. 163 // 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. 164 // Text which is not fullwidth will be set with a glyph-orientation of 9 0-degrees.
150 unsigned unicodeRange = findCharUnicodeRange(character); 165 unsigned unicodeRange = findCharUnicodeRange(character);
151 if (unicodeRange == cRangeSetLatin || unicodeRange == cRangeArabic) 166 if (unicodeRange == cRangeSetLatin || unicodeRange == cRangeArabic)
(...skipping 25 matching lines...) Expand all
177 // The function is based on spec requirements: 192 // The function is based on spec requirements:
178 // 193 //
179 // Spec: If the 'glyph-orientation-horizontal' results in an orientation ang le that is not a multiple of 194 // Spec: If the 'glyph-orientation-horizontal' results in an orientation ang le that is not a multiple of
180 // of 180 degrees, then the current text position is incremented according t o the vertical metrics of the glyph. 195 // of 180 degrees, then the current text position is incremented according t o the vertical metrics of the glyph.
181 // 196 //
182 // Spec: If if the 'glyph-orientation-vertical' results in an orientation an gle that is not a multiple of 197 // Spec: If if the 'glyph-orientation-vertical' results in an orientation an gle that is not a multiple of
183 // 180 degrees, then the current text position is incremented according to t he horizontal metrics of the glyph. 198 // 180 degrees, then the current text position is incremented according to t he horizontal metrics of the glyph.
184 199
185 const FontMetrics& fontMetrics = m_font.fontMetrics(); 200 const FontMetrics& fontMetrics = m_font.fontMetrics();
186 201
202 float ascent = fontMetrics.floatAscent() / m_effectiveZoom;
203 float descent = fontMetrics.floatDescent() / m_effectiveZoom;
204
187 // Vertical orientation handling. 205 // Vertical orientation handling.
188 if (isVerticalText) { 206 if (isVerticalText) {
189 float ascentMinusDescent = fontMetrics.floatAscent() - fontMetrics.float Descent(); 207 float ascentMinusDescent = ascent - descent;
208
190 if (!angle) { 209 if (!angle) {
191 xOrientationShift = (ascentMinusDescent - metrics.width()) / 2; 210 xOrientationShift = (ascentMinusDescent - metrics.width()) / 2;
192 yOrientationShift = fontMetrics.floatAscent(); 211 yOrientationShift = ascent;
193 } else if (angle == 180) { 212 } else if (angle == 180) {
194 xOrientationShift = (ascentMinusDescent + metrics.width()) / 2; 213 xOrientationShift = (ascentMinusDescent + metrics.width()) / 2;
195 } else if (angle == 270) { 214 } else if (angle == 270) {
196 yOrientationShift = metrics.width(); 215 yOrientationShift = metrics.width();
197 xOrientationShift = ascentMinusDescent; 216 xOrientationShift = ascentMinusDescent;
198 } 217 }
199 218
200 // Vertical advance calculation. 219 // Vertical advance calculation.
201 if (angle && !orientationIsMultiplyOf180Degrees) 220 if (angle && !orientationIsMultiplyOf180Degrees)
202 return metrics.width(); 221 return metrics.width();
203 222
204 return metrics.height(); 223 return metrics.height();
205 } 224 }
206 225
207 // Horizontal orientation handling. 226 // Horizontal orientation handling.
208 if (angle == 90) { 227 if (angle == 90) {
209 yOrientationShift = -metrics.width(); 228 yOrientationShift = -metrics.width();
210 } else if (angle == 180) { 229 } else if (angle == 180) {
211 xOrientationShift = metrics.width(); 230 xOrientationShift = metrics.width();
212 yOrientationShift = -fontMetrics.floatAscent(); 231 yOrientationShift = -ascent;
213 } else if (angle == 270) { 232 } else if (angle == 270) {
214 xOrientationShift = metrics.width(); 233 xOrientationShift = metrics.width();
215 } 234 }
216 235
217 // Horizontal advance calculation. 236 // Horizontal advance calculation.
218 if (angle && !orientationIsMultiplyOf180Degrees) 237 if (angle && !orientationIsMultiplyOf180Degrees)
219 return metrics.height(); 238 return metrics.height();
220 239
221 return metrics.width(); 240 return metrics.width();
222 } 241 }
223 242
224 } 243 }
OLDNEW
« no previous file with comments | « Source/core/layout/svg/SVGTextLayoutEngineBaseline.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698