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

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

Issue 2416033003: Remove unsafe getFontMetrics methods (Closed)
Patch Set: Address wkroman suggestions Created 4 years, 2 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 16 matching lines...) Expand all
27 27
28 SVGTextLayoutEngineBaseline::SVGTextLayoutEngineBaseline(const Font& font, 28 SVGTextLayoutEngineBaseline::SVGTextLayoutEngineBaseline(const Font& font,
29 float effectiveZoom) 29 float effectiveZoom)
30 : m_font(font), m_effectiveZoom(effectiveZoom) { 30 : m_font(font), m_effectiveZoom(effectiveZoom) {
31 ASSERT(m_effectiveZoom); 31 ASSERT(m_effectiveZoom);
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();
38 DCHECK(fontData);
39 if (!fontData)
40 return 0;
37 41
42 DCHECK(m_effectiveZoom);
38 switch (svgStyle.baselineShift()) { 43 switch (svgStyle.baselineShift()) {
39 case BS_LENGTH: 44 case BS_LENGTH:
40 return SVGLengthContext::valueForLength( 45 return SVGLengthContext::valueForLength(
41 svgStyle.baselineShiftValue(), style, 46 svgStyle.baselineShiftValue(), style,
42 m_font.getFontDescription().computedPixelSize() / m_effectiveZoom); 47 m_font.getFontDescription().computedPixelSize() / m_effectiveZoom);
43 case BS_SUB: 48 case BS_SUB:
44 return -m_font.getFontMetrics().floatHeight() / 2 / m_effectiveZoom; 49 return -fontData->getFontMetrics().floatHeight() / 2 / m_effectiveZoom;
45 case BS_SUPER: 50 case BS_SUPER:
46 return m_font.getFontMetrics().floatHeight() / 2 / m_effectiveZoom; 51 return fontData->getFontMetrics().floatHeight() / 2 / m_effectiveZoom;
47 default: 52 default:
48 ASSERT_NOT_REACHED(); 53 ASSERT_NOT_REACHED();
49 return 0; 54 return 0;
50 } 55 }
51 } 56 }
52 57
53 EAlignmentBaseline 58 EAlignmentBaseline
54 SVGTextLayoutEngineBaseline::dominantBaselineToAlignmentBaseline( 59 SVGTextLayoutEngineBaseline::dominantBaselineToAlignmentBaseline(
55 bool isVerticalText, 60 bool isVerticalText,
56 LineLayoutItem textLineLayout) const { 61 LineLayoutItem textLineLayout) const {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 ASSERT(textLineLayoutParent); 119 ASSERT(textLineLayoutParent);
115 120
116 EAlignmentBaseline baseline = 121 EAlignmentBaseline baseline =
117 textLineLayout.style()->svgStyle().alignmentBaseline(); 122 textLineLayout.style()->svgStyle().alignmentBaseline();
118 if (baseline == AB_AUTO || baseline == AB_BASELINE) { 123 if (baseline == AB_AUTO || baseline == AB_BASELINE) {
119 baseline = dominantBaselineToAlignmentBaseline(isVerticalText, 124 baseline = dominantBaselineToAlignmentBaseline(isVerticalText,
120 textLineLayoutParent); 125 textLineLayoutParent);
121 ASSERT(baseline != AB_AUTO && baseline != AB_BASELINE); 126 ASSERT(baseline != AB_AUTO && baseline != AB_BASELINE);
122 } 127 }
123 128
124 const FontMetrics& fontMetrics = m_font.getFontMetrics(); 129 const SimpleFontData* fontData = m_font.primaryFont();
130 DCHECK(fontData);
131 if (!fontData)
132 return 0;
133
134 const FontMetrics& fontMetrics = fontData->getFontMetrics();
125 float ascent = fontMetrics.floatAscent() / m_effectiveZoom; 135 float ascent = fontMetrics.floatAscent() / m_effectiveZoom;
126 float descent = fontMetrics.floatDescent() / m_effectiveZoom; 136 float descent = fontMetrics.floatDescent() / m_effectiveZoom;
127 float xheight = fontMetrics.xHeight() / m_effectiveZoom; 137 float xheight = fontMetrics.xHeight() / m_effectiveZoom;
128 138
129 // Note: http://wiki.apache.org/xmlgraphics-fop/LineLayout/AlignmentHandling 139 // Note: http://wiki.apache.org/xmlgraphics-fop/LineLayout/AlignmentHandling
130 switch (baseline) { 140 switch (baseline) {
131 case AB_BEFORE_EDGE: 141 case AB_BEFORE_EDGE:
132 case AB_TEXT_BEFORE_EDGE: 142 case AB_TEXT_BEFORE_EDGE:
133 return ascent; 143 return ascent;
134 case AB_MIDDLE: 144 case AB_MIDDLE:
(...skipping 11 matching lines...) Expand all
146 case AB_MATHEMATICAL: 156 case AB_MATHEMATICAL:
147 return ascent / 2; 157 return ascent / 2;
148 case AB_BASELINE: 158 case AB_BASELINE:
149 default: 159 default:
150 ASSERT_NOT_REACHED(); 160 ASSERT_NOT_REACHED();
151 return 0; 161 return 0;
152 } 162 }
153 } 163 }
154 164
155 } // namespace blink 165 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698