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

Side by Side Diff: ui/gfx/font_fallback_mac.mm

Issue 2959913002: PlatformFontMac: Use a default NSFont when an invalid font is passed. (Closed)
Patch Set: Use a default font Created 3 years, 5 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
« no previous file with comments | « no previous file | ui/gfx/platform_font_mac.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "ui/gfx/font_fallback.h" 5 #include "ui/gfx/font_fallback.h"
6 6
7 #include <CoreText/CoreText.h> 7 #include <CoreText/CoreText.h>
8 #import <Foundation/Foundation.h> 8 #import <Foundation/Foundation.h>
9 9
10 #include "base/mac/foundation_util.h" 10 #include "base/mac/foundation_util.h"
(...skipping 22 matching lines...) Expand all
33 base::ScopedCFTypeRef<CTFontDescriptorRef> lhs_descriptor( 33 base::ScopedCFTypeRef<CTFontDescriptorRef> lhs_descriptor(
34 CTFontCopyFontDescriptor(lhs)); 34 CTFontCopyFontDescriptor(lhs));
35 base::ScopedCFTypeRef<CTFontDescriptorRef> rhs_descriptor( 35 base::ScopedCFTypeRef<CTFontDescriptorRef> rhs_descriptor(
36 CTFontCopyFontDescriptor(rhs)); 36 CTFontCopyFontDescriptor(rhs));
37 return lhs_descriptor.get() == rhs_descriptor.get(); 37 return lhs_descriptor.get() == rhs_descriptor.get();
38 } 38 }
39 39
40 } // namespace 40 } // namespace
41 41
42 std::vector<Font> GetFallbackFonts(const Font& font) { 42 std::vector<Font> GetFallbackFonts(const Font& font) {
43 DCHECK(font.GetNativeFont());
43 // On Mac "There is a system default cascade list (which is polymorphic, based 44 // On Mac "There is a system default cascade list (which is polymorphic, based
44 // on the user's language setting and current font)" - CoreText Programming 45 // on the user's language setting and current font)" - CoreText Programming
45 // Guide. 46 // Guide.
46 NSArray* languages = [[NSUserDefaults standardUserDefaults] 47 NSArray* languages = [[NSUserDefaults standardUserDefaults]
47 stringArrayForKey:@"AppleLanguages"]; 48 stringArrayForKey:@"AppleLanguages"];
48 CFArrayRef languages_cf = base::mac::NSToCFCast(languages); 49 CFArrayRef languages_cf = base::mac::NSToCFCast(languages);
49 base::ScopedCFTypeRef<CFArrayRef> cascade_list( 50 base::ScopedCFTypeRef<CFArrayRef> cascade_list(
50 CTFontCopyDefaultCascadeListForLanguages( 51 CTFontCopyDefaultCascadeListForLanguages(
51 static_cast<CTFontRef>(font.GetNativeFont()), languages_cf)); 52 static_cast<CTFontRef>(font.GetNativeFont()), languages_cf));
52 53
53 std::vector<Font> fallback_fonts; 54 std::vector<Font> fallback_fonts;
55 if (!cascade_list)
56 return fallback_fonts; // This should only happen for an invalid |font|.
54 57
55 const CFIndex fallback_count = CFArrayGetCount(cascade_list); 58 const CFIndex fallback_count = CFArrayGetCount(cascade_list);
tapted 2017/06/28 03:46:10 Currently it's this line that crashes -- null can'
56 for (CFIndex i = 0; i < fallback_count; ++i) { 59 for (CFIndex i = 0; i < fallback_count; ++i) {
57 CTFontDescriptorRef descriptor = 60 CTFontDescriptorRef descriptor =
58 base::mac::CFCastStrict<CTFontDescriptorRef>( 61 base::mac::CFCastStrict<CTFontDescriptorRef>(
59 CFArrayGetValueAtIndex(cascade_list, i)); 62 CFArrayGetValueAtIndex(cascade_list, i));
60 base::ScopedCFTypeRef<CTFontRef> font( 63 base::ScopedCFTypeRef<CTFontRef> font(
61 CTFontCreateWithFontDescriptor(descriptor, 0.0, nullptr)); 64 CTFontCreateWithFontDescriptor(descriptor, 0.0, nullptr));
62 if (font.get()) 65 if (font.get())
63 fallback_fonts.push_back(Font(static_cast<NSFont*>(font.get()))); 66 fallback_fonts.push_back(Font(static_cast<NSFont*>(font.get())));
64 } 67 }
65 68
(...skipping 14 matching lines...) Expand all
80 base::ScopedCFTypeRef<CTFontRef> ct_result( 83 base::ScopedCFTypeRef<CTFontRef> ct_result(
81 CTFontCreateForString(ct_font, cf_string, {0, text_length})); 84 CTFontCreateForString(ct_font, cf_string, {0, text_length}));
82 if (FontsEqual(ct_font, ct_result)) 85 if (FontsEqual(ct_font, ct_result))
83 return false; 86 return false;
84 87
85 *result = Font(base::mac::CFToNSCast(ct_result.get())); 88 *result = Font(base::mac::CFToNSCast(ct_result.get()));
86 return true; 89 return true;
87 } 90 }
88 91
89 } // namespace gfx 92 } // namespace gfx
OLDNEW
« no previous file with comments | « no previous file | ui/gfx/platform_font_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698