PangoCairo fontmap takes a while to update
There seems to be a bug when loading new font files in runtime.
The bug can be reproduced with the following steps (or just run font.py):
- (Make sure the font directory is empty)
- Download a new font and save it to the disk (to the empty font directory where fontconfig can find it)
rc-listwith the subprocess package to verify that the new font is recognized
PangoCairo.font_map_get_default().list_families()to get the font families
- Repeat step 2-4 for another font file
When you follow these steps, PangoCairo fontmap should't contain the second font. Meanwhile, fontconfig is already up-to-date.
There are a couple of things that seem to stand out:
- Sometimes the fonts are loaded correctly, however most of the times they are not
- When this code is run inside a werkzeug WSGI webserver, with the PangoCairo objects kept in memory between multiple runs, the fonts appear in the fontmap after a while
- When the new font is not loaded correctly, fontconfig does not show debug output. However, when the new font does load succesfully, fontconfig displays debug output.
- Ubuntu 18.04 (in a docker container)
- Python 3.6
- The Pango and CairoPango libs that are used from Python with gObject introspection (using the
- (Cairo is used as well, from the
- We use a custom fontconfig configuration. Only fonts from specified directories are loaded (system fonts are discarded).
- Set the FC_DEBUG environment variable to
9to know when fontconfig is used
$ dpkg --list | grep pango ii gir1.2-pango-1 1.40.14-1ubu amd64 Layout and rendering of internati ii libpango-1.0-0 1.40.14-1ubu amd64 Layout and rendering of internati ii libpango1.0-0: 1.40.14-1ubu amd64 Layout and rendering of internati ii libpangocairo- 1.40.14-1ubu amd64 Layout and rendering of internati ii libpangoft2-1. 1.40.14-1ubu amd64 Layout and rendering of internati ii libpangomm-1.4 2.40.1-4 amd64 C++ Wrapper for pango (shared lib ii libpangox-1.0- 0.0.2-5 amd64 pango library X backend ii libpangoxft-1. 1.40.14-1ubu amd64 Layout and rendering of internati
$ dpkg --list | grep gobject ii libcairo-gobject2:amd64 1.15.10-2ubuntu0.1 amd64 Cairo 2D vector graphics library (GObject library) ii libharfbuzz-gobject0:amd64 1.7.2-1ubuntu1 amd64 OpenType text shaping engine ICU backend (GObject library) ii python3-gi 3.26.1-2ubuntu1 amd64 Python 3 bindings for gobject-introspection libraries