Skip to content

Load fallback fonts on demand - #155

Merged
dhardy merged 9 commits into
masterfrom
push-msusxnztkpnu
Aug 26, 2026
Merged

Load fallback fonts on demand#155
dhardy merged 9 commits into
masterfrom
push-msusxnztkpnu

Conversation

@dhardy

@dhardy dhardy commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

A Fontique Query is designed to run until sufficient matching fonts have been found. Previously we simply ran the query exhaustively, compiling a full list of fallbacks for every font selection, resulting in a lot of font loading up front. Lazily loading fonts from the query result internally would not have helped here since Fontique already loads each font into memory before returning the query result.

This PR stops the query early once all chars from the text have been matched to a glyph. There is a small cost to this: each font selection must now ensure all glyphs in the text are covered and if not re-run the query. As a side-effect, we can now assume our Font::glyph_map covers all chars c which are used and covered by a font face.

Far fewer fonts get loaded now, though still significantly more than the minimal set required: when a fallback font is required, the query runs until a suitable font is found, loading each font it tries in order. (This is not something that can be addressed here. It may be that Fontique's queries should return results in a different order or omit more fonts, but not necessarily — there may not be a better way to find a font covering a specific character.)

@dhardy
dhardy merged commit d7a40e8 into master Aug 26, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant