diff --git a/docs/CHANGES.txt b/docs/CHANGES.txt index 7a5e57749..3987011e4 100644 --- a/docs/CHANGES.txt +++ b/docs/CHANGES.txt @@ -34,11 +34,15 @@ https://tuxpaint.org/ + WIP Checking for fonts in any locations specified by "" entries found in system-wide and user-level FontConfig config files. This allows more fonts, and user-specific fonts, to be found & loaded. - - TODO - Looks in $FONTCONFIG_PATH/fonts.conf on macOS/iOS, - `/boot/system/settings/fonts/fonts.conf` on Haiku, otherwise - the Un*x-specific `/etc/fonts/fonts.conf` and - `~/.config/fontconfig/fonts.conf`. Should look in the correct - places on other platforms. + - It looks for: + - FIXME: (Windows) + - `./etc/fonts/fonts.conf` (ships with Tux Paint) (Windows) + - `$FONTCONFIG_PATH/fonts.conf` (macOS/iOS, Linux/Unix) + - or `/etc/fonts/fonts.conf` (Linux/Unix) + - `$XDG_CONFIG_HOME/fontconfig/fonts.conf` (Linux/Unix) + - or `$HOME/.config/fontconfig/fonts.conf` + - `/boot/system/settings/fonts/fonts.conf` (Haiku) + - FIXME: ??? (ships with Tux Paint) (macOS) - Note: This adds a build dependency on `libxml-2.0`. Bill Kendrick h/t Mark Kim & Luc Schrijvers diff --git a/src/fonts.c b/src/fonts.c index 53790b62e..ab6352907 100644 --- a/src/fonts.c +++ b/src/fonts.c @@ -1103,24 +1103,34 @@ char * * malloc_fontconfig_config_paths(int num_to_malloc, int * num_actually_ma /* See what dirs fontconfig configuration files point to, and try loading fonts from those locations */ - /* FIXME: We do not currently understand "" -bjk 2025.02.22 */ - #if defined(__APPLE__) - /* Apple: Look for fonts.conf in $FONTCONFIG_PATH */ fontconfig_config_paths = malloc_fontconfig_config_paths(1, &num_fontconfig_config_paths); if (fontconfig_config_paths != NULL) { + /* Apple: Look for fonts.conf in $FONTCONFIG_PATH */ fontconfig_config_paths[0] = malloc(1024); snprintf(fontconfig_config_paths[0], 1024, "%s/fonts.conf", getenv("FONTCONFIG_PATH")); + + /* FIXME: Apple: Look for the fonts.conf that we ship with Tux Paint for macOS */ } #elif defined(__HAIKU__) - /* Haiku: Look for fonts.conf in a known system directory */ fontconfig_config_paths = malloc_fontconfig_config_paths(1, &num_fontconfig_config_paths); if (fontconfig_config_paths != NULL) { + /* Haiku: Look for fonts.conf in a known system directory */ fontconfig_config_paths[0] = malloc(1024); snprintf(fontconfig_config_paths[0], 1024, "/boot/system/settings/fonts/fonts.conf"); } +#elif defined(WIN32) + fontconfig_config_paths = malloc_fontconfig_config_paths(1 /* FIXME */, &num_fontconfig_config_paths); + if (fontconfig_config_paths != NULL) + { + /* FIXME: Windows: Look for fonts.conf ??? in some system directory/ies ??? */ + + /* Windows: Look for the fonts.conf that we ship with Tux Paint for Windows */ + fontconfig_config_paths[0 /* FIXME */] = malloc(1024); + snprintf(fontconfig_config_paths[0 /* FIXME */], 1024, "etc/fonts/fonts.conf"); + } #else /* Others [e.g. Linux]: Look for fonts.conf in $FONTCONFIG_PATH (fallback to "/etc/fonts") and $XDG_CONFIG_HOME (fallback to "$HOME/.config") */ @@ -1167,7 +1177,7 @@ char * * malloc_fontconfig_config_paths(int num_to_malloc, int * num_actually_ma if (config_home != NULL) { fontconfig_config_paths[1] = malloc(1024); - snprintf(fontconfig_config_paths[1], 1024, "%s/.config/fontconfig/fonts.conf", config_home); + snprintf(fontconfig_config_paths[1], 1024, "%s/fontconfig/fonts.conf", config_home); free(config_home); } else @@ -1215,6 +1225,15 @@ char * * malloc_fontconfig_config_paths(int num_to_malloc, int * num_actually_ma xmlChar * path; char * path_str; + /* FIXME: We do not currently understand "" -bjk 2025.02.22 + (prefix may be one of "cwd"/"default", "xdg", or "relative"; + see https://www.freedesktop.org/software/fontconfig/fontconfig-user.html */ + + /* Note: As we already look for both system and user fonts on Windows, + we'll just ignore "WINDOWSUSERFONTDIR" and "WINDOWSFONTDIR" magic paths; + also ignoring "APPSHAREFONTDIR" and "CUSTOMFONTDIR". + See https://gitlab.freedesktop.org/fontconfig/fontconfig/-/blob/main/src/fcxml.c */ + path = xmlNodeGetContent(cur); if (path != NULL)