diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Device.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Device.java index ef30e780765..39e2b8283d4 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Device.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Device.java @@ -14,7 +14,7 @@ package org.eclipse.swt.graphics; import org.eclipse.swt.*; -import org.eclipse.swt.internal.ExceptionStash; +import org.eclipse.swt.internal.*; import org.eclipse.swt.internal.cocoa.*; /** @@ -244,7 +244,7 @@ public void dispose () { } destroy (); - disposed = true; + disposed = true; if (tracking) { synchronized (trackingLock) { printErrors (); @@ -391,7 +391,18 @@ public int getDepth () { * @exception SWTException + * + * @deprecated

This method returns a single global DPI value + * that does not reflect per-monitor DPI settings on modern operating systems. + * In environments with different scaling factors across monitors, it may provide + * a misleading or meaningless result, as it does not correspond to the actual DPI + * of any specific monitor.

+ * + *

Note: While deprecated for general {@code Device} instances like {@code Display}, + * this method may still be validly used when called on a {@code Printer} instance, + * where a single global DPI value is meaningful and expected.

*/ +@Deprecated public Point getDPI () { checkDevice (); return getScreenDPI(); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Device.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Device.java index 50996db4673..23ed27a6c87 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Device.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Device.java @@ -455,7 +455,18 @@ public int getDepth () { * @exception SWTException + * + * @deprecated

This method returns a single global DPI value + * that does not reflect per-monitor DPI settings on modern operating systems. + * In environments with different scaling factors across monitors, it may provide + * a misleading or meaningless result, as it does not correspond to the actual DPI + * of any specific monitor.

+ * + *

Note: While deprecated for general {@code Device} instances like {@code Display}, + * this method may still be validly used when called on a {@code Printer} instance, + * where a single global DPI value is meaningful and expected.

*/ +@Deprecated public Point getDPI () { checkDevice (); return getScreenDPI(); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Device.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Device.java index 887218f7c36..f929f6ab932 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Device.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Device.java @@ -521,7 +521,18 @@ public int getDepth () { * @exception SWTException + * + * @deprecated

This method returns a single global DPI value + * that does not reflect per-monitor DPI settings on modern operating systems. + * In environments with different scaling factors across monitors, it may provide + * a misleading or meaningless result, as it does not correspond to the actual DPI + * of any specific monitor.

+ * + *

Note: While deprecated for general {@code Device} instances like {@code Display}, + * this method may still be validly used when called on a {@code Printer} instance, + * where a single global DPI value is meaningful and expected.

*/ +@Deprecated public Point getDPI () { checkDevice (); long hDC = internal_new_GC (null); diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/imageanalyzer/ImageAnalyzer.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/imageanalyzer/ImageAnalyzer.java index 5daa74431ee..504316ff6f5 100644 --- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/imageanalyzer/ImageAnalyzer.java +++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/imageanalyzer/ImageAnalyzer.java @@ -1165,6 +1165,7 @@ void menuPrint() { if (image == null) return; try { + final int DOTS_PER_INCH = 96; // Ask the user to specify the printer. PrintDialog dialog = new PrintDialog(shell, SWT.NONE); if (printerData != null) dialog.setPrinterData(printerData); @@ -1172,9 +1173,8 @@ void menuPrint() { if (printerData == null) return; Printer printer = new Printer(printerData); - Point screenDPI = display.getDPI(); Point printerDPI = printer.getDPI(); - int scaleFactor = printerDPI.x / screenDPI.x; + int scaleFactor = printerDPI.x / DOTS_PER_INCH; Rectangle trim = printer.computeTrim(0, 0, 0, 0); if (printer.startJob(currentName)) { if (printer.startPage()) { diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet361.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet361.java index 56ef65dbeaa..3423008bc82 100644 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet361.java +++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet361.java @@ -146,6 +146,7 @@ public void getName(AccessibleEvent e) { } private static void performPrintAction(final Display display, final Shell shell) { + final int DOTS_PER_INCH = 96; Rectangle r = composite.getBounds(); Point p = shell.toDisplay(r.x, r.y); org.eclipse.swt.graphics.Image snapshotImage @@ -159,9 +160,8 @@ private static void performPrintAction(final Display display, final Shell shell) data = dialog.open(); if (data != null) { Printer printer = new Printer(data); - Point screenDPI = display.getDPI(); Point printerDPI = printer.getDPI(); - int scaleFactor = printerDPI.x / screenDPI.x; + int scaleFactor = printerDPI.x / DOTS_PER_INCH; Rectangle trim = printer.computeTrim(0, 0, 0, 0); if (printer.startJob("Print Image")) { ImageData imageData = snapshotImage.getImageData(); diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet367.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet367.java index 54b53dc1d39..8e5b7c2f7d7 100644 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet367.java +++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet367.java @@ -185,7 +185,7 @@ public int getGcStyle() { createSeparator(shell); - new Label (shell, SWT.NONE).setText ("5. 50x50 box\n(Display#getDPI(): " + display.getDPI().x + ")"); + new Label (shell, SWT.NONE).setText ("5. 50x50 box"); Label box= new Label (shell, SWT.NONE); box.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW)); box.setLayoutData (new GridData (50, 50)); diff --git a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Display.java b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Display.java index c66d1ccc7c1..05fdb3a2444 100644 --- a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Display.java +++ b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Display.java @@ -1573,6 +1573,7 @@ public void test_wake() { /* custom */ boolean disposeExecRan; +@SuppressWarnings("deprecation") @Test public void test_getDPI() { Display display = new Display();