Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fontscan] Better family substitutions #105

Merged
merged 3 commits into from
Nov 20, 2023
Merged

[fontscan] Better family substitutions #105

merged 3 commits into from
Nov 20, 2023

Conversation

benoitkugler
Copy link
Contributor

@benoitkugler benoitkugler commented Nov 17, 2023

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 neither CustomWeirdFont nor Helvetica, and calls ResolveFace('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 to sans-serif for which the system has (many) fonts (with support for the rune 'a'). So ResolveFace returns the 'preferred' sans-serif face. It has not take into account the Helvetica 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 for Helvetica, the expanded families will look like {CustomWeirdFont, Helvetica, NimbusSans, ..., other sans-serif families}, with the main difference being that NimbusSans, which is the preferred substitution for Helvetica, has now higher priority than the default sans-serif substitutions coming from CustomWeirdFont.

This behavior is closer to what fontconfig does on Linux systems, and seems overall a better way of looking for fallbacks.

Copy link
Contributor

@andydotxyz andydotxyz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Description sounds great and the code looks solid too, nice one :)

Copy link
Member

@whereswaldon whereswaldon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you; this is a definite improvement.

@whereswaldon whereswaldon merged commit 51cce45 into main Nov 20, 2023
20 checks passed
@whereswaldon whereswaldon deleted the substitutions branch November 20, 2023 17:57
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.

3 participants