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

Unified Diff: third_party/WebKit/Source/platform/exported/WebFont.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
« no previous file with comments | « third_party/WebKit/Source/platform/DragImage.cpp ('k') | third_party/WebKit/Source/platform/fonts/Font.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..1af56a47b46d903770fbefa38d8678c3a87be1b6 100644
--- a/third_party/WebKit/Source/platform/exported/WebFont.cpp
+++ b/third_party/WebKit/Source/platform/exported/WebFont.cpp
@@ -44,24 +44,36 @@ WebFontDescription WebFont::getFontDescription() const {
return WebFontDescription(m_private->getFont().getFontDescription());
}
+static inline const SimpleFontData* getFontData(const Font& font) {
+ const SimpleFontData* fontData = font.primaryFont();
+ DCHECK(fontData);
+ return fontData;
+}
+
int WebFont::ascent() const {
- return m_private->getFont().getFontMetrics().ascent();
+ const SimpleFontData* fontData = getFontData(m_private->getFont());
+ return fontData ? fontData->getFontMetrics().ascent() : 0;
}
int WebFont::descent() const {
- return m_private->getFont().getFontMetrics().descent();
+ const SimpleFontData* fontData = getFontData(m_private->getFont());
+ return fontData ? fontData->getFontMetrics().descent() : 0;
}
int WebFont::height() const {
- return m_private->getFont().getFontMetrics().height();
+ const SimpleFontData* fontData = getFontData(m_private->getFont());
+ return fontData ? fontData->getFontMetrics().height() : 0;
}
int WebFont::lineSpacing() const {
- return m_private->getFont().getFontMetrics().lineSpacing();
+ const SimpleFontData* fontData = getFontData(m_private->getFont());
+ 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,
« no previous file with comments | « third_party/WebKit/Source/platform/DragImage.cpp ('k') | third_party/WebKit/Source/platform/fonts/Font.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698