Fix newline handling and whitespace trimming #442
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.
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