Download missing fonts at runtime
Continuation of Fontconfig work started on #8.
Android devices have some fonts installed. List varies.
PDF expects a list of 14 fonts:
- Monospace: Courier, Courier Bold, Courier Oblique, Courier Bold-Oblique
- Sans-Serif: Helvetica, Helvetica Bold, Helvetica Oblique, Helvetica Bold-Oblique
- Serif: Times Roman, Times Bold, Times Italic, Times Bold-Italic
- Symbol
- Zapf Dingbats
Symbol and Zapf Dingbats were not found on tested devices, but they are quite small (both totalling under 100kb), so were included in this library in commit 8dd1207ee7600cf184ebb20220bb4ce5b2e5c53d
Most fonts have (metrically compatible ??) replacement fonts available on the device. Keyword being "most", Courier (monospace) only has base verson, but not bold or oblique (italic ??).
TODO:
- [ ] At app runtime go through the base14 font list and check if font provided by Fontconfig has the right properties: serif, sans-serif, monospace, bold, italic
- [ ] Research if this check can be done by querying Fontconfig functions or another alternative needed.
- [ ] Already linking against libFontforge, can use it to visually measure how wide the letters are to determine if font is monospace. https://stackoverflow.com/questions/34511603/check-whether-a-font-is-monospaced
- [ ] Research if "Android font download" infrastructure can provide actual .ttf/.otf whatever else files or is it only Java/Kotlin objects that are not available for C++ apps.
- [ ] If "Android font download" is unusable - download from fonts.google.com.
- [ ] Generate fontconfig rule for newly downloaded font.
Is this something we should log and get fixed upstream?
I doubt it. If you lack fonts on your desktop, it means your desktop is broken and you as the end user can fix it: install fonts package, adjust settings, et cetera. Android end users have no such options. Device gets shipped with some fonts and if the app wants to use different fonts it has to either bundle them with the app or download them at runtime.