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

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

Issue 2427773002: Fixing superscript and subscript baseline for tiny fonts in SVG
Patch Set: Rebaseline Created 3 years, 10 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
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 21 matching lines...) Expand all
32 } 32 }
33 33
34 float SVGTextLayoutEngineBaseline::calculateBaselineShift( 34 float SVGTextLayoutEngineBaseline::calculateBaselineShift(
35 const ComputedStyle& style) const { 35 const ComputedStyle& style) const {
36 const SVGComputedStyle& svgStyle = style.svgStyle(); 36 const SVGComputedStyle& svgStyle = style.svgStyle();
37 const SimpleFontData* fontData = m_font.primaryFont(); 37 const SimpleFontData* fontData = m_font.primaryFont();
38 DCHECK(fontData); 38 DCHECK(fontData);
39 if (!fontData) 39 if (!fontData)
40 return 0; 40 return 0;
41 41
42 // If font size is smaller than 3, rounding ascent and descent values in
43 // SimpleFontData sets the baseline shifts for superscript and subscript to
44 // zero. In this case, we use subpixel ascent and descent.
45 if (m_font.getFontDescription().getSize().value < 3.0) {
46 const SimpleFontData* altFontData =
47 fontData->subpixelAscentDescentFontData().get();
48 if (altFontData)
49 fontData = altFontData;
50 }
51 DCHECK(fontData);
52 if (!fontData)
53 return 0;
54
42 DCHECK(m_effectiveZoom); 55 DCHECK(m_effectiveZoom);
43 switch (svgStyle.baselineShift()) { 56 switch (svgStyle.baselineShift()) {
44 case BS_LENGTH: 57 case BS_LENGTH:
45 return SVGLengthContext::valueForLength( 58 return SVGLengthContext::valueForLength(
46 svgStyle.baselineShiftValue(), style, 59 svgStyle.baselineShiftValue(), style,
47 m_font.getFontDescription().computedPixelSize() / m_effectiveZoom); 60 m_font.getFontDescription().computedPixelSize() / m_effectiveZoom);
48 case BS_SUB: 61 case BS_SUB:
49 return -fontData->getFontMetrics().floatHeight() / 2 / m_effectiveZoom; 62 return -fontData->getFontMetrics().floatHeight() / 2 / m_effectiveZoom;
50 case BS_SUPER: 63 case BS_SUPER:
51 return fontData->getFontMetrics().floatHeight() / 2 / m_effectiveZoom; 64 return fontData->getFontMetrics().floatHeight() / 2 / m_effectiveZoom;
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 baseline = dominantBaselineToAlignmentBaseline(isVerticalText, 137 baseline = dominantBaselineToAlignmentBaseline(isVerticalText,
125 textLineLayoutParent); 138 textLineLayoutParent);
126 ASSERT(baseline != AB_AUTO && baseline != AB_BASELINE); 139 ASSERT(baseline != AB_AUTO && baseline != AB_BASELINE);
127 } 140 }
128 141
129 const SimpleFontData* fontData = m_font.primaryFont(); 142 const SimpleFontData* fontData = m_font.primaryFont();
130 DCHECK(fontData); 143 DCHECK(fontData);
131 if (!fontData) 144 if (!fontData)
132 return 0; 145 return 0;
133 146
147 // If font size is smaller than 3, rounding ascent and descent values in
148 // SimpleFontData sets the baseline shifts for superscript and subscript to
149 // zero. In this case, we use subpixel ascent and descent.
150 if (m_font.getFontDescription().getSize().value < 3.0) {
151 const SimpleFontData* altFontData =
152 fontData->subpixelAscentDescentFontData().get();
153 if (altFontData)
154 fontData = altFontData;
155 }
156 DCHECK(fontData);
157 if (!fontData)
158 return 0;
159
134 const FontMetrics& fontMetrics = fontData->getFontMetrics(); 160 const FontMetrics& fontMetrics = fontData->getFontMetrics();
135 float ascent = fontMetrics.floatAscent() / m_effectiveZoom; 161 float ascent = fontMetrics.floatAscent() / m_effectiveZoom;
136 float descent = fontMetrics.floatDescent() / m_effectiveZoom; 162 float descent = fontMetrics.floatDescent() / m_effectiveZoom;
137 float xheight = fontMetrics.xHeight() / m_effectiveZoom; 163 float xheight = fontMetrics.xHeight() / m_effectiveZoom;
138 164
139 // Note: http://wiki.apache.org/xmlgraphics-fop/LineLayout/AlignmentHandling 165 // Note: http://wiki.apache.org/xmlgraphics-fop/LineLayout/AlignmentHandling
140 switch (baseline) { 166 switch (baseline) {
141 case AB_BEFORE_EDGE: 167 case AB_BEFORE_EDGE:
142 case AB_TEXT_BEFORE_EDGE: 168 case AB_TEXT_BEFORE_EDGE:
143 return ascent; 169 return ascent;
(...skipping 12 matching lines...) Expand all
156 case AB_MATHEMATICAL: 182 case AB_MATHEMATICAL:
157 return ascent / 2; 183 return ascent / 2;
158 case AB_BASELINE: 184 case AB_BASELINE:
159 default: 185 default:
160 ASSERT_NOT_REACHED(); 186 ASSERT_NOT_REACHED();
161 return 0; 187 return 0;
162 } 188 }
163 } 189 }
164 190
165 } // namespace blink 191 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698