JFLib

text/fallback.rs#

Source: lib/text/fallback.rs

fallback -- characters a font lacks, drawn with another font (font fallback)

  set_fallback_fonts(ids)        (shaping.rs) the app's own chain, tried first; shaping uses
                                 it as well
  set_system_fallback(on)        then system fonts: the families of FAMILIES (this OS's
                                 list: Windows, macOS / iOS, Linux and the rest, Android;
                                 after the ';' separated families of jfgui_FALLBACK_FONTS
                                 and, where the system has a fonts.xml (Android), its
                                 families in its order: FontConf::sys_families, their
                                 files found in the FontDb), found with a FontDb of the font
                                 folders (scanned on the first missing character; its cache
                                 is cache://fontdb.fdb, not with jfgui_FONTDIRS) and loaded
                                 when first needed
  set_fallback_lang(tag)         the UI language: its fonts (FontConf::lang_families, after
                                 jfgui_FALLBACK_FONTS) come before FAMILIES, so Han
                                 characters take the language's forms (ja, zh-Hans, zh-Hant,
                                 ko) and scripts their usual font
  system_fallback() -> bool
  fallback_for(cp) -> Option<font id>   the first font of the chain that has cp (remembered
                                 per code point, also when none has it)
  fallback_active() -> bool      a chain is set (run / shaping only look for fallbacks then)

Characters that fonts lack on purpose (controls, zero-width spaces and joiners, bidi marks,
variation selectors, tags) never fall back.  Fallback glyphs share the baseline and the
pixel size of the run; ascent, descent and line height stay the first font's.

impl Text

  • fn set_system_fallback(&mut self, on: bool) look for missing characters in system fonts too (after set_fallback_fonts' chain)
  • fn set_fallback_lang(&mut self, tag: &str) the language whose fonts the system fallback tries first ("" none)
  • fn system_fallback(&self) -> bool whether system fonts are searched for missing characters
  • fn fallback_active(&self) -> bool whether run / shaping look for fallback fonts at all
  • fn fallback_for(&mut self, cp: u32) -> Option<u32> the first font of the fallback chain that has cp (None: none has it)

Source: docs/API.md in the JFLib repository.