Mercurial > repos > blastem
comparison nuklear_ui/font_mac.m @ 1559:098c11aaf8f0
Fix silly bug in handling of Mac Roman font names. Make Mac font search more exhaustive if the faster prefix check fails. Added a bunch of debug printfs in case those aren't sufficient to get things working on other machines
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Wed, 04 Apr 2018 00:01:17 -0700 |
parents | b4914d92308b |
children | 18ffa9caa00c |
comparison
equal
deleted
inserted
replaced
1558:55d357bb4398 | 1559:098c11aaf8f0 |
---|---|
6 | 6 |
7 sfnt_table *find_font_in_dir(char *path, char *prefix, const char *ps_name) | 7 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 = strlen(prefix); | 11 size_t prefix_len = prefix ? strlen(prefix) : 0; |
12 sfnt_table *selected = NULL; | 12 sfnt_table *selected = NULL; |
13 for (size_t i = 0; i < num_entries && !selected; i++) | 13 for (size_t i = 0; i < num_entries && !selected; i++) |
14 { | 14 { |
15 char *ext = path_extension(entries[i].name); | 15 char *ext = path_extension(entries[i].name); |
16 if (!ext || (strcasecmp(ext, "ttf") && strcasecmp(ext, "ttc") && strcasecmp(ext, "dfont"))) { | 16 if (!ext || (strcasecmp(ext, "ttf") && strcasecmp(ext, "ttc") && strcasecmp(ext, "dfont"))) { |
17 //not a truetype font, ignore | 17 //not a truetype font, ignore |
18 printf("Skipping %s because of its extension\n", entries[i].name); | |
18 free(ext); | 19 free(ext); |
19 continue; | 20 continue; |
20 } | 21 } |
21 free(ext); | 22 free(ext); |
22 if (!strncasecmp(entries[i].name, prefix, prefix_len)) { | 23 if (!prefix || !strncasecmp(entries[i].name, prefix, prefix_len)) { |
23 char *full_path = path_append(path, entries[i].name); | 24 char *full_path = path_append(path, entries[i].name); |
24 FILE *f = fopen(full_path, "rb"); | 25 FILE *f = fopen(full_path, "rb"); |
25 if (f) | 26 if (f) |
26 { | 27 { |
27 long font_size = file_size(f); | 28 long font_size = file_size(f); |
28 uint8_t *blob = malloc(font_size); | 29 uint8_t *blob = malloc(font_size); |
29 if (font_size == fread(blob, 1, font_size, f)) | 30 if (font_size == fread(blob, 1, font_size, f)) |
30 { | 31 { |
31 sfnt_container *sfnt = load_sfnt(blob, font_size); | 32 sfnt_container *sfnt = load_sfnt(blob, font_size); |
32 if (sfnt) { | 33 if (sfnt) { |
34 printf("Examining font file %s\n", entries[i].name); | |
33 for (uint8_t j = 0; j < sfnt->num_fonts && !selected; j++) | 35 for (uint8_t j = 0; j < sfnt->num_fonts && !selected; j++) |
34 { | 36 { |
35 char *cur_ps = sfnt_name(sfnt->tables + j, SFNT_POSTSCRIPT); | 37 char *cur_ps = sfnt_name(sfnt->tables + j, SFNT_POSTSCRIPT); |
38 printf("\t%s\n", cur_ps); | |
36 if (!strcmp(cur_ps, ps_name)) { | 39 if (!strcmp(cur_ps, ps_name)) { |
37 selected = sfnt->tables + j; | 40 selected = sfnt->tables + j; |
38 } | 41 } |
39 free(cur_ps); | 42 free(cur_ps); |
40 } | 43 } |
41 } else { | 44 } else { |
45 printf("Failed to load %s as sfnt containern\n", entries[i].name); | |
42 free(blob); | 46 free(blob); |
43 } | 47 } |
44 } else { | 48 } else { |
45 free(blob); | 49 free(blob); |
46 } | 50 } |
83 sfnt_table *selected = find_font_in_dir("/Library/Fonts", (char *)prefix, ps_name); | 87 sfnt_table *selected = find_font_in_dir("/Library/Fonts", (char *)prefix, ps_name); |
84 if (!selected) { | 88 if (!selected) { |
85 selected = find_font_in_dir("/System/Library/Fonts", (char *)prefix, ps_name); | 89 selected = find_font_in_dir("/System/Library/Fonts", (char *)prefix, ps_name); |
86 } | 90 } |
87 if (!selected) { | 91 if (!selected) { |
92 puts("Check using prefix failed, exhaustively checking fonts"); | |
93 selected = find_font_in_dir("/Library/Fonts", NULL, ps_name); | |
94 } | |
95 if (!selected) { | |
96 selected = find_font_in_dir("/System/Library/Fonts", NULL, ps_name); | |
97 } | |
98 if (!selected) { | |
88 fatal_error("Failed to find system font %s using prefix %s\n", ps_name, prefix); | 99 fatal_error("Failed to find system font %s using prefix %s\n", ps_name, prefix); |
89 } | 100 } |
90 free(prefix); | 101 free(prefix); |
91 return sfnt_flatten(selected, size_out); | 102 return sfnt_flatten(selected, size_out); |
92 } | 103 } |