Skip to content

Commit a8605ae

Browse files
Deprecating Device#getDPI
Having the scale factor being based on the screen DPI leads to unexpected result e.g. Image too big/small. Having a screen dpi independent factor leads to consistent results
1 parent 51fed8e commit a8605ae

File tree

5 files changed

+10
-5
lines changed

5 files changed

+10
-5
lines changed

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2037,6 +2037,12 @@ public int getIconDepth () {
20372037
};
20382038
}
20392039

2040+
@Deprecated
2041+
@Override
2042+
public Point getDPI () {
2043+
return super.getDPI();
2044+
}
2045+
20402046
ImageList getImageList (int style, int width, int height, int zoom) {
20412047
if (imageList == null) imageList = new ImageList [4];
20422048

examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/imageanalyzer/ImageAnalyzer.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,9 +1172,8 @@ void menuPrint() {
11721172
if (printerData == null) return;
11731173

11741174
Printer printer = new Printer(printerData);
1175-
Point screenDPI = display.getDPI();
11761175
Point printerDPI = printer.getDPI();
1177-
int scaleFactor = printerDPI.x / screenDPI.x;
1176+
int scaleFactor = printerDPI.x / 100;
11781177
Rectangle trim = printer.computeTrim(0, 0, 0, 0);
11791178
if (printer.startJob(currentName)) {
11801179
if (printer.startPage()) {

examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet361.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,8 @@ private static void performPrintAction(final Display display, final Shell shell)
159159
data = dialog.open();
160160
if (data != null) {
161161
Printer printer = new Printer(data);
162-
Point screenDPI = display.getDPI();
163162
Point printerDPI = printer.getDPI();
164-
int scaleFactor = printerDPI.x / screenDPI.x;
163+
int scaleFactor = printerDPI.x / 100;
165164
Rectangle trim = printer.computeTrim(0, 0, 0, 0);
166165
if (printer.startJob("Print Image")) {
167166
ImageData imageData = snapshotImage.getImageData();

examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet367.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ public int getGcStyle() {
185185

186186
createSeparator(shell);
187187

188-
new Label (shell, SWT.NONE).setText ("5. 50x50 box\n(Display#getDPI(): " + display.getDPI().x + ")");
188+
new Label (shell, SWT.NONE).setText ("5. 50x50 box");
189189
Label box= new Label (shell, SWT.NONE);
190190
box.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW));
191191
box.setLayoutData (new GridData (50, 50));

tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Display.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1573,6 +1573,7 @@ public void test_wake() {
15731573
/* custom */
15741574
boolean disposeExecRan;
15751575

1576+
@SuppressWarnings("deprecation")
15761577
@Test
15771578
public void test_getDPI() {
15781579
Display display = new Display();

0 commit comments

Comments
 (0)