diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/GC.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/GC.java index 06429400a56..fa44dbe351f 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/GC.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/GC.java @@ -3037,6 +3037,9 @@ private RectF drawText(long gdipGraphics, char[] buffer, int start, int length, private void drawTextGDIP(long gdipGraphics, String string, int x, int y, int flags, boolean draw, Point size) { boolean needsBounds = !draw || (flags & SWT.DRAW_TRANSPARENT) == 0; char[] buffer; + if ((flags & SWT.DRAW_DELIMITER) == 0) { + string = string.replaceAll("[\\r\\n]+", ""); + } int length = string.length(); if (length != 0) { buffer = string.toCharArray(); diff --git a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_GC.java b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_GC.java index 95965f72e96..e01c9cdecc4 100644 --- a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_GC.java +++ b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_GC.java @@ -954,6 +954,18 @@ public void test_textExtentLjava_lang_StringI() { assertEquals(SWT.ERROR_GRAPHIC_DISPOSED, e.code); } +@Test +public void test_textExtentLjava_lang_StringI_disabledLineDelimiter() { + gc.setAdvanced(false); + Point ptWithoutAdvanced = gc.textExtent("abc\u4E2D" + System.lineSeparator() + "def", 0); + gc.setAdvanced(true); + Point ptWithAdvanced = gc.textExtent("abc\u4E2D" + System.lineSeparator() + "def", 0); + // Due to slightly different rendering, size must not be identical but similar in advanced/non-advanced mode + assertTrue(Math.abs(ptWithAdvanced.x - ptWithoutAdvanced.x) <= 2); + assertTrue(Math.abs(ptWithAdvanced.y - ptWithoutAdvanced.y) <= 2); + gc.dispose(); +} + @Test public void test_toString() { String s = gc.toString();