kas-gui / kas-text

Rich text processing
Apache License 2.0
58 stars 2 forks source link

Selecting fonts and fallbacks #53

Open dhardy opened 3 years ago

dhardy commented 3 years ago

Since #46 we use fontdb by @RazrFalcon plus some hacky lists of preferred family names to select fonts. This vaguely works but has several issues:

  1. It probably requires tweaking to work acceptably on all systems
  2. It ignores system/user preferences
  3. It loads more fonts than necessary at start-up. This could be fixed with lazy-loading, but that wouldn't help much given the current fallback mechanism.
  4. The "missing glyph" fallback mechanism simply checks each loaded font in order (ttf_parser::Face::glyph_index), for each missing glyph. This now has caching but is still slow with multiple fallback fonts.
  5. It misses many fonts required for various (especially CJK) scripts. While we could simply add more fonts to the standard lists (or even replace them with some globbing rules), this would compound with (3) and (4) causing performance issues for any glyph not in the first (few) fonts and potentially also at start-up (more an issue when using fontdue).

Some significant changes are needed, at least to the way we choose fallback fonts and likely also to the way fonts are selected. This could either be via closer integration with system libraries or via closer adherence to CSS font selection (using the effective character map, and ... CSS recommends using the "system font fallback" mechanism as the next step).

Also relevant: rust-fontconfig by @fschutt.

fschutt commented 3 years ago

Use fontdb, rust-fontconfig will be in alpha stage for a long time

yisibl commented 2 years ago

Have a look at https://github.com/alibaba/font-toolkit, we plan to implement a better font fallback.