fix(text): preserve lines at rounded fractional heights - #21834
Merged
Conversation
A wrapped TextBlock with a fractional line height must retain every line when its desired height lands exactly on a fractional-scale pixel boundary.
TextLayout treated a floating-point accumulation error as a MaxHeight overflow. Use the established tolerant comparison so a line that exactly fits its rounded layout bounds is retained.
NathanDrake2406
marked this pull request as ready for review
July 23, 2026 16:06
|
You can test this PR using the following package version. |
MrJul
approved these changes
Jul 24, 2026
MrJul
left a comment
Member
There was a problem hiding this comment.
Floating point errors strike again.
LGTM!
MrJul
enabled auto-merge
July 24, 2026 14:55
|
You can test this PR using the following package version. |
github-merge-queue
Bot
removed this pull request from the merge queue due to failed status checks
Jul 24, 2026
MrJul
added a commit
that referenced
this pull request
Jul 29, 2026
* test(textblock): cover fractional layout rounding A wrapped TextBlock with a fractional line height must retain every line when its desired height lands exactly on a fractional-scale pixel boundary. * fix(text): preserve lines at rounded fractional heights TextLayout treated a floating-point accumulation error as a MaxHeight overflow. Use the established tolerant comparison so a line that exactly fits its rounded layout bounds is retained. --------- Co-authored-by: Julien Lebosquain <julien@lebosquain.net>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What does the pull request do?
Fixes #21786 by preventing a wrapped
TextBlockfrom omitting its final line when a fractionalLineHeightlands exactly on a display-scale rounded height.What is the current behavior?
At 125% scaling, three 20.8-unit lines round to 62.4 logical units. Floating-point accumulation can evaluate the total as marginally above 62.4, so
TextLayouttreats the last line as exceedingMaxHeightand omits it.What is the updated/expected behavior with this PR?
All three wrapped lines remain visible when the rounded layout height exactly fits them. Real max-height overflow continues to clip or trim text.
Validation:
TextBlockwithLineHeight=20.8. The test fails before the fix with 2 lines instead of 3.dotnet run --project tests/Avalonia.Controls.UnitTests/Avalonia.Controls.UnitTests.csproj -- --filter-class "Avalonia.Controls.UnitTests.TextBlockTests"dotnet run --project tests/Avalonia.Skia.UnitTests/Avalonia.Skia.UnitTests.csproj -- --filter-class "Avalonia.Skia.UnitTests.Media.TextFormatting.TextLayoutTests"How was the solution implemented (if it is not obvious)?
The max-height comparison now uses the established tolerant
MathUtilities.GreaterThancheck instead of exact>. This is already used for text-width overflow and avoids treating ordinary floating-point precision error as an extra line.Checklist
Breaking changes
None.
Obsoletions / Deprecations
None.
Fixed issues
Fixes #21786