| 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..6075a0d77318852c74132b07bc94422cd3ef49b4 100644
|
| --- a/ui/gfx/render_text_mac.mm
|
| +++ b/ui/gfx/render_text_mac.mm
|
| @@ -61,6 +61,30 @@ 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();
|
| +}
|
| +
|
| +// Checks whether |font_list| is valid. If it isn't, returns the default font
|
| +// list (or a font list derived from it). The returned font list will have a
|
| +// valid primary native font.
|
| +gfx::FontList GetValidFontList(const gfx::FontList& font_list) {
|
| + if (HasValidPrimaryNativeFont(font_list))
|
| + return font_list;
|
| +
|
| + const gfx::FontList default_font_list;
|
| + const int size_delta =
|
| + font_list.GetFontSize() - default_font_list.GetFontSize();
|
| + const 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 +114,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.
|
| + RenderText::SetFontList(GetValidFontList(font_list));
|
| +}
|
| +
|
| bool RenderTextMac::MultilineSupported() const {
|
| return false;
|
| }
|
| @@ -283,6 +312,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};
|
|
|