Load fallback fonts on demand - #155
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_mapcovers all charscwhich 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.)