[fontscan] Better family substitutions #105
Merged
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.
This PR alters the way we perform family substitutions when looking for a fallback font, by applying them to the whole family list of the user query, so that substitution priorities are better respected.
Let me illustrate the change on the following example, where an user queries
{CustomWeirdFont, Helvetica}
, on a system with neitherCustomWeirdFont
norHelvetica
, and callsResolveFace('a')
Before the change
No exact match occurs (step 1), so we apply substitutions (step 2).
CustomWeirdFont
is unknown from the library rules, so it is expanded by default tosans-serif
for which the system has (many) fonts (with support for the rune 'a'). SoResolveFace
returns the 'preferred'sans-serif
face. It has not take into account theHelvetica
substitutions.After the change
We still look for an exact match, in the user query order. Like before, no one occurs. We now apply substitutions on the whole
{CustomWeirdFont, Helvetica}
list. Since the library has rules forHelvetica
, the expanded families will look like{CustomWeirdFont, Helvetica, NimbusSans, ..., other sans-serif families}
, with the main difference being thatNimbusSans
, which is the preferred substitution forHelvetica
, has now higher priority than the default sans-serif substitutions coming fromCustomWeirdFont
.This behavior is closer to what fontconfig does on Linux systems, and seems overall a better way of looking for fallbacks.