Sigh, I wasted* hours hacking on #fontconfig, trying to make it be a better Windows citizen, and it is just horrible.

Apparently it was written back in the last years of the 1900s in what was supposed to be a very "portable" fashion, where "portability" then meant "run on any random hardware and Unix-like OS/environment with ancient C compilers that possibly could run the X Window System", and it has not been cleaned up since then.

For instance, what is the point with using this FcChar8 type, a typedef for unsigned char, and thus having to cast back and forth to char all the time whenever calling C library functions? What's wrong with using plain char?

(Sure, char might be signed or unsigned, but when manipulating strings that seldom matters. For actual arithmetics on chars, in those few code snippets where that is done, it could then use casts to unsigned char. Using FcChar8 all over the place is just bonkers.)

The Windows portability bits, at least partially written by my younger self over 20 years ago, use only "narrow" character APIs for pathname related APIs, which by now is deeply troubling.

Windows NT is the only type of Windows that remains. (Windows 2000 → XP → Vista → 7 → 8 → 10 → 11). Its file systems use UTF-16 for names, and to be able to access all files and folders one needs to use wide character APIs. Like _wopen() instead of open(), and FindFirstFileExW() instead of FindFirstFileEx().

Should I even bother trying to upstream improvements, or just do the bare minimum to make it work properly in non-ASCII situations in the new Collabora Office? Upstreaming fixes cleanly and properly will take a lot of time. Not interested enough to spend much own time on this, more than I already did.

The principle in a fontconfig cleanup for file names on Windows should be: Keep using plain narrow char strings, as for Unix, to avoid massive changes all over it, but assume/ensure they are in UTF-8 on Windows, and convert to/from UTF-16 only right before/after calling C library or Win32 APIs that take/return pathnames.

I wonder how much FLOSS software nowadays uses fontconfig on Windows? Probably more than I think. Which means a potential upstreaming of Windows-related improvements must be careful not to break such use.

*) Not actually ”wasted”, any investigation and experimentation where you learn things is useful.

fontconfigのこの問題は、いつまで放置するんだろうね。16年も放置されたままというのは、やっぱり異常だよ #linux #fontconfig

65-nonlatin should be updated for CJK fonts (\#53) · Issue · fontconfig/fontconfig: https://gitlab.freedesktop.org/fontconfig/fontconfig/-/issues/53

65-nonlatin should be updated for CJK fonts (#53) · Issues · fontconfig / fontconfig · GitLab

Submitted by Qianqian Fang Assigned to [email protected] Link to original bug...

GitLab

Debian SidにFirefox 143が降りてきたのでNoto color emojiフォントが表示されない問題を確認した

結論としては、143で不具合は直っているけどfontconfigの設定も確認しろ、です

というのもパッケージをアップグレードしただけでは、表示は変わりません。相変わらず絵文字は見えないままです。ここでfontconfigの設定(`/etc/fonts/local.conf`や`~/.config/fontconfig/fonts.conf`)を見て、ビットマップフォントを無効にする`embeddedbitmap`の設定があるか確認してください。あれば削除しましょう

ということでFirefox 142のときは、fontconfigに関係なくNoto color emojiが表示されなかったけれど、143では不具合は直りました。しかし、fontconfigの設定で見えないから注意しろというのが結論ということでした

#linux #firefox #emoji #fontconfig

I have managed to break my #Linux system, because I used Font Manager to deactivate most of the pre-installed #fonts. I despise font cruft.

BUT, that means that the configuration files for the #fontconfig subsystem are not referencing any of the fonts I actually have installed and activated, so when I installed Font Awesome 6 for a particular #Conky config I downloaded, other applications started using Font Awesome as their default font for sans-serif.

#OpenBSD now runs fd.o #fontconfig fc-cache(1) utility as an unprivileged '_fc-cache' user, dropping root privileges at both build time & at runtime (pkg_add). 

bentley@ modified src/*: Change ownership of fontconfig cache to _fc-cache user.

ok kn@ deraadt@

bentley@ modified usr.sbin/pkg_add/OpenBSD/PackingElement.pm: When installing fonts, run fc-cache as the unprivileged _fc-cache user.

From espie; ok deraadt@

bentley@ modified xenocara/*: Don't perform font caching as root.

During build, run fc-cache as BUILDUSER.

When fc-cache is run as root, drop automatically to the _fc-cache user so /var/cache/fontconfig doesn't acquire root-owned files.

ok deraadt@

This nicely improves upon Anthony J. Bentley previous effort back in May, adding pledge(2) to fc-cache(1). 

bentley@ modified xenocara/dist/fontconfig/fc-cache/fc-cache.c: Call pledge(2) in fc-cache(1): "stdio rpath wpath cpath flock".

ok deraadt

LibreOffice Writerでフォントを見てたらfontconfigがバグっててフォント名が文字化けしてた。trixieまでに直ってくれたらいいけど #debian #fontconfig #libreoffice
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1098401
#1098401 - fontconfig: Japanese font names are garbled. The font cannot be used - Debian Bug report logs

chromium 的 skia 不能识别 sans-serif 能识别 sans 的原因找到了,其内部只认为 sans/serif/monospace 是需要 fallback 的,sans-serif 不是。基于这种假设,sans-serif 会应用其一般字体判断逻辑,即 #fontconfig 初始化后返回的第一个 sans-serif 和经过 fc-match -a 后的第一个 sans-serif 两者比较名称是否相同。但是 fc-match -a 有一个作用是把不存在于系统的字体剔除,如果是一般字体比如 Roboto 完全没有问题,初始化的 pattern 它肯定排第一个,因为没有规则对这种具体字体做 prepend 操作,这种比较实际上等于查找它在不在。但 sans-serif 不一样,存在的第一个字体绝大多数时候都不等于 pattern 的第一个字体。能 work 是因为到了 sans 这种 fallback 字体就不进行名称相同比较了。但这样效率只有 50%,因为所有写了 sans-serif 的网页都要做一次理论无效实际也无效的比较
越来越清晰了,继编译了 chromium 的魔改 content_shell 后,又制作了魔改版的 skia_debug_tool,已经能深入到 chromium 怎么调用 #fontconfig 了,博客再写下去能发 sci 了吧…回到前面的问题:日志里 times new roman 多是因为 chromium linux 默认的 standard font family 是它;sans-serif 不好使是因为在 matchFamilyName 环节用 zh_CN 的 namelang 匹配到了 Noto Sans。感觉这像是我自己的锅,因为 openSUSE 有个 config 是按照 Google 官方的 Noto Sans CJK 使用建议给中文前 prepend Source Sans 还是 Roboto 来着,印象里好像当时 prepend 的是 Noto Sans。然后 sans 好像 fontconfig 官方是 append 的 sans-serif,导致两者结果不一致。
魔改版的 chromium content_shell 已经做完了,发现几个比较有意思的问题:1. Chromium 每次不管加载什么网页都会先找 Times New Roman 2. 我曾经以为网页 css 写的 sans-serif 替换会发生在 Skia/fontconfig 里,其实不是,是 sans-serif 也找不到字体,blink 自动加入了 Sans,用 sans 在 Skia/fontconfig 里找到的中文字体。具体研究需要进一步制作魔改 plus 版 content_shell。#fontconfig
Because KDE and essentially anything non-gnome supports it, I've enabled subpixel rendering again. I also use the truetype engine v35 and no font hinting. #KDE #nixOS #fontconfig #freetype