Skip to content

Commit 8296f26

Browse files
akoch-yattaHeikoKlare
authored andcommitted
[win32] Fix TextLayout::getBounds vertical indent
This commit fixes too high lines when vertical indent was set for one TextLayout. There was a usage of vertical indent in pixels where vertical indent in points should have been used. Contributes to #62 and #127
1 parent 00cbedf commit 8296f26

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

bundles/org.eclipse.swt/Eclipse SWT Tests/win32/org/eclipse/swt/graphics/TextLayoutWin32Tests.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
*******************************************************************************/
1414
package org.eclipse.swt.graphics;
1515

16-
import static org.junit.Assert.assertEquals;
16+
import static org.junit.jupiter.api.Assertions.assertEquals;
17+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
1718

1819
import org.eclipse.swt.internal.*;
1920
import org.junit.jupiter.api.*;
@@ -38,7 +39,26 @@ public void testGetBoundPublicAPIshouldReturnTheSameValueRegardlessOfZoomLevel()
3839
layout.draw(scaledGc, 10, 10);
3940
Rectangle scaledBounds = layout.getBounds();
4041

41-
assertEquals("The public API for getBounds should give the same result for any zoom level", scaledBounds, unscaledBounds);
42+
assertEquals(unscaledBounds, scaledBounds, "The public API for getBounds should give the same result for any zoom level");
43+
}
44+
45+
@Test
46+
public void testCalculateGetBoundsWithVerticalIndent() {
47+
TextLayout layout = new TextLayout(display);
48+
layout.setVerticalIndent(16);
49+
layout.setText(text);
50+
Rectangle unscaledBounds = layout.getBounds();
51+
52+
int scalingFactor = 2;
53+
int newZoom = DPIUtil.getNativeDeviceZoom() * scalingFactor;
54+
changeDPIZoom(newZoom);
55+
TextLayout scaledLayout = new TextLayout(display);
56+
scaledLayout.setVerticalIndent(16);
57+
scaledLayout.setText(text);
58+
Rectangle scaledBounds = scaledLayout.getBounds();
59+
60+
assertNotEquals(layout.nativeZoom, scaledLayout.nativeZoom, "The native zoom for the TextLayouts must differ");
61+
assertEquals(unscaledBounds.height, scaledBounds.height, 1, "The public API for getBounds with vertical indent > 0 should give a similar result for any zoom level");
4262
}
4363

4464
}

bundles/org.eclipse.swt/Eclipse SWT Tests/win32/org/eclipse/swt/internal/Win32AutoscaleTestBase.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public void tearDownTest() {
4141
}
4242

4343
protected void changeDPIZoom (int nativeZoom) {
44+
DPIUtil.setDeviceZoom(nativeZoom);
4445
float scalingFactor = 1f * DPIUtil.getZoomForAutoscaleProperty(nativeZoom) / DPIUtil.getZoomForAutoscaleProperty(shell.nativeZoom);
4546
DPIZoomChangeRegistry.applyChange(shell, nativeZoom, scalingFactor);
4647
}

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/TextLayout.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1792,7 +1792,7 @@ public Rectangle getBounds () {
17921792
width = Math.max(width, DPIUtil.scaleDown(lineWidthInPixels[line], getZoom()) + getLineIndent(line));
17931793
}
17941794
}
1795-
return new Rectangle (0, 0, width, lineY[lineY.length - 1] + getScaledVerticalIndent());
1795+
return new Rectangle (0, 0, width, lineY[lineY.length - 1] + getVerticalIndent());
17961796
}
17971797

17981798
/**

0 commit comments

Comments
 (0)