Chromium Code Reviews| 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}; |