comparison nuklear_ui/font_win.c @ 1524:b96f9fae757f nuklear_ui

Fix Windows build, added Windows default_font_path implementation
author Michael Pavone <pavone@retrodev.com>
date Wed, 07 Feb 2018 00:07:12 -0800
parents
children 4f6e8acd7b6a
comparison
equal deleted inserted replaced
1523:c416ace65ff1 1524:b96f9fae757f
1 #include <windows.h>
2 #include <shlobj.h>
3 #include "../paths.h"
4 #include "../util.h"
5
6 char *default_font_path(void)
7 {
8 NONCLIENTMETRICSA metrics = {
9 .cbSize = sizeof(metrics)
10 };
11 char *pref_name = NULL;
12 if (SystemParametersInfoA(SPI_GETNONCLIENTMETRICS, sizeof(metrics), &metrics, 0)) {
13 pref_name = metrics.lfCaptionFont.lfFaceName;
14 }
15 char windows[MAX_PATH];
16 SHGetFolderPathA(NULL, CSIDL_WINDOWS, NULL, 0, windows);
17 char *fonts = path_append(windows, "Fonts");
18 size_t num_entries;
19 char *preferred = NULL, *tahoma = NULL, *arial = NULL;
20 dir_entry *entries = get_dir_list(fonts, &num_entries);
21 for (size_t i = 0; i < num_entries; i++)
22 {
23 if (entries[i].is_dir) {
24 continue;
25 }
26 char *ext = path_extension(entries[i].name);
27 if (!ext || strcasecmp(ext, "ttf")) {
28 //not a truetype font, ignore
29 free(ext);
30 continue;
31 }
32 free(ext);
33 char *base = basename_no_extension(entries[i].name);
34 if (!strcasecmp(base, pref_name)) {
35 preferred = entries[i].name;
36 free(base);
37 break;
38 } else if (!strcasecmp(base, "tahoma")) {
39 tahoma = entries[i].name;
40 } else if (!strcasecmp(base, "arial")) {
41 arial = entries[i].name;
42 }
43 free(base);
44 }
45 char *path = NULL;
46 if (preferred) {
47 path = path_append(fonts, preferred);
48 } else if(tahoma) {
49 path = path_append(fonts, tahoma);
50 } else if(arial) {
51 path = path_append(fonts, arial);
52 }
53 free(fonts);
54 free_dir_list(entries, num_entries);
55 return path;
56 }