Search code examples
windowsunicodefontsinternationalizationpango

Pango/Cairo/Fontconfig: Making unicode font fallback/linking work properly in Windows


Recently, a windows user made us aware that Japanese (and other unicode) characters in our app don't display properly under Windows. He just gets boxes with numbers instead.

We're using Pango, Fontconfig/freetype and rendering with Cairo. In Unix (that is, both Linux and macOS) it works perfectly. However, under Windows we just can't seem to get it to work.

I imagine it has to do with how font fallback/linking works under Windows, but I have no idea even where to begin looking into making this work properly.


Solution

  • Turns out the issue is simpler than expected, but not very well documented anywhere. Fontconfig needs its config files (fonts.conf and the secondary configs found under conf.d). In linux it's never an issue because most (if not all) distros use fontconfig by default so even if one botches it, there's still a system config to fall back on.

    By contrast, windows doesn't normally use fontconfig, so unless devs ship out a set of fontconfig configuration files, it will at most load the specified fonts but it won't be able to do anything else (like font fallback).

    The solution to this is to ship out a "fonts" folder containing at least fonts.conf and also any appropriate definitions from conf.d, usually the folder should be in the same folder as the fontconfig library. (and if that doesn't work you can set FONTCONFIG_PATH to ".")

    Finally, unless you actually made any special changes to the config, you can just copy the default config files from /etc/ to ship out with your app.