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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "public/platform/WebFont.h" 5 #include "public/platform/WebFont.h"
6 6
7 #include "platform/fonts/Font.h" 7 #include "platform/fonts/Font.h"
8 #include "platform/fonts/FontCache.h" 8 #include "platform/fonts/FontCache.h"
9 #include "platform/fonts/FontDescription.h" 9 #include "platform/fonts/FontDescription.h"
10 #include "platform/graphics/GraphicsContext.h" 10 #include "platform/graphics/GraphicsContext.h"
(...skipping 26 matching lines...) Expand all
37 37
38 WebFont::WebFont(const WebFontDescription& description) 38 WebFont::WebFont(const WebFontDescription& description)
39 : m_private(new Impl(description)) {} 39 : m_private(new Impl(description)) {}
40 40
41 WebFont::~WebFont() {} 41 WebFont::~WebFont() {}
42 42
43 WebFontDescription WebFont::getFontDescription() const { 43 WebFontDescription WebFont::getFontDescription() const {
44 return WebFontDescription(m_private->getFont().getFontDescription()); 44 return WebFontDescription(m_private->getFont().getFontDescription());
45 } 45 }
46 46
47 static inline const SimpleFontData* getFontData(const Font& font) {
48 const SimpleFontData* fontData = font.primaryFont();
49 DCHECK(fontData);
50 return fontData;
51 }
52
47 int WebFont::ascent() const { 53 int WebFont::ascent() const {
48 return m_private->getFont().getFontMetrics().ascent(); 54 const SimpleFontData* fontData = getFontData(m_private->getFont());
55 return fontData ? fontData->getFontMetrics().ascent() : 0;
49 } 56 }
50 57
51 int WebFont::descent() const { 58 int WebFont::descent() const {
52 return m_private->getFont().getFontMetrics().descent(); 59 const SimpleFontData* fontData = getFontData(m_private->getFont());
60 return fontData ? fontData->getFontMetrics().descent() : 0;
53 } 61 }
54 62
55 int WebFont::height() const { 63 int WebFont::height() const {
56 return m_private->getFont().getFontMetrics().height(); 64 const SimpleFontData* fontData = getFontData(m_private->getFont());
65 return fontData ? fontData->getFontMetrics().height() : 0;
57 } 66 }
58 67
59 int WebFont::lineSpacing() const { 68 int WebFont::lineSpacing() const {
60 return m_private->getFont().getFontMetrics().lineSpacing(); 69 const SimpleFontData* fontData = getFontData(m_private->getFont());
70 return fontData ? fontData->getFontMetrics().lineSpacing() : 0;
61 } 71 }
62 72
63 float WebFont::xHeight() const { 73 float WebFont::xHeight() const {
64 return m_private->getFont().getFontMetrics().xHeight(); 74 const SimpleFontData* fontData = m_private->getFont().primaryFont();
75 DCHECK(fontData);
76 return fontData ? fontData->getFontMetrics().xHeight() : 0;
65 } 77 }
66 78
67 void WebFont::drawText(WebCanvas* canvas, 79 void WebFont::drawText(WebCanvas* canvas,
68 const WebTextRun& run, 80 const WebTextRun& run,
69 const WebFloatPoint& leftBaseline, 81 const WebFloatPoint& leftBaseline,
70 WebColor color, 82 WebColor color,
71 const WebRect& clip) const { 83 const WebRect& clip) const {
72 FontCachePurgePreventer fontCachePurgePreventer; 84 FontCachePurgePreventer fontCachePurgePreventer;
73 FloatRect textClipRect(clip); 85 FloatRect textClipRect(clip);
74 TextRun textRun(run); 86 TextRun textRun(run);
(...skipping 28 matching lines...) Expand all
103 WebFloatRect WebFont::selectionRectForText(const WebTextRun& run, 115 WebFloatRect WebFont::selectionRectForText(const WebTextRun& run,
104 const WebFloatPoint& leftBaseline, 116 const WebFloatPoint& leftBaseline,
105 int height, 117 int height,
106 int from, 118 int from,
107 int to) const { 119 int to) const {
108 return m_private->getFont().selectionRectForText(run, leftBaseline, height, 120 return m_private->getFont().selectionRectForText(run, leftBaseline, height,
109 from, to); 121 from, to);
110 } 122 }
111 123
112 } // namespace blink 124 } // namespace blink
OLDNEW
« 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