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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/layout/svg/SVGTextLayoutEngineBaseline.cpp
diff --git a/third_party/WebKit/Source/core/layout/svg/SVGTextLayoutEngineBaseline.cpp b/third_party/WebKit/Source/core/layout/svg/SVGTextLayoutEngineBaseline.cpp
index 5467d5df7c8a68c23dcf277b5958e7c2a7692900..560d971671948399be37b02732835171d124d411 100644
--- a/third_party/WebKit/Source/core/layout/svg/SVGTextLayoutEngineBaseline.cpp
+++ b/third_party/WebKit/Source/core/layout/svg/SVGTextLayoutEngineBaseline.cpp
@@ -34,16 +34,21 @@ SVGTextLayoutEngineBaseline::SVGTextLayoutEngineBaseline(const Font& font,
float SVGTextLayoutEngineBaseline::calculateBaselineShift(
const ComputedStyle& style) const {
const SVGComputedStyle& svgStyle = style.svgStyle();
+ const SimpleFontData* fontData = m_font.primaryFont();
+ DCHECK(fontData);
+ if (!fontData)
+ return 0;
+ DCHECK(m_effectiveZoom);
switch (svgStyle.baselineShift()) {
case BS_LENGTH:
return SVGLengthContext::valueForLength(
svgStyle.baselineShiftValue(), style,
m_font.getFontDescription().computedPixelSize() / m_effectiveZoom);
case BS_SUB:
- return -m_font.getFontMetrics().floatHeight() / 2 / m_effectiveZoom;
+ return -fontData->getFontMetrics().floatHeight() / 2 / m_effectiveZoom;
case BS_SUPER:
- return m_font.getFontMetrics().floatHeight() / 2 / m_effectiveZoom;
+ return fontData->getFontMetrics().floatHeight() / 2 / m_effectiveZoom;
default:
ASSERT_NOT_REACHED();
return 0;
@@ -121,7 +126,12 @@ float SVGTextLayoutEngineBaseline::calculateAlignmentBaselineShift(
ASSERT(baseline != AB_AUTO && baseline != AB_BASELINE);
}
- const FontMetrics& fontMetrics = m_font.getFontMetrics();
+ const SimpleFontData* fontData = m_font.primaryFont();
+ DCHECK(fontData);
+ if (!fontData)
+ return 0;
+
+ const FontMetrics& fontMetrics = fontData->getFontMetrics();
float ascent = fontMetrics.floatAscent() / m_effectiveZoom;
float descent = fontMetrics.floatDescent() / m_effectiveZoom;
float xheight = fontMetrics.xHeight() / m_effectiveZoom;

Powered by Google App Engine
This is Rietveld 408576698