Re: [Tuxpaint-devel] Windows & Android (& others?) FontConfig `fonts.conf` parsing
An award-winning drawing program for children of all ages
Brought to you by:
wkendrick
From: Bill K. <nb...@so...> - 2025-02-22 10:29:47
|
On Sat, Feb 22, 2025 at 04:10:46PM +0900, Shin-ichi TOYAMA wrote: > Hi! > > I had made it to load fonts stored in user's font directory on Windows. > > See commit 365ee3ea20af489996e045f97ae2d874e43f5591 > > Then I think there is no more thing to be added so far. What I'm hoping for is a location (or locations) on Windows to read FontConfig configuration file(s) -- "fonts.conf" -- which might contain some <dir>...</dir> clauses that point to other places to find fonts. (Tux Paint then proceeds to pass each path along to `loadfonts()`.) For example, on my Linux system, Tux Paint will look for fonts in three locations, based on two configuration files (user and system): $ grep "<dir>" ~/.config/fontconfig/fonts.conf /etc/fonts/fonts.conf /home/kendrick/.config/fontconfig/fonts.conf: <dir>~/.fonts</dir> /etc/fonts/fonts.conf: <dir>/usr/share/fonts</dir> /etc/fonts/fonts.conf: <dir>/usr/local/share/fonts</dir> /etc/fonts/fonts.conf: <dir>~/.fonts</dir> I actually just went in and updated `load_user_fonts()` to utilize some environment variables, if set, in the 'default' block of code that's used by Linux (and anything else not __APPLE__ or __HAIKU__). Specifically, * Don't assume `/etc/fonts/fonts.conf`, but use $FONTCONFIG_PATH if set. * Don't assume `$HOME/.config/fonts.conf`, but use $XDG_CONFIG_HOME if set. As a reminder, now that Tux Paint explicitly looks for and loads fonts found in the "<dir>" paths that my `fonts.conf` files point to, I am now able to use a lot more fonts in Tux Paint than I could before; things I'm used to seeing in other apps (Gimp, Inkscape, LibreOffice). So to summarize my question for you -- is there a location (or set of locations) -- where one would expect to find FontConfig "fonts.conf" files on Windows? Interestingly, when I search Google for the question "where is fontconfig fonts.conf on windows", it's AI Overview states: On Windows, there is no "fonts.conf" file in the traditional sense of Fontconfig, as Windows manages fonts through its own system, and does not utilize the Fontconfig framework; therefore, you won't find a "fonts.conf" file on a Windows system; all fonts are typically stored in the "C:\Windows\Fonts" directory. HOWEVER, I cannot determine how it came to this conclusion, so I don't trust this answer. It may be a hallucination. >:-( Tux Paint actually SHIPS with its own "fonts.conf" file for Windows [*], which includes these <dir> paths: <dir prefix="cwd">data/fonts/locale</dir> <dir prefix="cwd">data/fonts</dir> <dir>WINDOWSFONTDIR</dir> <dir>WINDOWSUSERFONTDIR</dir> <dir prefix="xdg">fonts</dir> <dir>~/.fonts</dir> Those "WINDOWSFONTDIR" and "WINDOWSUSERFONTDIR" values seem to be magic strings used by FontConfig; see: https://gitlab.freedesktop.org/fontconfig/fontconfig/-/blob/main/src/fcxml.c#L1330 I think at the very least, one place the Windows version of Tux Paint should look for "fonts.conf" is own one that ships with Tux Paint: `etc/fonts/fonts.conf` (inside Tux Paint). If we were to mimick the behavior of FontConfig itself when those two "WINDOWS...FONTDIR" values are seen, I think that might actually remove the need for your user font dir scanning code (added in `365ee3ea20af489996e045f97ae2d874e43f5591`). Wouldn't it? I think I might drop some FIXME's in there, and I'd appreciate if you could try implementing and testing. :) Expect more commits in a few minutes. Then, as usual, I REALLY need to get to bed. :-D -bill! [*] We also ship a "fonts.conf" inside the macOS build. Comments in tuxpaint.c explain: /* Pango uses Fontconfig which requires fonts.conf. By default, Fontconfig * searches for this file in a global path (e.g., /opt/local/etc/fonts if * using the MacPorts port of Fontconfig) which does not exist on a vanilla * macOS install. As a workaround, the macOS port of Tux Paint provides its * own copy, and tells Fontconfig to look inside the Tux Paint app bundle for * this file by setting the FONTCONFIG_PATH environment variable here. > > Thanks > > On Sun, 16 Feb 2025 12:57:15 -0800, Bill Kendrick wrote: > > > >I've been quite busy lately, and was just trying to remind myself > >what's up in the in-progress 0.9.35 version of Tux Paint. > > > >In CHANGES.txt I spotted this entry: > > > > + WIP Checking for fonts in any locations specified by "<dir>" > > 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. > > - Note: This adds a build dependency on `libxml-2.0`. > > > >Pere and Shin-ichi, I'm sure I asked already, but can you let me know > >what else, if anything, we should add so that Tux Paint can find a user's > >`fonts.conf` (FontConfig XML configuration file) so the Android & Windows > >builds of Tux Paint can also take advantage of this new capability...? > > > >And of course if anyone else out here has suggestions for more OS-specific > >paths that we should look at, please speak up! > > > >Thanks in advance! > > > >-bill! > > > >PS - As a reminder, the _other_ things coming in 0.9.35 (so far) are: > > > > * "emitter" (heart, stars, sparkles) magic tools > > * text pasting (copy/paste buffer) in Text & Label tools > > * UX improvement to HSV color picker > > * minor doc improvements > > * some build improvements (NetBSD, Slackware) > > * less noise to STDOUT > > > > > > > >_______________________________________________ > >Tuxpaint-devel mailing list > >Tux...@li... > >https://lists.sourceforge.net/lists/listinfo/tuxpaint-devel > > > -- > Shin-ichi TOYAMA <dol...@wm...> > |