Skip to content

Deprecating Device#getDPI #2260

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2037,6 +2037,12 @@ public int getIconDepth () {
};
}

@Deprecated
@Override
public Point getDPI () {
return super.getDPI();
}

ImageList getImageList (int style, int width, int height, int zoom) {
if (imageList == null) imageList = new ImageList [4];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1172,9 +1172,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 / 100;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wasn't Display:getDPI always returning 96?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it depends on the display. Sometimes 144 or 96 or depending on the monitor. We then decided to use 100 as the base consistent value to calculate the scaleFactor like we did here: https://github.com/eclipse-platform/eclipse.platform.swt/pull/1802/files

Rectangle trim = printer.computeTrim(0, 0, 0, 0);
if (printer.startJob(currentName)) {
if (printer.startPage()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,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 / 100;
Rectangle trim = printer.computeTrim(0, 0, 0, 0);
if (printer.startJob("Print Image")) {
ImageData imageData = snapshotImage.getImageData();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1573,6 +1573,7 @@ public void test_wake() {
/* custom */
boolean disposeExecRan;

@SuppressWarnings("deprecation")
@Test
public void test_getDPI() {
Display display = new Display();
Expand Down
Loading