# HG changeset patch # User Michael Pavone # Date 1522825277 25200 # Node ID 098c11aaf8f0591fe6ebee125b68df0f49b88272 # Parent 55d357bb4398c974ce69ec4ccf7b1913ce008fda 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 diff -r 55d357bb4398 -r 098c11aaf8f0 nuklear_ui/font_mac.m --- a/nuklear_ui/font_mac.m Mon Apr 02 00:58:42 2018 -0700 +++ b/nuklear_ui/font_mac.m Wed Apr 04 00:01:17 2018 -0700 @@ -8,18 +8,19 @@ { size_t num_entries; dir_entry *entries = get_dir_list(path, &num_entries); - size_t prefix_len = strlen(prefix); + size_t prefix_len = prefix ? strlen(prefix) : 0; sfnt_table *selected = NULL; for (size_t i = 0; i < num_entries && !selected; i++) { char *ext = path_extension(entries[i].name); if (!ext || (strcasecmp(ext, "ttf") && strcasecmp(ext, "ttc") && strcasecmp(ext, "dfont"))) { //not a truetype font, ignore + printf("Skipping %s because of its extension\n", entries[i].name); free(ext); continue; } free(ext); - if (!strncasecmp(entries[i].name, prefix, prefix_len)) { + if (!prefix || !strncasecmp(entries[i].name, prefix, prefix_len)) { char *full_path = path_append(path, entries[i].name); FILE *f = fopen(full_path, "rb"); if (f) @@ -30,15 +31,18 @@ { sfnt_container *sfnt = load_sfnt(blob, font_size); if (sfnt) { + printf("Examining font file %s\n", entries[i].name); for (uint8_t j = 0; j < sfnt->num_fonts && !selected; j++) { char *cur_ps = sfnt_name(sfnt->tables + j, SFNT_POSTSCRIPT); + printf("\t%s\n", cur_ps); if (!strcmp(cur_ps, ps_name)) { selected = sfnt->tables + j; } free(cur_ps); } } else { + printf("Failed to load %s as sfnt containern\n", entries[i].name); free(blob); } } else { @@ -85,6 +89,13 @@ selected = find_font_in_dir("/System/Library/Fonts", (char *)prefix, ps_name); } if (!selected) { + puts("Check using prefix failed, exhaustively checking fonts"); + selected = find_font_in_dir("/Library/Fonts", NULL, ps_name); + } + if (!selected) { + selected = find_font_in_dir("/System/Library/Fonts", NULL, ps_name); + } + if (!selected) { fatal_error("Failed to find system font %s using prefix %s\n", ps_name, prefix); } free(prefix); diff -r 55d357bb4398 -r 098c11aaf8f0 nuklear_ui/sfnt.c --- a/nuklear_ui/sfnt.c Mon Apr 02 00:58:42 2018 -0700 +++ b/nuklear_ui/sfnt.c Wed Apr 04 00:01:17 2018 -0700 @@ -200,9 +200,9 @@ } if (entry == macroman_entry) { //TODO: convert these properly to UTF-8 - char *ret = malloc(name_size + 1); + char *ret = malloc(name_length + 1); memcpy(ret, name_table + full_off, name_length); - ret[name_size] = 0; + ret[name_length] = 0; return ret; } else { return utf16be_to_utf8(name_table + full_off, name_length/2);