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

Unified Diff: third_party/WebKit/Source/core/svg/SVGLengthContext.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/svg/SVGLengthContext.cpp
diff --git a/third_party/WebKit/Source/core/svg/SVGLengthContext.cpp b/third_party/WebKit/Source/core/svg/SVGLengthContext.cpp
index 2670221a4c2a590ac206e0a08d65c43cd50bd97d..bd4cf089796b580dc03810a7fd2d4dcd88b938b4 100644
--- a/third_party/WebKit/Source/core/svg/SVGLengthContext.cpp
+++ b/third_party/WebKit/Source/core/svg/SVGLengthContext.cpp
@@ -373,11 +373,12 @@ float SVGLengthContext::convertValueFromUserUnits(
float SVGLengthContext::convertValueFromUserUnitsToCHS(float value) const {
const ComputedStyle* style = computedStyleForLengthResolving(m_context);
- if (!style)
+ const SimpleFontData* fontData = style->font().primaryFont();
+ if (!style || !fontData)
return 0;
float zeroWidth =
- style->getFontMetrics().zeroWidth() / style->effectiveZoom();
+ fontData->getFontMetrics().zeroWidth() / style->effectiveZoom();
if (!zeroWidth)
return 0;
@@ -386,22 +387,25 @@ float SVGLengthContext::convertValueFromUserUnitsToCHS(float value) const {
float SVGLengthContext::convertValueFromCHSToUserUnits(float value) const {
const ComputedStyle* style = computedStyleForLengthResolving(m_context);
- if (!style)
+ const SimpleFontData* fontData = style->font().primaryFont();
+ if (!style || !fontData)
return 0;
- return value * style->getFontMetrics().zeroWidth() / style->effectiveZoom();
+ return value * fontData->getFontMetrics().zeroWidth() /
+ style->effectiveZoom();
}
float SVGLengthContext::convertValueFromUserUnitsToEXS(float value) const {
const ComputedStyle* style = computedStyleForLengthResolving(m_context);
- if (!style)
+ const SimpleFontData* fontData = style->font().primaryFont();
+ if (!style || !fontData)
return 0;
// Use of ceil allows a pixel match to the W3Cs expected output of
// coords-units-03-b.svg, if this causes problems in real world cases maybe it
// would be best to remove this.
float xHeight =
- ceilf(style->getFontMetrics().xHeight() / style->effectiveZoom());
+ ceilf(fontData->getFontMetrics().xHeight() / style->effectiveZoom());
if (!xHeight)
return 0;
@@ -410,14 +414,15 @@ float SVGLengthContext::convertValueFromUserUnitsToEXS(float value) const {
float SVGLengthContext::convertValueFromEXSToUserUnits(float value) const {
const ComputedStyle* style = computedStyleForLengthResolving(m_context);
- if (!style)
+ const SimpleFontData* fontData = style->font().primaryFont();
+ if (!style || !fontData)
return 0;
// Use of ceil allows a pixel match to the W3Cs expected output of
// coords-units-03-b.svg, if this causes problems in real world cases maybe it
// would be best to remove this.
return value *
- ceilf(style->getFontMetrics().xHeight() / style->effectiveZoom());
+ ceilf(fontData->getFontMetrics().xHeight() / style->effectiveZoom());
}
bool SVGLengthContext::determineViewport(FloatSize& viewportSize) const {
« no previous file with comments | « third_party/WebKit/Source/core/style/ComputedStyle.cpp ('k') | third_party/WebKit/Source/core/testing/Internals.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698