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

Side by Side 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 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 27 matching lines...) Expand all
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 int WebFont::ascent() const { 47 int WebFont::ascent() const {
48 return m_private->getFont().getFontMetrics().ascent(); 48 const SimpleFontData* fontData = m_private->getFont().primaryFont();
49 DCHECK(fontData);
50 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.
49 } 51 }
50 52
51 int WebFont::descent() const { 53 int WebFont::descent() const {
52 return m_private->getFont().getFontMetrics().descent(); 54 const SimpleFontData* fontData = m_private->getFont().primaryFont();
55 DCHECK(fontData);
56 return fontData ? fontData->getFontMetrics().descent() : 0;
53 } 57 }
54 58
55 int WebFont::height() const { 59 int WebFont::height() const {
56 return m_private->getFont().getFontMetrics().height(); 60 const SimpleFontData* fontData = m_private->getFont().primaryFont();
61 DCHECK(fontData);
62 return fontData ? fontData->getFontMetrics().height() : 0;
57 } 63 }
58 64
59 int WebFont::lineSpacing() const { 65 int WebFont::lineSpacing() const {
60 return m_private->getFont().getFontMetrics().lineSpacing(); 66 const SimpleFontData* fontData = m_private->getFont().primaryFont();
67 DCHECK(fontData);
68 return fontData ? fontData->getFontMetrics().lineSpacing() : 0;
61 } 69 }
62 70
63 float WebFont::xHeight() const { 71 float WebFont::xHeight() const {
64 return m_private->getFont().getFontMetrics().xHeight(); 72 const SimpleFontData* fontData = m_private->getFont().primaryFont();
73 DCHECK(fontData);
74 return fontData ? fontData->getFontMetrics().xHeight() : 0;
65 } 75 }
66 76
67 void WebFont::drawText(WebCanvas* canvas, 77 void WebFont::drawText(WebCanvas* canvas,
68 const WebTextRun& run, 78 const WebTextRun& run,
69 const WebFloatPoint& leftBaseline, 79 const WebFloatPoint& leftBaseline,
70 WebColor color, 80 WebColor color,
71 const WebRect& clip) const { 81 const WebRect& clip) const {
72 FontCachePurgePreventer fontCachePurgePreventer; 82 FontCachePurgePreventer fontCachePurgePreventer;
73 FloatRect textClipRect(clip); 83 FloatRect textClipRect(clip);
74 TextRun textRun(run); 84 TextRun textRun(run);
(...skipping 28 matching lines...) Expand all
103 WebFloatRect WebFont::selectionRectForText(const WebTextRun& run, 113 WebFloatRect WebFont::selectionRectForText(const WebTextRun& run,
104 const WebFloatPoint& leftBaseline, 114 const WebFloatPoint& leftBaseline,
105 int height, 115 int height,
106 int from, 116 int from,
107 int to) const { 117 int to) const {
108 return m_private->getFont().selectionRectForText(run, leftBaseline, height, 118 return m_private->getFont().selectionRectForText(run, leftBaseline, height,
109 from, to); 119 from, to);
110 } 120 }
111 121
112 } // namespace blink 122 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698