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

Ability to configure font features #14157

Merged
merged 2 commits into from
Feb 1, 2024

Conversation

HermanKirshin
Copy link
Contributor

@HermanKirshin HermanKirshin commented Jan 9, 2024

What does the pull request do?

Added ability to configure font features.

What is the current behavior?

Default font configuration is used. For example in case of Inter by default it will automatically replace -> with arrow, 'x' between numbers to mathematical multiply sign and numbers are not tabular (this makes tables hardly readable).
See attached screenshot - current behavior is under 'Default'. Actual text specified in TextBlock.Text is

111111 x64 ->
999999 x64 ->

What is the updated/expected behavior with this PR?

Text elements now have property FontFeatures that allow to specify comma-separated feature values that configures the font (feature syntax is for example here). Property can be specified either on Run, or on TextBlock or on TextBox or on container (as attached), absolutely same as other font-related properties like size etc:

      <TextBlock Text="111111 x64 ->" FontFeatures="-calt,+tnum"></TextBlock> 

      <TextBlock>
        <Run FontFeatures="-calt,+tnum">111111 x64 -></Run>
      </TextBlock>

      <TextBox Text="111111 x64 ->" FontFeatures="-calt,+tnum"></TextBox>

      <StackPanel TextElement.FontFeatures="-calt,+tnum">
        <TextBlock Text="111111 x64 ->" />
      </StackPanel>
image

@HermanKirshin HermanKirshin force-pushed the fixes/fontfeatures branch 3 times, most recently from 1c7dd41 to ae398b7 Compare January 10, 2024 10:33
@avaloniaui-bot
Copy link

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

Copy link
Contributor

@Gillibald Gillibald left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution. I have added some comments.

In general, we should try to let Harfbuzz parse features/tags or just copy the parsing logic from HarfBuzzSharp

Something like this should be possible:

<TextElement.FontFeatures>
    <FontFeatureCollection>
        <FontFeature Tag="liga" Value="0"/>
    <FontFeatureCollection>
</TextElement.FontFeatures>

@Gillibald
Copy link
Contributor

@HermanKirshin Are you able to continue working on this or should I take over?

@HermanKirshin
Copy link
Contributor Author

HermanKirshin commented Jan 17, 2024

@HermanKirshin Are you able to continue working on this or should I take over?

@Gillibald Hi! Thanks for the review. Sorry for the delay, I'm a bit overwhelmed by work tasks currently, but assume that will be able to fix this PR on the weekend. But if you prefer to take over I wont mind either.

@Gillibald
Copy link
Contributor

I just wanted to make sure this is still being worked on take your time

@HermanKirshin HermanKirshin force-pushed the fixes/fontfeatures branch 2 times, most recently from f23df82 to 4b05118 Compare January 25, 2024 18:12
@avaloniaui-bot
Copy link

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

@HermanKirshin
Copy link
Contributor Author

@Gillibald Here are the fixes. I squashed commits for cleaner history.

@avaloniaui-bot
Copy link

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

@Gillibald
Copy link
Contributor

I have made some adjustments myself but I am not able to push to your fork

Here are the changes: https://github.com/AvaloniaUI/Avalonia/tree/pull/14157

@Gillibald
Copy link
Contributor

FontFeature is no longer mutable to avoid unexpected behavior. If someone wanted to animate text by altering font features one has to replace the whole collection.

@HermanKirshin
Copy link
Contributor Author

Merged pull/14157 into the fork

@avaloniaui-bot
Copy link

You can test this PR using the following package version. 11.1.999-cibuild0044042-beta. (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. 11.1.999-cibuild0044175-beta. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@maxkatz6 maxkatz6 requested a review from Gillibald January 31, 2024 23:11
@Gillibald Gillibald added this pull request to the merge queue Feb 1, 2024
@Gillibald
Copy link
Contributor

Thank you for your contribution

Merged via the queue into AvaloniaUI:master with commit 88967de Feb 1, 2024
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.

6 participants