comparison nuklear_ui/font.c @ 2483:48ab1e3e5df5

Fix Linux font selection regression
author Michael Pavone <pavone@retrodev.com>
date Sun, 31 Mar 2024 10:21:34 -0700
parents 369a52e302e2
children
comparison
equal deleted inserted replaced
2482:fb8f49b0aece 2483:48ab1e3e5df5
21 //TODO: specify language dynamically once BlastEm is localized 21 //TODO: specify language dynamically once BlastEm is localized
22 FILE *fc_pipe = popen("fc-match -s -f '%{file}\n' :lang=en", "r"); 22 FILE *fc_pipe = popen("fc-match -s -f '%{file}\n' :lang=en", "r");
23 if (!fc_pipe) { 23 if (!fc_pipe) {
24 return NULL; 24 return NULL;
25 } 25 }
26 size_t buf_size = 4096; 26 size_t buf_size = 2048;
27 char *buffer = NULL; 27 char *buffer = NULL;
28 size_t total = 0, read = 0; 28 size_t total = 0, read = 0;
29 do { 29 do {
30 total += read; 30 total += read;
31 buf_size *= 2; 31 buf_size *= 2;
32 buffer = realloc(buffer, buf_size); 32 buffer = realloc(buffer, buf_size);
33 if (!buffer) { 33 if (!buffer) {
34 return NULL; 34 return NULL;
35 } 35 }
36 read = fread(buffer, 1, buf_size - total, fc_pipe); 36 read = fread(buffer + total, 1, buf_size - total, fc_pipe);
37 } while (read == (buf_size - total)); 37 } while (read == (buf_size - total));
38 total += read; 38 total += read;
39 buffer[total] = 0; 39 buffer[total] = 0;
40 *num_out = 0; 40 *num_out = 0;
41 for (size_t i = 0; i < total; i++) 41 for (size_t i = 0; i < total; i++)