Skip to content

Commit 29bae82

Browse files
akoch-yattaHeikoKlare
authored andcommitted
[win32] Use operations for Path manipulation
This commit refactors Path in the win32 implementation to better support multiple handles for different zoom settings of a Path when monitor-specific scaling is enabled. The previous implementation only applied adaptions to the initial handle of the path and relied on the path not to be changed afterwards. This doesn't cover all scenarios and can lead to unexpected behavior when re-using Path objects over different zoom settings.
1 parent 523a5d4 commit 29bae82

File tree

5 files changed

+653
-222
lines changed

5 files changed

+653
-222
lines changed

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

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

16+
import static org.junit.Assert.assertFalse;
1617
import static org.junit.Assert.assertTrue;
1718

1819
import java.util.*;
@@ -49,9 +50,11 @@ public void testHandlesExistForEachZoomLevelInHashMap() {
4950
DPIUtil.setDeviceZoom(zoom);
5051
Path path = new Path(display);
5152
path.addArc(0, 0, 10, 10, 0, 90);
53+
path.getHandle(zoom);
54+
assertTrue("zoomLevelToHandle should contain initial zoom's handle", path.toString().contains(zoom + "="));
55+
assertFalse("zoomLevelToHandle should not contains scaled handle", path.toString().contains(scaledZoom + "="));
5256
path.getHandle(scaledZoom);
53-
assertTrue("zoomLevelToHandle contains scaled handle", path.toString().contains(scaledZoom + "="));
54-
assertTrue("zoomLevelToHandle contains initial zoom's handle", path.toString().contains(zoom + "="));
57+
assertTrue("zoomLevelToHandle should contain scaled handle", path.toString().contains(scaledZoom + "="));
5558
}
5659

5760
@Test
@@ -70,4 +73,22 @@ public void testBoundsAreScaledWRTZoomLevel() {
7073
assertTrue("Height is scaled up wrt the scalingFactor", bounds.Height * scalingFactor == scaledBounds.Height);
7174
assertTrue("Height is scaled up wrt the scalingFactor", bounds.Width * scalingFactor == scaledBounds.Width);
7275
}
76+
77+
@Test
78+
public void testCreatePathHandleWithDisposedPathInvolved() {
79+
Display display = Display.getDefault();
80+
81+
Path path = new Path(display);
82+
path.addArc(0, 0, 10, 10, 0, 90);
83+
84+
Path path2 = new Path(display);
85+
path.addArc(0, 0, 30, 30, 0, 270);
86+
87+
path.addPath(path2);
88+
89+
path2.dispose();
90+
path.getHandle(100);
91+
path.getHandle(200);
92+
path.dispose();
93+
}
7394
}

0 commit comments

Comments
 (0)