diff --git a/bundles/org.eclipse.swt/Eclipse SWT AWT/win32/org/eclipse/swt/awt/SWT_AWT.java b/bundles/org.eclipse.swt/Eclipse SWT AWT/win32/org/eclipse/swt/awt/SWT_AWT.java index 20dfbd5f2a..68541e6326 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT AWT/win32/org/eclipse/swt/awt/SWT_AWT.java +++ b/bundles/org.eclipse.swt/Eclipse SWT AWT/win32/org/eclipse/swt/awt/SWT_AWT.java @@ -286,7 +286,6 @@ public static Shell new_Shell (final Display display, final Canvas parent) { SWT.error (SWT.ERROR_NOT_IMPLEMENTED, e); } if (handle == 0) SWT.error (SWT.ERROR_INVALID_ARGUMENT, null, " [peer not created]"); - final Shell shell = Shell.win32_new (display, handle); final ComponentListener listener = new ComponentAdapter () { @Override @@ -294,7 +293,7 @@ public void componentResized (ComponentEvent e) { display.syncExec (() -> { if (shell.isDisposed()) return; Dimension dim = parent.getSize (); - shell.setSize(DPIUtil.autoScaleDown(new Point(dim.width, dim.height))); // To Points + shell.setSize(DPIUtil.scaleDown(new Point(dim.width, dim.height), DPIUtil.getDeviceZoom())); // To Points }); } }; diff --git a/bundles/org.eclipse.swt/Eclipse SWT Browser/win32/org/eclipse/swt/browser/IE.java b/bundles/org.eclipse.swt/Eclipse SWT Browser/win32/org/eclipse/swt/browser/IE.java index 840d258570..eb91911b6b 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Browser/win32/org/eclipse/swt/browser/IE.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Browser/win32/org/eclipse/swt/browser/IE.java @@ -1880,7 +1880,7 @@ void handleDOMEvent (OleEvent e) { int screenY = pVarResult.getInt(); pVarResult.dispose(); - Point position = DPIUtil.autoScaleDown(new Point(screenX, screenY)); // To Points + Point position = DPIUtil.scaleDown(new Point(screenX, screenY), DPIUtil.getDeviceZoom()); // To Points position = browser.getDisplay().map(null, browser, position); newEvent.x = position.x; newEvent.y = position.y; diff --git a/bundles/org.eclipse.swt/Eclipse SWT Browser/win32/org/eclipse/swt/browser/WebSite.java b/bundles/org.eclipse.swt/Eclipse SWT Browser/win32/org/eclipse/swt/browser/WebSite.java index 75574d434a..b88a7ff346 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Browser/win32/org/eclipse/swt/browser/WebSite.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Browser/win32/org/eclipse/swt/browser/WebSite.java @@ -320,8 +320,8 @@ int ShowContextMenu(int dwID, long ppt, long pcmdtReserved, long pdispReserved) Event event = new Event(); POINT pt = new POINT(); OS.MoveMemory(pt, ppt, POINT.sizeof); - pt.x = DPIUtil.autoScaleDown(pt.x); // To Points - pt.y = DPIUtil.autoScaleDown(pt.y); // To Points + pt.x = DPIUtil.scaleDown(pt.x, DPIUtil.getDeviceZoom()); // To Points + pt.y = DPIUtil.scaleDown(pt.y, DPIUtil.getDeviceZoom()); // To Points event.x = pt.x; event.y = pt.y; browser.notifyListeners(SWT.MenuDetect, event); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Image.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Image.java index d1e95565b4..4b011c93b5 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Image.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Image.java @@ -1822,11 +1822,11 @@ public String toString () { * @noreference This method is not intended to be referenced by clients. */ public static void drawScaled(GC gc, Image original, int width, int height, float scaleFactor) { - gc.drawImage (original, 0, 0, DPIUtil.autoScaleDown (width), DPIUtil.autoScaleDown (height), + gc.drawImage (original, 0, 0, CocoaDPIUtil.autoScaleDown (width), CocoaDPIUtil.autoScaleDown (height), /* E.g. destWidth here is effectively DPIUtil.autoScaleDown (scaledWidth), but avoiding rounding errors. * Nevertheless, we still have some rounding errors due to the point-based API GC#drawImage(..). */ - 0, 0, Math.round (DPIUtil.autoScaleDown (width * scaleFactor)), Math.round (DPIUtil.autoScaleDown (height * scaleFactor))); + 0, 0, Math.round (CocoaDPIUtil.autoScaleDown (width * scaleFactor)), Math.round (CocoaDPIUtil.autoScaleDown (height * scaleFactor))); } } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/internal/CocoaDPIUtil.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/internal/CocoaDPIUtil.java new file mode 100644 index 0000000000..7e0e0aaba4 --- /dev/null +++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/internal/CocoaDPIUtil.java @@ -0,0 +1,48 @@ +/******************************************************************************* + * Copyright (c) 2022 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Daniel Kruegler - #420 - [High DPI] "swt.autoScale" should add new "half" option + * Yatta Solutions - #131 - Additional methods to specify target zoom directly + *******************************************************************************/ +package org.eclipse.swt.internal; + +/** + * This class hold common constants and utility functions w.r.t. to SWT high DPI + * functionality. + *
+ * The {@code autoScaleUp(..)} methods convert from API coordinates (in SWT + * points) to internal high DPI coordinates (in pixels) that interface with + * native widgets. + *
+ *+ * The {@code autoScaleDown(..)} convert from high DPI pixels to API coordinates + * (in SWT points). + *
+ * + * @since 3.105 + */ +public class CocoaDPIUtil { + + /** + * Auto-scale down int dimensions. + */ + public static int autoScaleDown(int size) { + return DPIUtil.scaleDown(size, DPIUtil.deviceZoom); + } + + /** + * Auto-scale down float dimensions. + */ + public static float autoScaleDown(float size) { + return DPIUtil.scaleDown(size, DPIUtil.deviceZoom); + } +} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageData.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageData.java index c5515b3fe7..4333190bb4 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageData.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageData.java @@ -2613,31 +2613,31 @@ static void buildDitheredGradientChannel(int from, int to, int steps, static void fillGradientRectangle(GC gc, Device device, int x, int y, int width, int height, boolean vertical, RGB fromRGB, RGB toRGB, - int redBits, int greenBits, int blueBits) { + int redBits, int greenBits, int blueBits, int zoom) { /* Create the bitmap and tile it */ ImageData band = createGradientBand(width, height, vertical, fromRGB, toRGB, redBits, greenBits, blueBits); Image image = new Image(device, band); if ((band.width == 1) || (band.height == 1)) { - gc.drawImage(image, 0, 0, DPIUtil.autoScaleDown(band.width), DPIUtil.autoScaleDown(band.height), - DPIUtil.autoScaleDown(x), DPIUtil.autoScaleDown(y), DPIUtil.autoScaleDown(width), - DPIUtil.autoScaleDown(height)); + gc.drawImage(image, 0, 0, DPIUtil.scaleDown(band.width, zoom), DPIUtil.scaleDown(band.height, zoom), + DPIUtil.scaleDown(x, zoom), DPIUtil.scaleDown(y, zoom), DPIUtil.scaleDown(width, zoom), + DPIUtil.scaleDown(height, zoom)); } else { if (vertical) { for (int dx = 0; dx < width; dx += band.width) { int blitWidth = width - dx; if (blitWidth > band.width) blitWidth = band.width; - gc.drawImage(image, 0, 0, DPIUtil.autoScaleDown(blitWidth), DPIUtil.autoScaleDown(band.height), - DPIUtil.autoScaleDown(dx + x), DPIUtil.autoScaleDown(y), DPIUtil.autoScaleDown(blitWidth), - DPIUtil.autoScaleDown(band.height)); + gc.drawImage(image, 0, 0, DPIUtil.scaleDown(blitWidth, zoom), DPIUtil.scaleDown(band.height, zoom), + DPIUtil.scaleDown(dx + x, zoom), DPIUtil.scaleDown(y, zoom), DPIUtil.scaleDown(blitWidth, zoom), + DPIUtil.scaleDown(band.height, zoom)); } } else { for (int dy = 0; dy < height; dy += band.height) { int blitHeight = height - dy; if (blitHeight > band.height) blitHeight = band.height; - gc.drawImage(image, 0, 0, DPIUtil.autoScaleDown(band.width), DPIUtil.autoScaleDown(blitHeight), - DPIUtil.autoScaleDown(x), DPIUtil.autoScaleDown(dy + y), DPIUtil.autoScaleDown(band.width), - DPIUtil.autoScaleDown(blitHeight)); + gc.drawImage(image, 0, 0, DPIUtil.scaleDown(band.width, zoom), DPIUtil.scaleDown(blitHeight, zoom), + DPIUtil.scaleDown(x, zoom), DPIUtil.scaleDown(dy + y, zoom), DPIUtil.scaleDown(band.width, zoom), + DPIUtil.scaleDown(blitHeight, zoom)); } } } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/DPIUtil.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/DPIUtil.java index a15f4683ae..36dfe1b48f 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/DPIUtil.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/DPIUtil.java @@ -40,7 +40,7 @@ public class DPIUtil { private static final int DPI_ZOOM_100 = 96; - private static int deviceZoom = 100; + public static int deviceZoom = 100; private static int nativeDeviceZoom = 100; private static enum AutoScaleMethod { AUTO, NEAREST, SMOOTH; @@ -59,7 +59,6 @@ public static Optional+ * The {@code autoScaleUp(..)} methods convert from API coordinates (in + * SWT points) to internal high DPI coordinates (in pixels) that interface with + * native widgets. + *
+ *+ * The {@code autoScaleDown(..)} convert from high DPI pixels to API coordinates + * (in SWT points). + *
+ * + * @since 3.105 + */ +public class GtkDPIUtil { + + /** + * Auto-scale up ImageData to device zoom that is at 100%. + */ + public static ImageData autoScaleUp (Device device, final ImageData imageData) { + return autoScaleImageData(device, imageData, 100); + } + + /** + * Auto-scale ImageData to device zoom that are at given zoom factor. + */ + public static ImageData autoScaleImageData (Device device, final ImageData imageData, int imageDataZoomFactor) { + if (DPIUtil.deviceZoom == imageDataZoomFactor || imageData == null || (device != null && !device.isAutoScalable())) return imageData; + float scaleFactor = (float) DPIUtil.deviceZoom / imageDataZoomFactor; + return DPIUtil.autoScaleImageData(device, imageData, scaleFactor); + } + +} 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 6199377681..cf3ab4b48a 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 @@ -2807,10 +2807,10 @@ void fillArcInPixels (int x, int y, int width, int height, int startAngle, int a */ public void fillGradientRectangle (int x, int y, int width, int height, boolean vertical) { Rectangle rect = DPIUtil.scaleUp(drawable, new Rectangle(x, y, width, height), getZoom()); - fillGradientRectangleInPixels(rect.x, rect.y, rect.width, rect.height, vertical); + fillGradientRectangleInPixels(rect.x, rect.y, rect.width, rect.height, vertical, getZoom()); } -void fillGradientRectangleInPixels(int x, int y, int width, int height, boolean vertical) { +void fillGradientRectangleInPixels(int x, int y, int width, int height, boolean vertical, int zoom) { checkNonDisposed(); if (width == 0 || height == 0) return; @@ -2901,7 +2901,7 @@ void fillGradientRectangleInPixels(int x, int y, int width, int height, boolean final int bitResolution = (depth >= 24) ? 8 : (depth >= 15) ? 5 : 0; ImageData.fillGradientRectangle(this, data.device, x, y, width, height, vertical, fromRGB, toRGB, - bitResolution, bitResolution, bitResolution); + bitResolution, bitResolution, bitResolution, zoom); } /** diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java index 511fcdfec4..77523bf7be 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java @@ -1592,7 +1592,7 @@ public Menu getMenuBar () { @Override public Rectangle getBounds() { checkDevice (); - return DPIUtil.autoScaleDown(getBoundsInPixels()); + return DPIUtil.scaleDown(getBoundsInPixels(), DPIUtil.getDeviceZoom()); } Rectangle getBoundsInPixels () { @@ -1665,7 +1665,7 @@ int getClickCount (int type, int button, long hwnd, long lParam) { @Override public Rectangle getClientArea () { checkDevice (); - return DPIUtil.autoScaleDown(getClientAreaInPixels()); + return DPIUtil.scaleDown(getClientAreaInPixels(), DPIUtil.getDeviceZoom()); } Rectangle getClientAreaInPixels () { diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/SingleZoomCoordinateSystemMapper.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/SingleZoomCoordinateSystemMapper.java index e925359299..4e23cbb4e6 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/SingleZoomCoordinateSystemMapper.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/SingleZoomCoordinateSystemMapper.java @@ -72,7 +72,7 @@ public Rectangle map(Control from, Control to, int x, int y, int width, int heig @Override public Rectangle mapMonitorBounds(Rectangle rect, int zoom) { - return DPIUtil.autoScaleDown(rect); + return DPIUtil.scaleDown(rect, zoom); } @Override @@ -97,13 +97,15 @@ public Rectangle translateToDisplayCoordinates(Rectangle rect, int zoom) { @Override public Point getCursorLocation() { + int zoom = DPIUtil.getDeviceZoom(); Point cursorLocationInPixels = display.getCursorLocationInPixels(); - return DPIUtil.autoScaleDown(cursorLocationInPixels); + return DPIUtil.scaleDown(cursorLocationInPixels, zoom); } @Override public void setCursorLocation(int x, int y) { - display.setCursorLocationInPixels(DPIUtil.autoScaleUp(x), DPIUtil.autoScaleUp(y)); + int zoom = DPIUtil.getDeviceZoom(); + display.setCursorLocationInPixels(DPIUtil.scaleUp(x, zoom), DPIUtil.scaleUp(y, zoom)); } @Override diff --git a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/DPIUtilTests.java b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/DPIUtilTests.java index d501c4d0a6..802f3ef794 100644 --- a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/DPIUtilTests.java +++ b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/DPIUtilTests.java @@ -14,7 +14,6 @@ package org.eclipse.swt.tests.junit; -import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertSame; @@ -50,97 +49,16 @@ public void tearDown() { DPIUtil.setDeviceZoom(deviceZoom); } - @Test - public void scaleDownFloatArray() { - float[] valueAt200 = new float[] { 2, 3, 4 }; - float[] valueAt150 = new float[] { 1.5f, 2.25f, 3 }; - float[] valueAt100 = new float[] { 1, 1.5f, 2 }; - - float[] scaledValue = DPIUtil.autoScaleDown(valueAt200); - assertArrayEquals(valueAt100, scaledValue, .001f, String.format("Scaling down float array from device zoom (%d) to 100 failed", - ZOOM_200)); - scaledValue = DPIUtil.autoScaleDown((Device) null, valueAt200); - assertArrayEquals(valueAt100, scaledValue, .001f, String.format("Scaling down float array from device zoom (%d) to 100 with device failed", - ZOOM_200)); - - scaledValue = DPIUtil.scaleDown(valueAt200, 200); - assertArrayEquals(valueAt100, scaledValue, .001f, "Scaling down float array from 200 failed"); - scaledValue = DPIUtil.scaleDown((Device) null, valueAt200, 200); - assertArrayEquals(valueAt100, scaledValue, .001f, "Scaling down float array from 200 with device failed"); - scaledValue = DPIUtil.scaleDown(valueAt150, 150); - assertArrayEquals(valueAt100, scaledValue, .001f, "Scaling down float array from 150 failed"); - scaledValue = DPIUtil.scaleDown((Device) null, valueAt150, 150); - assertArrayEquals(valueAt100, scaledValue, .001f, "Scaling down float array from 150 with device failed"); - scaledValue = DPIUtil.scaleDown(valueAt100, 100); - assertSame(valueAt100, scaledValue, "Scaling down float array without zoom change failed"); - scaledValue = DPIUtil.scaleDown((Device) null, valueAt100, 100); - assertSame(valueAt100, scaledValue, "Scaling down float array without zoom change with device failed"); - } - - @Test - public void scaleDownInteger() { - int valueAt200 = 10; - int valueAt150 = 7; - int valueAt100 = 5; - - int scaledValue = DPIUtil.autoScaleDown(valueAt200); - assertEquals( - valueAt100, scaledValue, String.format("Scaling down integer from device zoom (%d) to 100 failed", ZOOM_200)); - scaledValue = DPIUtil.autoScaleDown((Device) null, valueAt200); - assertEquals( - valueAt100, scaledValue, String.format("Scaling down integer from device zoom (%d) to 100 with device failed", ZOOM_200)); - - scaledValue = DPIUtil.scaleDown(valueAt200, 200); - assertEquals(valueAt100, scaledValue, "Scaling down integer from 200 failed"); - scaledValue = DPIUtil.scaleDown((Device) null, valueAt200, 200); - assertEquals(valueAt100, scaledValue, "Scaling down integer from 200 with device failed"); - scaledValue = DPIUtil.scaleDown(valueAt150, 150); - assertEquals(valueAt100, scaledValue, "Scaling down integer from 150 failed"); - scaledValue = DPIUtil.scaleDown((Device) null, valueAt150, 150); - assertEquals(valueAt100, scaledValue, "Scaling down integer from 150 with device failed"); - scaledValue = DPIUtil.scaleDown(valueAt100, 100); - assertSame(valueAt100, scaledValue, "Scaling down integer without zoom change failed"); - scaledValue = DPIUtil.scaleDown((Device) null, valueAt100, 100); - assertSame(valueAt100, scaledValue, "Scaling down integer without zoom change with device failed"); - } - - @Test - public void scaleDownFloat() { - float valueAt200 = 10f; - float valueAt150 = 7.5f; - float valueAt100 = 5f; - - float scaledValue = DPIUtil.autoScaleDown(valueAt200); - assertEquals(valueAt100, scaledValue, .001f, - String.format("Scaling down float from device zoom (%d) to 100 failed", ZOOM_200)); - scaledValue = DPIUtil.autoScaleDown((Device) null, valueAt200); - assertEquals(valueAt100, scaledValue, .001f, String - .format("Scaling down float from device zoom (%d) to 100 with device failed", ZOOM_200)); - - scaledValue = DPIUtil.scaleDown(valueAt200, 200); - assertEquals(valueAt100, scaledValue, .001f, "Scaling down float from 200 failed"); - scaledValue = DPIUtil.scaleDown((Device) null, valueAt200, 200); - assertEquals(valueAt100, scaledValue, .001f, "Scaling down float from 200 with device failed"); - scaledValue = DPIUtil.scaleDown(valueAt150, 150); - assertEquals(valueAt100, scaledValue, .001f, "Scaling down float from 150 failed"); - scaledValue = DPIUtil.scaleDown((Device) null, valueAt150, 150); - assertEquals(valueAt100, scaledValue, .001f, "Scaling down float from 150 with device failed"); - scaledValue = DPIUtil.scaleDown(valueAt100, 100); - assertEquals(valueAt100, scaledValue, .001f, "Scaling down float without zoom change failed"); - scaledValue = DPIUtil.scaleDown((Device) null, valueAt100, 100); - assertEquals(valueAt100, scaledValue, .001f, "Scaling down float without zoom change with device failed"); - } - @Test public void scaleDownPoint() { Point valueAt200 = new Point(10, 14); Point valueAt150 = new Point(7, 10); Point valueAt100 = new Point(5, 7); - Point scaledValue = DPIUtil.autoScaleDown(valueAt200); + Point scaledValue = DPIUtil.scaleDown(valueAt200, 100); assertEquals(valueAt100, scaledValue, String.format("Scaling down Point from device zoom (%d) to 100 failed", ZOOM_200)); - scaledValue = DPIUtil.autoScaleDown((Device) null, valueAt200); + scaledValue = DPIUtil.scaleDown((Device) null, valueAt200, 100); assertEquals(valueAt100, scaledValue, String .format("Scaling down Point from device zoom (%d) to 100 with device failed", ZOOM_200)); @@ -164,10 +82,10 @@ public void scaleDownRectangle() { Rectangle valueAt150 = new Rectangle(75, 113, 7, 10); Rectangle valueAt100 = new Rectangle(50, 75, 5, 7); - Rectangle scaledValue = DPIUtil.autoScaleDown(valueAt200); + Rectangle scaledValue = DPIUtil.scaleDown(valueAt200, 100); assertEquals(valueAt100, scaledValue, String.format("Scaling down Rectangle from device zoom (%d) to 100 failed", ZOOM_200)); - scaledValue = DPIUtil.autoScaleDown((Device) null, valueAt200); + scaledValue = DPIUtil.scaleDown((Device) null, valueAt200, 100); assertEquals(valueAt100, scaledValue, String.format( "Scaling down Rectangle from device zoom (%d) to 100 with device failed", ZOOM_200)); @@ -185,43 +103,16 @@ public void scaleDownRectangle() { assertSame(valueAt100, scaledValue, "Scaling down Rectangle without zoom change with device failed"); } - @Test - public void scaleUpIntArray() { - int[] valueAt200 = new int[] { 10, 12, 14 }; - int[] valueAt150 = new int[] { 8, 9, 11 }; - int[] valueAt100 = new int[] { 5, 6, 7 }; - - int[] scaledValue = DPIUtil.autoScaleUp(valueAt100); - assertArrayEquals(valueAt200, scaledValue, - String.format("Scaling up int array to device zoom (%d) to 100 failed", ZOOM_200)); - scaledValue = DPIUtil.autoScaleUp((Device) null, valueAt100); - assertArrayEquals(valueAt200, scaledValue, String - .format("Scaling up int array to device zoom (%d) to 100 with device failed", ZOOM_200)); - - scaledValue = DPIUtil.scaleUp(valueAt100, 200); - assertArrayEquals(valueAt200, scaledValue, "Scaling up int array to 200 failed"); - scaledValue = DPIUtil.scaleUp((Device) null, valueAt100, 200); - assertArrayEquals(valueAt200, scaledValue, "Scaling up int array to 200 with device failed"); - scaledValue = DPIUtil.scaleUp(valueAt100, 150); - assertArrayEquals(valueAt150, scaledValue, "Scaling up int array to 150 failed"); - scaledValue = DPIUtil.scaleUp((Device) null, valueAt100, 150); - assertArrayEquals(valueAt150, scaledValue, "Scaling up int array to 150 with device failed"); - scaledValue = DPIUtil.scaleUp(valueAt100, 100); - assertSame(valueAt100, scaledValue, "Scaling up int array without zoom change failed"); - scaledValue = DPIUtil.scaleUp((Device) null, valueAt100, 100); - assertSame(valueAt100, scaledValue, "Scaling up int array without zoom change with device failed"); - } - @Test public void scaleUpInteger() { int valueAt200 = 10; int valueAt150 = 8; int valueAt100 = 5; - int scaledValue = DPIUtil.autoScaleUp(valueAt100); + int scaledValue = DPIUtil.scaleUp(valueAt100, 100); assertEquals(valueAt200, scaledValue, String.format("Scaling up integer to device zoom (%d) to 100 failed", ZOOM_200)); - scaledValue = DPIUtil.autoScaleUp((Device) null, valueAt100); + scaledValue = DPIUtil.scaleUp((Device) null, valueAt100, 100); assertEquals(valueAt200, scaledValue, String .format("Scaling up integer to device zoom (%d) to 100 with device failed", ZOOM_200)); @@ -245,10 +136,10 @@ public void scaleUpFloat() { float valueAt150 = 7.5f; float valueAt100 = 5; - float scaledValue = DPIUtil.autoScaleUp(valueAt100); + float scaledValue = DPIUtil.scaleUp(valueAt100, 100); assertEquals(valueAt200, scaledValue, 0.001f, String.format("Scaling up integer to device zoom (%d) to 100 failed", ZOOM_200)); - scaledValue = DPIUtil.autoScaleUp((Device) null, valueAt100); + scaledValue = DPIUtil.scaleUp((Device) null, valueAt100, 100); assertEquals(valueAt200, scaledValue, 0.001f, String .format("Scaling up integer to device zoom (%d) to 100 with device failed", ZOOM_200)); @@ -272,10 +163,10 @@ public void scaleUpPoint() { Point valueAt150 = new Point(8, 11); Point valueAt100 = new Point(5, 7); - Point scaledValue = DPIUtil.autoScaleUp(valueAt100); + Point scaledValue = DPIUtil.scaleUp(valueAt100, 100); assertEquals(valueAt200, scaledValue, String.format("Scaling up Point to device zoom (%d) to 100 failed", ZOOM_200)); - scaledValue = DPIUtil.autoScaleUp((Device) null, valueAt100); + scaledValue = DPIUtil.scaleUp((Device) null, valueAt100, 100); assertEquals(valueAt200, scaledValue, String .format("Scaling up Point to device zoom (%d) to 100 with device failed", ZOOM_200)); @@ -299,10 +190,10 @@ public void scaleUpRectangle() { Rectangle valueAt150 = new Rectangle(75, 113, 8, 10); Rectangle valueAt100 = new Rectangle(50, 75, 5, 7); - Rectangle scaledValue = DPIUtil.autoScaleUp(valueAt100); + Rectangle scaledValue = DPIUtil.scaleUp(valueAt100, 100); assertEquals(valueAt200, scaledValue, String.format("Scaling up Rectangle to device zoom (%d) to 100 failed", ZOOM_200)); - scaledValue = DPIUtil.autoScaleUp((Device) null, valueAt100); + scaledValue = DPIUtil.scaleUp((Device) null, valueAt100, 100); assertEquals(valueAt200, scaledValue, String .format("Scaling up Rectangle to device zoom (%d) to 100 with device failed", ZOOM_200)); diff --git a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_Image.java b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_Image.java index eceef1c959..dc7cb2f84e 100644 --- a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_Image.java +++ b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_Image.java @@ -598,7 +598,7 @@ public void test_getBoundsInPixels() { Rectangle bounds = image.getBounds(); image.dispose(); assertEquals("Image.getBounds method doesn't return original bounds.", initialBounds, bounds); - assertEquals("Image.getBoundsInPixels method doesn't return bounds in Pixel values.", DPIUtil.autoScaleUp(initialBounds), boundsInPixels); + assertEquals("Image.getBoundsInPixels method doesn't return bounds in Pixel values.", DPIUtil.scaleUp(initialBounds, 100), boundsInPixels); // create icon image ImageData imageData = new ImageData(initialBounds.width, initialBounds.height, 1, new PaletteData(new RGB[] {new RGB(0, 0, 0)})); @@ -607,21 +607,21 @@ public void test_getBoundsInPixels() { bounds = image.getBounds(); image.dispose(); assertEquals("Image.getBounds method doesn't return original bounds.", initialBounds, bounds); - assertEquals("Image.getBoundsInPixels method doesn't return bounds in Pixel values.", DPIUtil.autoScaleUp(initialBounds), boundsInPixels); + assertEquals("Image.getBoundsInPixels method doesn't return bounds in Pixel values.", DPIUtil.scaleUp(initialBounds, 100), boundsInPixels); // create image with FileNameProvider image = new Image(display, imageFileNameProvider); boundsInPixels = image.getBoundsInPixels(); bounds = image.getBounds(); image.dispose(); - assertEquals("Image.getBoundsInPixels method doesn't return bounds in Pixel values.", DPIUtil.autoScaleUp(bounds), boundsInPixels); + assertEquals("Image.getBoundsInPixels method doesn't return bounds in Pixel values.", DPIUtil.scaleUp(bounds, 100), boundsInPixels); // create image with ImageDataProvider image = new Image(display, imageDataProvider); boundsInPixels = image.getBoundsInPixels(); bounds = image.getBounds(); image.dispose(); - assertEquals("Image.getBoundsInPixels method doesn't return bounds in Pixel values.", DPIUtil.autoScaleUp(bounds), boundsInPixels); + assertEquals("Image.getBoundsInPixels method doesn't return bounds in Pixel values.", DPIUtil.scaleUp(bounds, 100), boundsInPixels); // create image with ImageGcDrawer image = new Image(display, imageGcDrawer, initialBounds.width, initialBounds.height); @@ -629,7 +629,7 @@ public void test_getBoundsInPixels() { bounds = image.getBounds(); image.dispose(); assertEquals("Image.getBounds method doesn't return original bounds.", initialBounds, bounds); - assertEquals("Image.getBoundsInPixels method doesn't return bounds in Pixel values for ImageGcDrawer.", DPIUtil.autoScaleUp(initialBounds), boundsInPixels); + assertEquals("Image.getBoundsInPixels method doesn't return bounds in Pixel values for ImageGcDrawer.", DPIUtil.scaleUp(initialBounds, 100), boundsInPixels); } @SuppressWarnings("deprecation") @@ -647,7 +647,7 @@ public void test_getImageDataCurrentZoom() { ImageData imageDataAtCurrentZoom = image.getImageDataAtCurrentZoom(); image.dispose(); Rectangle boundsAtCurrentZoom = new Rectangle(0, 0, imageDataAtCurrentZoom.width, imageDataAtCurrentZoom.height); - assertEquals(":a: Size of ImageData returned from Image.getImageDataAtCurrentZoom method doesn't return matches with bounds in Pixel values.", boundsAtCurrentZoom, DPIUtil.autoScaleUp(bounds)); + assertEquals(":a: Size of ImageData returned from Image.getImageDataAtCurrentZoom method doesn't return matches with bounds in Pixel values.", boundsAtCurrentZoom, DPIUtil.scaleUp(bounds, 100)); // create icon image and compare size of imageData ImageData imageData = new ImageData(bounds.width, bounds.height, 1, new PaletteData(new RGB[] {new RGB(0, 0, 0)})); @@ -655,7 +655,7 @@ public void test_getImageDataCurrentZoom() { imageDataAtCurrentZoom = image.getImageDataAtCurrentZoom(); image.dispose(); boundsAtCurrentZoom = new Rectangle(0, 0, imageDataAtCurrentZoom.width, imageDataAtCurrentZoom.height); - assertEquals(":b: Size of ImageData returned from Image.getImageDataAtCurrentZoom method doesn't return matches with bounds in Pixel values.", boundsAtCurrentZoom, DPIUtil.autoScaleUp(bounds)); + assertEquals(":b: Size of ImageData returned from Image.getImageDataAtCurrentZoom method doesn't return matches with bounds in Pixel values.", boundsAtCurrentZoom, DPIUtil.scaleUp(bounds, 100)); // create image with FileNameProvider image = new Image(display, imageFileNameProvider); @@ -663,7 +663,7 @@ public void test_getImageDataCurrentZoom() { boundsAtCurrentZoom = new Rectangle(0, 0, imageDataAtCurrentZoom.width, imageDataAtCurrentZoom.height); bounds = image.getBounds(); image.dispose(); - assertEquals(":c: Size of ImageData returned from Image.getImageDataAtCurrentZoom method doesn't return matches with bounds in Pixel values.", boundsAtCurrentZoom, DPIUtil.autoScaleUp(bounds)); + assertEquals(":c: Size of ImageData returned from Image.getImageDataAtCurrentZoom method doesn't return matches with bounds in Pixel values.", boundsAtCurrentZoom, DPIUtil.scaleUp(bounds, 100)); // create image with ImageDataProvider image = new Image(display, imageDataProvider); @@ -671,7 +671,7 @@ public void test_getImageDataCurrentZoom() { boundsAtCurrentZoom = new Rectangle(0, 0, imageDataAtCurrentZoom.width, imageDataAtCurrentZoom.height); bounds = image.getBounds(); image.dispose(); - assertEquals(":d: Size of ImageData returned from Image.getImageDataAtCurrentZoom method doesn't return matches with bounds in Pixel values.", boundsAtCurrentZoom, DPIUtil.autoScaleUp(bounds)); + assertEquals(":d: Size of ImageData returned from Image.getImageDataAtCurrentZoom method doesn't return matches with bounds in Pixel values.", boundsAtCurrentZoom, DPIUtil.scaleUp(bounds, 100)); } @Test