-
-
Notifications
You must be signed in to change notification settings - Fork 73
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
Fix newline handling and whitespace trimming #442
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 7 out of 14 changed files in this pull request and generated 2 comments.
Files not reviewed (7)
- tests/Images/ReferenceOutput/LineWrappingWithExplicitNewLine__WrappingLength_800_.png: Language not supported
- tests/Images/ReferenceOutput/LineWrappingWithImplicitNewLine__WrappingLength_800_.png: Language not supported
- tests/Images/ReferenceOutput/RenderingTextIncludesAllGlyphs__WrappingLength_1900_.png: Language not supported
- tests/SixLabors.Fonts.Tests/Issues/Issues_35.cs: Evaluated as low risk
- tests/SixLabors.Fonts.Tests/Issues/Issues_27.cs: Evaluated as low risk
- tests/SixLabors.Fonts.Tests/Issues/Issues_36.cs: Evaluated as low risk
- tests/SixLabors.Fonts.Tests/Issues/Issues_434.cs: Evaluated as low risk
Comments suppressed due to low confidence (2)
src/SixLabors.Fonts/TextLayout.cs:410
- [nitpick] The use of
goto
statements can make the code harder to read and maintain. Consider refactoring the code to avoid usinggoto
.
goto end;
src/SixLabors.Fonts/TextLayout.cs:1222
- Ensure that the changes are covered by tests to verify the new behavior.
textLine = remaining;
Out of interest, what happens to |
No. That would remain as |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
generally approved, i'm not 100% sure we need to goto
s but happy to leave them you you believe they are the right construct to use
src/SixLabors.Fonts/TextLayout.cs
Outdated
boxLocation.X = originX; | ||
boxLocation.Y += advanceY; | ||
continue; | ||
goto end; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
surely this would be the same as
goto end; | |
return glyphs; |
for this particular case? (there's a good chance i'm missing something that make the goto worth it)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I shouldn't code late at night.
Prerequisites
Description
Fixes
This PR resolves the following issues:
Summary
This PR addresses two primary issues:
Mandatory Break Overshoot:
Breaking at a mandatory break could occasionally overshoot, causing wrapping to occur incorrectly. This is now fixed, ensuring that lines break correctly within the wrapping length.
Line Counting and Whitespace Trimming Improvements:
Additional fixes improve the handling of trailing whitespace and newline characters during text measurement and layout creation. These changes affect the number of
GlyphLayout
instances produced when breaking multiple concurrent newlines, ensuring consistent cross-platform behavior. These additional glyphs are not passed to the renderer.Key Changes
Trailing Whitespace Trimming
Example:
Explanation:
Example:
Explanation:
Hello
starts on the second line after the break.Newline Preservation
\r
,\n
,\r\n
) are now processed according to Unicode Standard Rule 13.\r\n
sequence is collapsed into a single\r
, where the break occurs at\r
and the\n
is trimmed.Example:
Explanation:
\r\n
becomes\r
, ensuring consistent line-breaking semantics.\r\n\r\n
) correctly result in one empty line.Improved Line Counting