Mercurial > repos > blastem
comparison nuklear_ui/font_mac.m @ 1560:18ffa9caa00c
Added code to fallback to Yosemite or pre-Yosemite system font in case current system font can't be found or is in an unusable format. San Francisco font used on current OS X versions is in a .otf file whih presumably means it has CFF outlines that stb_truetype can't use.
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Thu, 05 Apr 2018 00:06:19 -0700 |
parents | 098c11aaf8f0 |
children |
comparison
equal
deleted
inserted
replaced
1559:098c11aaf8f0 | 1560:18ffa9caa00c |
---|---|
2 #include <stddef.h> | 2 #include <stddef.h> |
3 #include "../paths.h" | 3 #include "../paths.h" |
4 #include "../util.h" | 4 #include "../util.h" |
5 #include "sfnt.h" | 5 #include "sfnt.h" |
6 | 6 |
7 sfnt_table *find_font_in_dir(char *path, char *prefix, const char *ps_name) | 7 static sfnt_table *find_font_in_dir(char *path, char *prefix, const char *ps_name) |
8 { | 8 { |
9 size_t num_entries; | 9 size_t num_entries; |
10 dir_entry *entries = get_dir_list(path, &num_entries); | 10 dir_entry *entries = get_dir_list(path, &num_entries); |
11 size_t prefix_len = prefix ? strlen(prefix) : 0; | 11 size_t prefix_len = prefix ? strlen(prefix) : 0; |
12 sfnt_table *selected = NULL; | 12 sfnt_table *selected = NULL; |
54 } | 54 } |
55 } | 55 } |
56 return selected; | 56 return selected; |
57 } | 57 } |
58 | 58 |
59 uint8_t *default_font(uint32_t *size_out) | 59 static sfnt_table *find_font_by_ps_name(const char*ps_name, uint8_t exhaustive) |
60 { | 60 { |
61 NSFont *sys = [NSFont systemFontOfSize:0]; | |
62 NSString *name = [sys fontName]; | |
63 const char *ps_name = [name UTF8String]; | |
64 const unsigned char *prefix_start = (const unsigned char *)ps_name; | 61 const unsigned char *prefix_start = (const unsigned char *)ps_name; |
65 while(*prefix_start && ( | 62 while(*prefix_start && ( |
66 *prefix_start < '0' || | 63 *prefix_start < '0' || |
67 (*prefix_start > 'z' && *prefix_start <= 0x80) || | 64 (*prefix_start > 'z' && *prefix_start <= 0x80) || |
68 (*prefix_start > 'Z' && *prefix_start < 'a') || | 65 (*prefix_start > 'Z' && *prefix_start < 'a') || |
86 //check /Library/Fonts first | 83 //check /Library/Fonts first |
87 sfnt_table *selected = find_font_in_dir("/Library/Fonts", (char *)prefix, ps_name); | 84 sfnt_table *selected = find_font_in_dir("/Library/Fonts", (char *)prefix, ps_name); |
88 if (!selected) { | 85 if (!selected) { |
89 selected = find_font_in_dir("/System/Library/Fonts", (char *)prefix, ps_name); | 86 selected = find_font_in_dir("/System/Library/Fonts", (char *)prefix, ps_name); |
90 } | 87 } |
88 if (exhaustive) { | |
89 if (!selected) { | |
90 puts("Check using prefix failed, exhaustively checking fonts"); | |
91 selected = find_font_in_dir("/Library/Fonts", NULL, ps_name); | |
92 } | |
93 if (!selected) { | |
94 selected = find_font_in_dir("/System/Library/Fonts", NULL, ps_name); | |
95 } | |
96 } | |
97 free(prefix); | |
98 return selected; | |
99 } | |
100 | |
101 uint8_t *default_font(uint32_t *size_out) | |
102 { | |
103 NSFont *sys = [NSFont systemFontOfSize:0]; | |
104 NSString *name = [sys fontName]; | |
105 sfnt_table *selected = find_font_by_ps_name([name UTF8String], 1); | |
91 if (!selected) { | 106 if (!selected) { |
92 puts("Check using prefix failed, exhaustively checking fonts"); | 107 selected = find_font_by_ps_name(".HelveticaNeueDeskInterface-Regular", 0); |
93 selected = find_font_in_dir("/Library/Fonts", NULL, ps_name); | |
94 } | 108 } |
95 if (!selected) { | 109 if (!selected) { |
96 selected = find_font_in_dir("/System/Library/Fonts", NULL, ps_name); | 110 selected = find_font_by_ps_name(".LucidaGrandeUI", 0); |
97 } | 111 } |
112 | |
98 if (!selected) { | 113 if (!selected) { |
99 fatal_error("Failed to find system font %s using prefix %s\n", ps_name, prefix); | 114 fatal_error("Failed to find system font %s\n", [name UTF8String]); |
100 } | 115 } |
101 free(prefix); | |
102 return sfnt_flatten(selected, size_out); | 116 return sfnt_flatten(selected, size_out); |
103 } | 117 } |
104 | 118 |