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

Unified Diff: ui/gfx/render_text_mac.mm

Issue 2734333005: RenderTextMac: Fix crash when passed an invalid font. (Closed)
Patch Set: Created 3 years, 9 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 | « ui/gfx/render_text_mac.h ('k') | ui/gfx/render_text_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/render_text_mac.mm
diff --git a/ui/gfx/render_text_mac.mm b/ui/gfx/render_text_mac.mm
index 948a303ab320c29914d5ad9757acd9ea208f2a91..7ccd4a48876604044e327cc009c450f1451e7c2b 100644
--- a/ui/gfx/render_text_mac.mm
+++ b/ui/gfx/render_text_mac.mm
@@ -61,6 +61,27 @@ base::ScopedCFTypeRef<CTFontRef> CopyFontWithSymbolicTraits(CTFontRef font,
CTFontCreateWithFontDescriptor(desc, 0.0, nullptr));
}
+// Returns whether |font_list| has a valid primary native font.
+bool HasValidPrimaryNativeFont(const gfx::FontList& font_list) {
+ return font_list.GetPrimaryFont().GetNativeFont();
+}
+
+gfx::FontList GetValidFontList(const gfx::FontList& font_list) {
+ if (HasValidPrimaryNativeFont(font_list))
+ return font_list;
+
+ gfx::FontList default_font_list;
+ const int size_delta =
+ font_list.GetFontSize() - default_font_list.GetFontSize();
+ gfx::FontList derived_font_list = default_font_list.Derive(
+ size_delta, font_list.GetFontStyle(), font_list.GetFontWeight());
+ if (HasValidPrimaryNativeFont(derived_font_list))
+ return derived_font_list;
+
+ DCHECK(HasValidPrimaryNativeFont(default_font_list));
+ return default_font_list;
+}
+
} // namespace
namespace gfx {
@@ -90,6 +111,11 @@ std::unique_ptr<RenderText> RenderTextMac::CreateInstanceOfSameType() const {
return base::WrapUnique(new RenderTextMac);
}
+void RenderTextMac::SetFontList(const FontList& font_list) {
+ // Ensure the font list used has a valid native font.
karandeepb 2017/03/09 01:33:32 We may need to do something similar in the base Re
+ RenderText::SetFontList(GetValidFontList(font_list));
+}
+
bool RenderTextMac::MultilineSupported() const {
return false;
}
@@ -283,6 +309,7 @@ base::ScopedCFTypeRef<CTLineRef> RenderTextMac::EnsureLayoutInternal(
base::ScopedCFTypeRef<CFMutableArrayRef>* attributes_owner) {
CTFontRef ct_font =
base::mac::NSToCFCast(font_list().GetPrimaryFont().GetNativeFont());
+ DCHECK(ct_font);
const void* keys[] = {kCTFontAttributeName};
const void* values[] = {ct_font};
« no previous file with comments | « ui/gfx/render_text_mac.h ('k') | ui/gfx/render_text_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698