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

Unified Diff: third_party/WebKit/Source/platform/exported/WebFont.cpp

Issue 2416033003: Remove unsafe getFontMetrics methods (Closed)
Patch Set: 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/platform/exported/WebFont.cpp
diff --git a/third_party/WebKit/Source/platform/exported/WebFont.cpp b/third_party/WebKit/Source/platform/exported/WebFont.cpp
index 018aac915e7373d33b47246ca0abb0786b138772..d35b35f48dfe685bcb2b1a2130d559ae3224e37e 100644
--- a/third_party/WebKit/Source/platform/exported/WebFont.cpp
+++ b/third_party/WebKit/Source/platform/exported/WebFont.cpp
@@ -45,23 +45,33 @@ WebFontDescription WebFont::getFontDescription() const {
}
int WebFont::ascent() const {
- return m_private->getFont().getFontMetrics().ascent();
+ const SimpleFontData* fontData = m_private->getFont().primaryFont();
+ DCHECK(fontData);
+ return fontData ? fontData->getFontMetrics().ascent() : 0;
wkorman 2016/10/13 22:54:31 Could be worth a helper method to use here and in
eae 2016/10/13 23:09:58 Good idea.
}
int WebFont::descent() const {
- return m_private->getFont().getFontMetrics().descent();
+ const SimpleFontData* fontData = m_private->getFont().primaryFont();
+ DCHECK(fontData);
+ return fontData ? fontData->getFontMetrics().descent() : 0;
}
int WebFont::height() const {
- return m_private->getFont().getFontMetrics().height();
+ const SimpleFontData* fontData = m_private->getFont().primaryFont();
+ DCHECK(fontData);
+ return fontData ? fontData->getFontMetrics().height() : 0;
}
int WebFont::lineSpacing() const {
- return m_private->getFont().getFontMetrics().lineSpacing();
+ const SimpleFontData* fontData = m_private->getFont().primaryFont();
+ DCHECK(fontData);
+ return fontData ? fontData->getFontMetrics().lineSpacing() : 0;
}
float WebFont::xHeight() const {
- return m_private->getFont().getFontMetrics().xHeight();
+ const SimpleFontData* fontData = m_private->getFont().primaryFont();
+ DCHECK(fontData);
+ return fontData ? fontData->getFontMetrics().xHeight() : 0;
}
void WebFont::drawText(WebCanvas* canvas,

Powered by Google App Engine
This is Rietveld 408576698