[Win32] Normalise \r and \r\n to \n in GDI+ text rendering#3368
Draft
HeikoKlare wants to merge 1 commit into
Draft
[Win32] Normalise \r and \r\n to \n in GDI+ text rendering#3368HeikoKlare wants to merge 1 commit into
HeikoKlare wants to merge 1 commit into
Conversation
GDI+ Graphics_DrawString only treats \n as a line delimiter; bare \r is silently ignored rather than treated as a line break. The GDI DrawText path (non-advanced mode) and the old DrawDriverString path both accepted \r and \r\n as line delimiters, so the mismatch was a regression for callers that pass Windows-style (CRLF) or old Mac-style (CR-only) line endings with DRAW_DELIMITER set. Fix: in drawTextGDIP(), when DRAW_DELIMITER is active, normalise \r\n to \n first (to avoid double line breaks), then convert any remaining lone \r to \n before handing the string to Graphics_DrawString. Add a cross-platform regression test that verifies all three line-ending variants (\n, \r, \r\n) produce the same text height in both advanced and non-advanced rendering mode. Contributes to eclipse-platform#3091
Contributor
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.
Summary
GDI+
Graphics_DrawStringonly treats\nas a line delimiter; bare\ris silently ignored rather than treated as a line break. The GDIDrawTextpath (non-advanced mode) and the oldDrawDriverStringpath both accept\rand\r\nas line delimiters, so callers that pass Windows-style (CRLF) or old Mac-style (CR-only) line endings withDRAW_DELIMITERset get different results depending on whether advanced mode is active.drawTextGDIP(), whenDRAW_DELIMITERis active, normalise\r\n→\nfirst (to avoid double line breaks), then convert any remaining lone\r→\nbefore passing the string toGraphics_DrawString.test_textExtentLjava_lang_StringI_lineDelimiterVariants) that verifies all three line-ending variants produce the sametextExtentheight in both advanced and non-advanced mode.Contributes to #3091
Manual verification
The following snippet renders the same two-line text with
\n,\r, and\r\nin both GDI (reference) and GDI+ mode side by side. Before the fix, the CR column in the GDI+ row shows both lines collapsed onto one line. After the fix all six cells look identical.The
中character is included in the GDI+ strings to force thedrawTextGDIP()path viauseGDIP()(it has no glyph in Courier New). It appears at the end of line 2 and can be ignored.