Skip to content

fix: Enhance font weight determination for variable fonts #18894

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

gadfly3173
Copy link

What does the pull request do?

Fixes #18875 , enhance font weight determination for variable fonts.

What is the current behavior?

Font weight of the variable fonts is not correct.

image

What is the updated/expected behavior with this PR?

image

    <!-- Cascadia Code font -->
    <TextBlock Text="This is normal text in Cascadia Code font"
               FontFamily="Cascadia Code"
               FontSize="16" />
    <TextBlock Text="This is bold text in Cascadia Code font"
               FontFamily="Cascadia Code"
               FontWeight="Bold"
               FontSize="16" />

    <!-- Noto Sans font -->
    <TextBlock Text="This is normal text in Noto Sans font"
               FontFamily="Noto Sans SC"
               FontSize="16" />
    <TextBlock Text="This is bold text in Noto Sans font"
               FontFamily="Noto Sans SC"
               FontWeight="Bold"
               FontSize="16" />

    <!-- Dejavu Sans Mono font -->
    <TextBlock Text="This is normal text in Dejavu Sans Mono font"
               FontFamily="Dejavu Sans Mono"
               FontSize="16" />
    <TextBlock Text="This is bold text in Dejavu Sans Mono font"
               FontFamily="Dejavu Sans Mono"
               FontWeight="Bold"
               FontSize="16" />

    <!-- 思源黑体 CN font -->
    <TextBlock Text="This is normal text in 思源黑体 CN font"
               FontFamily="思源黑体 CN"
               FontSize="16" />
    <TextBlock Text="This is bold text in 思源黑体 CN font"
               FontFamily="思源黑体 CN"
               FontWeight="Bold"
               FontSize="16" />

    <!-- Roboto Flex font -->
    <TextBlock Text="This is normal text in Roboto Flex font"
               FontFamily="Roboto Flex"
               FontSize="16" />
    <TextBlock Text="This is bold text in Roboto Flex font"
               FontFamily="Roboto Flex"
               FontWeight="Bold"
               FontSize="16" />
  </StackPanel>

How was the solution implemented (if it's not obvious)?

Added variable font detection via 'fvar' table check

Checklist

Breaking changes

Obsoletions / Deprecations

Fixed issues

Fixes #18875

@rabbitism
Copy link
Contributor

Could you please also help to check if this is fixed? #18677

@cla-avalonia
Copy link
Collaborator

cla-avalonia commented May 20, 2025

  • All contributors have signed the CLA.

@gadfly3173
Copy link
Author

@cla-avalonia agree

@gadfly3173
Copy link
Author

gadfly3173 commented May 20, 2025

Could you please also help to check if this is fixed? #18677

It's not fixed. I don't think your issue is related to the font weight determination.

@avaloniaui-bot
Copy link

You can test this PR using the following package version. 12.0.999-cibuild0056617-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@avaloniaui-bot
Copy link

You can test this PR using the following package version. 12.0.999-cibuild0056619-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@Gillibald
Copy link
Contributor

Gillibald commented May 20, 2025

I can't accept this hack. We need to add proper variable fonts support and actually control the wght axis.

Variable fonts are not supported at the moment. Looking for the presence of fvar isn't enough.

@gadfly3173
Copy link
Author

Looking for the presence of fvar isn't enough.

I agree. SKTypeface lacks sufficient information to determine if it’s a variable font. However, variable font rendering works correctly below version 11.3. Should we revert the Weight assignment to the following logic?

Weight = (fontSimulations & FontSimulations.Bold) != 0 ? FontWeight.Bold : (FontWeight)typeface.FontWeight;

宋体 in the following pic is a single-weight, non-italic typeface. Its rendering effect is identical to #18113, while also supporting variable fonts.

image

#18113 effect:

image

@avaloniaui-bot
Copy link

You can test this PR using the following package version. 12.0.999-cibuild0056621-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

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.

Font Weight Rendering Regression in Avalonia 11.3.0
5 participants