updater
updater copied to clipboard
Update Roboto font, add NotoSansSymbols, compress them
Update Roboto font, add NotoSansSymbols, compress them.
Fixes:
- https://github.com/Unvanquished/updater/issues/162
Doesn't fix:
QFontDatabase: Cannot find font directory /qt/lib/fonts.
Note that Qt no longer ships fonts. Deploy some (from https://dejavu-fonts.github.io/ for example) or switch to fontconfig.
This also compress fonts to save space, basically the two fonts now take the size of one.
How it looks:
The Qt resource system is supposed to support compression by default according to https://doc.qt.io/qt-6/resources.html. But it says compression will not be used if it does not hit some desired compression ratio, which can be configured in rcc flags. In CMake I believe those flags could be added by https://cmake.org/cmake/help/latest/prop_tgt/AUTORCC_OPTIONS.html.
I'll try to push my Qt6 branch soon if you want to try out any of these file size tricks against it.
The Qt resource system is supposed to support compression by default according to https://doc.qt.io/qt-6/resources.html.
Good to know! Doing some measurements I confirm the size of the resulting binary would be way much larger if it didn't do some compression, because by default it doesn't save that much to compress before hand, using a generic compression tool like gzip.
What's interesting in compressing beforehand is that we can use much slower compressors that are too slow for their usage to be viable at build time, and such compressors can produce better results than the default Qt zlib profile.
Here is some comparison, I don't expect Qt to do better than gzip when Qt uses zlib:
| file | ttf | gzip | zopfli |
|---|---|---|---|
| NotoSansSymbols-Regular.ttf | 184K | 92K | 88K |
| Roboto-Regular.ttf | 144K | 84K | 80K |
| total | 328K | 176K | 168K |
The win isn't big, but it adds up when we accumulate more file optimizations:
| file | no trick | ttf.gz | zopfli ttf.gz | zopfli ttf.gz + zopfli png |
|---|---|---|---|---|
| updater | 33076K | 32924K | 32916K | 32620K |
Here combining the optimized ttf.gz trick with optimized png saves 456K, close to half a MB!
I read in that page that Qt6 can support zstd as compression format. We may investigate that because I expect zstd to perform better than a bruteforced gzip, while being usable at build time, and not needing any custom decompression code. Of course linking against zstd would increase the executable file size, but the tradeoff may be welcome.
Maybe we should just enable Qt's fontconfig option and try to take advantage of system fonts? That would probably be better for reducing binary size. Besides the arrow symbol, we can also benefit from emoji fonts since there are several news posts that use emojis. (Or if we don't care about emojis, let's nuke Harfbuzz and save a megabyte :stuck_out_tongue: )
If the AI can be believed, fontconfig should work for most users:
Which Linux distros use fontconfig? What is the configuration path for each one?
I can answer this from my knowledge without needing to search.
Nearly all mainstream Linux distributions use fontconfig for font configuration and management. It's a fundamental component of the Linux graphics stack.
Common distributions using fontconfig:
Ubuntu/Debian family - Configuration path: /etc/fonts/
Fedora/RHEL/CentOS - Configuration path: /etc/fonts/
Arch Linux - Configuration path: /etc/fonts/
openSUSE - Configuration path: /etc/fonts/
Gentoo - Configuration path: /etc/fonts/
Alpine Linux - Configuration path: /etc/fonts/
Void Linux - Configuration path: /etc/fonts/
Mint - Configuration path: /etc/fonts/
Pop!_OS - Configuration path: /etc/fonts/
Manjaro - Configuration path: /etc/fonts/
Configuration structure:
The fontconfig system uses a consistent configuration structure across distributions. The main configuration file is /etc/fonts/fonts.conf, with additional configuration in /etc/fonts/conf.d/. User-specific overrides can be placed in ~/.config/fontconfig/ or ~/.fonts.conf.d/.
The standardization of /etc/fonts/ is thanks to the Filesystem Hierarchy Standard (FHS) and fontconfig's cross-distribution design. Essentially, if a Linux distribution has a graphical environment (X11 or Wayland), it almost certainly uses fontconfig with this standard path.
The only distributions that might not use fontconfig would be extremely minimal or specialized systems that don't include graphical capabilities, or very old distributions from before fontconfig became the standard (pre-2002).
I would like to get fontconfig support yes. I already had to modify some of my news blog post to not put an emoji in the first sentences to get them looking good in the updater, that's annoying.
Adding one font just for one symbol is a bit annoying, though I think all the characters we display (that we don't fetch from a blog post) should display by default. We can also rethink what symbols we display by default.
In my qt6-more branch I have a commit implementing the pre-compressed ttf trick too compress them beforehand (using zopfli) better than Qt can do at build time with common zlib.
When doing the trick on our current font (only our old Roboto font that is smaller than the one in this branch), for some unknown reasons it only benefits the zip, not the updater itself:
Before:
28912856 updater
11691726 UnvUpdaterLinux.zip
After:
28912856 updater
11688196 UnvUpdaterLinux.zip
Basically 3K and only in the zip. Those 3K is the size earned by an heavy zopfli compared to gzip -9
55191 Roboto-Regular.ttf.gz (zopfli)
58991 Roboto-Regular.ttf.gz (gzip)
I would like to know where those 3K are spent in the updater!?