annotate nuklear_ui/font_win.c @ 1971:80920c21bb52

Add an event log soft flush and call it twice per frame in between hard flushes to netplay latency when there are insufficient hardware updates to flush packets in the middle of a frame
author Michael Pavone <pavone@retrodev.com>
date Fri, 08 May 2020 11:40:30 -0700
parents 137dbd05ceab
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1524
b96f9fae757f Fix Windows build, added Windows default_font_path implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1 #include <windows.h>
b96f9fae757f Fix Windows build, added Windows default_font_path implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
2 #include <shlobj.h>
1527
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
3 #include <string.h>
1524
b96f9fae757f Fix Windows build, added Windows default_font_path implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
4 #include "../paths.h"
b96f9fae757f Fix Windows build, added Windows default_font_path implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
5 #include "../util.h"
1527
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
6 #include "sfnt.h"
1524
b96f9fae757f Fix Windows build, added Windows default_font_path implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
7
1527
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
8 uint8_t *default_font(uint32_t *size_out)
1524
b96f9fae757f Fix Windows build, added Windows default_font_path implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
9 {
1527
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
10 static const char *thin[] = {"Thin", NULL};
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
11 static const char *extra_light[] = {"ExtraLight", "UltraLight", NULL};
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
12 static const char *light[] = {"Light", NULL};
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
13 static const char *regular[] = {"Regular", "Normal", "Book", NULL};
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
14 static const char *medium[] = {"Medium", NULL};
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
15 static const char *semi_bold[] = {"SemiBold", "DemiBold", NULL};
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
16 static const char *bold[] = {"Bold", NULL};
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
17 static const char *extra_bold[] = {"ExtraBold", "UltraBold", NULL};
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
18 static const char *heavy[] = {"Heavy", "Black", NULL};
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
19 static const char **weight_to_subfamilies[] = {
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
20 NULL,
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
21 thin,
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
22 extra_light,
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
23 light,
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
24 regular,
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
25 medium,
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
26 semi_bold,
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
27 bold,
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
28 extra_bold,
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
29 heavy
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
30 };
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
31
1524
b96f9fae757f Fix Windows build, added Windows default_font_path implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
32 NONCLIENTMETRICSA metrics = {
b96f9fae757f Fix Windows build, added Windows default_font_path implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
33 .cbSize = sizeof(metrics)
b96f9fae757f Fix Windows build, added Windows default_font_path implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
34 };
1527
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
35 char *pref_name = NULL, *pref_prefix = NULL;
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
36 const char **pref_sub_families;
1524
b96f9fae757f Fix Windows build, added Windows default_font_path implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
37 if (SystemParametersInfoA(SPI_GETNONCLIENTMETRICS, sizeof(metrics), &metrics, 0)) {
1527
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
38 pref_name = metrics.lfMenuFont.lfFaceName;
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
39 int32_t weight = metrics.lfMenuFont.lfWeight / 100;
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
40 if (weight < 1 || weight > 9) {
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
41 weight = 4;
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
42 }
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
43 pref_sub_families = weight_to_subfamilies[weight];
1524
b96f9fae757f Fix Windows build, added Windows default_font_path implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
44 }
1527
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
45 if (pref_name) {
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
46 uint32_t prefix_len = 0;
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
47 while (pref_name[prefix_len] && pref_name[prefix_len] != ' ')
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
48 {
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
49 prefix_len++;
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
50 }
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
51 pref_prefix = malloc(prefix_len + 1);
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
52 memcpy(pref_prefix, pref_name, prefix_len);
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
53 pref_prefix[prefix_len] = 0;
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
54 }
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
55 sfnt_table *selected = NULL;
1524
b96f9fae757f Fix Windows build, added Windows default_font_path implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
56 char windows[MAX_PATH];
b96f9fae757f Fix Windows build, added Windows default_font_path implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
57 SHGetFolderPathA(NULL, CSIDL_WINDOWS, NULL, 0, windows);
b96f9fae757f Fix Windows build, added Windows default_font_path implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
58 char *fonts = path_append(windows, "Fonts");
b96f9fae757f Fix Windows build, added Windows default_font_path implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
59 size_t num_entries;
1527
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
60 char *tahoma = NULL, *arial = NULL;
1524
b96f9fae757f Fix Windows build, added Windows default_font_path implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
61 dir_entry *entries = get_dir_list(fonts, &num_entries);
1527
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
62 char *path = NULL;
1524
b96f9fae757f Fix Windows build, added Windows default_font_path implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
63 for (size_t i = 0; i < num_entries; i++)
b96f9fae757f Fix Windows build, added Windows default_font_path implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
64 {
b96f9fae757f Fix Windows build, added Windows default_font_path implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
65 if (entries[i].is_dir) {
b96f9fae757f Fix Windows build, added Windows default_font_path implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
66 continue;
b96f9fae757f Fix Windows build, added Windows default_font_path implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
67 }
b96f9fae757f Fix Windows build, added Windows default_font_path implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
68 char *ext = path_extension(entries[i].name);
1527
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
69 if (!ext || (strcasecmp(ext, "ttf") && strcasecmp(ext, "ttc") && strcasecmp(ext, "dfont"))) {
1524
b96f9fae757f Fix Windows build, added Windows default_font_path implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
70 //not a truetype font, ignore
b96f9fae757f Fix Windows build, added Windows default_font_path implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
71 free(ext);
b96f9fae757f Fix Windows build, added Windows default_font_path implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
72 continue;
b96f9fae757f Fix Windows build, added Windows default_font_path implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
73 }
b96f9fae757f Fix Windows build, added Windows default_font_path implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
74 free(ext);
b96f9fae757f Fix Windows build, added Windows default_font_path implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
75 char *base = basename_no_extension(entries[i].name);
1527
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
76 if (pref_prefix && !strncasecmp(base, pref_prefix, 6)) {
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
77 path = path_append(fonts, entries[i].name);
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
78 FILE *f = fopen(path, "rb");
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
79 if (f)
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
80 {
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
81 long font_size = file_size(f);
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
82 uint8_t *blob = malloc(font_size);
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
83 if (font_size == fread(blob, 1, font_size, f))
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
84 {
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
85 sfnt_container *sfnt = load_sfnt(blob, font_size);
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
86 if (sfnt) {
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
87 selected = sfnt_subfamily_by_names(sfnt, pref_sub_families);
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
88 if (!selected) {
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
89 sfnt_free(sfnt);
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
90 }
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
91 } else {
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
92 free(blob);
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
93 }
1536
982c5327dfcc Fix memory leak in edge case of font_win
Michael Pavone <pavone@retrodev.com>
parents: 1527
diff changeset
94 } else {
982c5327dfcc Fix memory leak in edge case of font_win
Michael Pavone <pavone@retrodev.com>
parents: 1527
diff changeset
95 free(blob);
1527
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
96 }
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
97 fclose(f);
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
98 }
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
99 free(path);
1524
b96f9fae757f Fix Windows build, added Windows default_font_path implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
100 free(base);
1527
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
101 if (selected) {
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
102 printf("Found preferred font in %s\n", entries[i].name);
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
103 break;
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
104 }
1524
b96f9fae757f Fix Windows build, added Windows default_font_path implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
105 } else if (!strcasecmp(base, "tahoma")) {
b96f9fae757f Fix Windows build, added Windows default_font_path implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
106 tahoma = entries[i].name;
b96f9fae757f Fix Windows build, added Windows default_font_path implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
107 } else if (!strcasecmp(base, "arial")) {
b96f9fae757f Fix Windows build, added Windows default_font_path implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
108 arial = entries[i].name;
b96f9fae757f Fix Windows build, added Windows default_font_path implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
109 }
b96f9fae757f Fix Windows build, added Windows default_font_path implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
110 free(base);
b96f9fae757f Fix Windows build, added Windows default_font_path implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
111 }
1527
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
112 if (!selected) {
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
113 path = NULL;
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
114 if (tahoma) {
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
115 path = path_append(fonts, tahoma);
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
116 } else if (arial) {
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
117 path = path_append(fonts, arial);
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
118 }
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
119 if (path) {
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
120 FILE *f = fopen(path, "rb");
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
121 if (f)
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
122 {
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
123 long font_size = file_size(f);
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
124 uint8_t *blob = malloc(font_size);
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
125 if (font_size == fread(blob, 1, font_size, f))
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
126 {
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
127 sfnt_container *sfnt = load_sfnt(blob, font_size);
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
128 if (sfnt) {
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
129 selected = sfnt->tables;
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
130 } else {
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
131 free(blob);
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
132 }
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
133 }
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
134 fclose(f);
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
135 }
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
136 free(path);
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
137 }
1524
b96f9fae757f Fix Windows build, added Windows default_font_path implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
138 }
1594
137dbd05ceab Fix some issues identified by cppcheck
Michael Pavone <pavone@retrodev.com>
parents: 1547
diff changeset
139 free(pref_prefix);
1524
b96f9fae757f Fix Windows build, added Windows default_font_path implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
140 free(fonts);
b96f9fae757f Fix Windows build, added Windows default_font_path implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
141 free_dir_list(entries, num_entries);
1527
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
142 if (selected) {
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
143 return sfnt_flatten(selected, size_out);
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
144 }
4f6e8acd7b6a Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents: 1524
diff changeset
145 return NULL;
1524
b96f9fae757f Fix Windows build, added Windows default_font_path implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
146 }