changeset 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 5a6339e46917
files nuklear_ui/font_mac.m
diffstat 1 files changed, 24 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/nuklear_ui/font_mac.m	Wed Apr 04 00:01:17 2018 -0700
+++ b/nuklear_ui/font_mac.m	Thu Apr 05 00:06:19 2018 -0700
@@ -4,7 +4,7 @@
 #include "../util.h"
 #include "sfnt.h"
 
-sfnt_table *find_font_in_dir(char *path, char *prefix, const char *ps_name)
+static sfnt_table *find_font_in_dir(char *path, char *prefix, const char *ps_name)
 {
 	size_t num_entries;
 	dir_entry *entries = get_dir_list(path, &num_entries);
@@ -56,11 +56,8 @@
 	return selected;
 }
 
-uint8_t *default_font(uint32_t *size_out)
+static sfnt_table *find_font_by_ps_name(const char*ps_name, uint8_t exhaustive)
 {
-	NSFont *sys = [NSFont systemFontOfSize:0];
-	NSString *name = [sys fontName];
-	const char *ps_name = [name UTF8String];
 	const unsigned char *prefix_start = (const unsigned char *)ps_name;
 	while(*prefix_start && (
 		*prefix_start < '0' || 
@@ -88,17 +85,34 @@
 	if (!selected) {
 		selected = find_font_in_dir("/System/Library/Fonts", (char *)prefix, ps_name);
 	}
+	if (exhaustive) {
+		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);
+		}
+	}
+	free(prefix);
+	return selected;
+}
+
+uint8_t *default_font(uint32_t *size_out)
+{
+	NSFont *sys = [NSFont systemFontOfSize:0];
+	NSString *name = [sys fontName];
+	sfnt_table *selected = find_font_by_ps_name([name UTF8String], 1);
 	if (!selected) {
-		puts("Check using prefix failed, exhaustively checking fonts");
-		selected = find_font_in_dir("/Library/Fonts", NULL, ps_name);
+		selected = find_font_by_ps_name(".HelveticaNeueDeskInterface-Regular", 0);
 	}
 	if (!selected) {
-		selected = find_font_in_dir("/System/Library/Fonts", NULL, ps_name);
+		selected = find_font_by_ps_name(".LucidaGrandeUI", 0);
 	}
+	
 	if (!selected) {
-		fatal_error("Failed to find system font %s using prefix %s\n", ps_name, prefix);
+		fatal_error("Failed to find system font %s\n", [name UTF8String]);
 	}
-	free(prefix);
 	return sfnt_flatten(selected, size_out);
 }