Font fallback #
What the paragraph engine does with text the fonts it was given have no glyph for, and what the platform contributes.
Two kinds of fallback #
Parley shapes each run with the first font of its font-family list
that has the run's characters, and past the list with fontique's
fallbacks for the run's script: on macOS, the one family CoreText names
for a sample of that script, found once per script and locale. That
covers a script's own letters, such as Han for Chinese text in a Latin
font, and nothing else: a symbol such as ⌘ or ☐ has no script of its
own, shapes in the run around it, and draws as a missing glyph when
neither the list nor the script's fallback has it.
A browser asks the platform about each character it cannot draw
instead, and takes any installed font. The engine does the same, on top
of fontique: after shaping a segment it looks for clusters that shaped
to the missing glyph, asks the platform's font matching
(native::FontFallback, one implementation per platform under
crates/native/src/platform/) which installed family would draw each,
and appends that family to the fallbacks of the cluster's script, after
the ones fontique found. The segment then shapes again. The family stays
in the script's fallbacks, so every later paragraph with the same text
in the same script shapes with it at once.
What the engine asks, and when #
- Only clusters with a missing glyph, never whitespace or control characters, which have none to draw.
- Each text once: a text the platform names no family for, or a family the font collection does not list, is remembered and not asked again.
- A text no installed font has gets no family: CoreText draws it with its last-resort font, which maps every character to a placeholder for its block, so learned as a fallback it would take every later character of the script.
- The script is the one Parley chose fallbacks by: the script of the last character before the cluster in its segment that has one, else the segment's first, else Latin. Parley carries a script across changes of style, so a sign styled apart from the text before it still takes that text's script. A sign after Chinese text joins the Han fallbacks, one after Latin text the Latin fallbacks.
- A learned family comes after the script's own fallback, so Chinese text keeps its Chinese font even when a symbol font learned for a sign happens to have some of its characters.
- Learning a family counts as a font change: every cached paragraph
shapes again when next used, as after
register_font. So does giving the engine the platform's matching, which the application host does at startup; paragraphs shaped before it draw their glyphs afterwards.
The host test utility gives the engine no platform matching, so a test
that needs one sets native::test::MemoryFontFallback on the engine
with the family to answer for a character, and reads back what it was
asked. The fixture testdata/fonts/NotoSansSymbols2-Subset.ttf holds
the few glyphs Noto Sans lacks that those tests use.