Skip to content

[WIP]Fix line height calculation for lines that contain fallback fonts #19013

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 9 commits into
base: master
Choose a base branch
from

Conversation

Gillibald
Copy link
Contributor

@Gillibald Gillibald commented Jun 6, 2025

What does the pull request do?

This PR changes the line text metrics calculation so fallback fonts do not affect the final metrics.
This also fixes an issue with zero-width glyphs that are being hit-tested.

What is the current behavior?

What is the updated/expected behavior with this PR?

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

Checklist

Breaking changes

Obsoletions / Deprecations

Fixed issues

@avaloniaui-bot
Copy link

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

@kerams
Copy link
Contributor

kerams commented Jun 6, 2025

Oh, cool, I tested this and it actually fixes my line height issues with combined font/script texts, which I thought were caused by some incompatibilities between fonts. #18881 and #18279 will probably see improvement too.

@kerams
Copy link
Contributor

kerams commented Jun 6, 2025

Having said that, the line height reduction also results in diacritics below the descender being clipped

12.0.999-cibuild0056951-alpha vs 12.0.999-cibuild0056532-alpha

image

@Gillibald
Copy link
Contributor Author

Could you provide me the string that shows the clipping?

@kerams
Copy link
Contributor

kerams commented Jun 6, 2025

بمكتب محامي

I'll try to whack out a repro project if the problem does not manifest for you (I am not adding any constraints that would cause it that I can see, but maybe the Material theme does).

And it turns out the 2 missing dots are not even combining diacritics, but proper part of the letter https://unicode-explorer.com/c/064A

@Gillibald Gillibald changed the title Fix line height calculation for lines that contain fallback fonts [WIP]Fix line height calculation for lines that contain fallback fonts Jun 9, 2025
@Gillibald Gillibald changed the title [WIP]Fix line height calculation for lines that contain fallback fonts Fix line height calculation for lines that contain fallback fonts Jun 10, 2025
@avaloniaui-bot
Copy link

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

@Gillibald Gillibald added customer-priority Issue reported by a customer with a support agreement. backport-candidate-11.3.x Consider this PR for backporting to 11.3 branch labels Jun 12, 2025
@avaloniaui-bot
Copy link

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

@MrJul
Copy link
Member

MrJul commented Jun 12, 2025

I don't think that's right, the fallback fonts should be used to determine the line's height as soon as they're used, or we'll get clipping and other issues. They should have no impact if unused though.

Said another way, having FontFamily="B" and FontFamily="A,B" should result in the exact same render if B is the only font effectively used, even if it's a fallback in the latter case.

Example:

<StackPanel TextElement.FontSize="32">
  <TextBlock Background="DodgerBlue" Text="رقم سري" FontFamily="/#Noto Sans Arabic" Margin="8" />
  <TextBlock Background="DodgerBlue" Text="رقم سري" FontFamily="/#Noto Sans,/#Noto Sans Arabic" Margin="8" />
</StackPanel>

Master:
image
This behavior, which in my opinion is the correct one, was actually a fix introduced in early 11.2 (I think in #15837?). It was broken in 11.1.x.

This PR:
image

Notice the clipping and line height not being respected.

Fonts: https://fonts.google.com/specimen/Noto+Sans and https://fonts.google.com/specimen/Noto+Sans+Arabic
Noto Sans Arabic is a great testing candidate since it has a huge line height.

@Gillibald
Copy link
Contributor Author

So there needs to be a different approach for the line height adjustment. We could adjust the scaling of the fallback font to better match the base font. In the end we want to avoid line height changes when a base font is mixed with a fallback font. If there is no ideal solution I need to revert the lineheight related changes.

@Gillibald Gillibald changed the title Fix line height calculation for lines that contain fallback fonts [WIP]Fix line height calculation for lines that contain fallback fonts Jun 13, 2025
@Gillibald
Copy link
Contributor Author

Related: #18438
#18438 (comment)

@avaloniaui-bot
Copy link

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

Remove InlineUIContainer BaselineAlignment override
Fix TextBlock InlineUIContainer arrange
@avaloniaui-bot
Copy link

You can test this PR using the following package version. 12.0.999-cibuild0057041-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
backport-candidate-11.3.x Consider this PR for backporting to 11.3 branch customer-priority Issue reported by a customer with a support agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants