Skip to content

Commit ed40940

Browse files
ShahzaibIbrahimazoitl
authored andcommitted
Replacing usages of Device#getDPI
Having the scale factor being based on the screen DPI leads to unexpected result. Having a screen dpi independent factor leads to consistent results.
1 parent b385e10 commit ed40940

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

org.eclipse.draw2d.examples/sandbox/swt/bugs/Bug81467.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515
import org.eclipse.swt.graphics.Font;
1616
import org.eclipse.swt.graphics.GC;
1717
import org.eclipse.swt.printing.Printer;
18-
import org.eclipse.swt.widgets.Display;
1918

2019
import org.eclipse.draw2d.PrinterGraphics;
2120
import org.eclipse.draw2d.SWTGraphics;
2221

2322
public class Bug81467 {
2423

2524
public static void main(String[] args) {
25+
final float DOTS_PER_INCH = 96.0f;
2626
Font font = new Font(null, "Helvetica", 12, 0); //$NON-NLS-1$
2727
Printer printer = new Printer();
2828
printer.startJob("bugzilla 81467"); //$NON-NLS-1$
@@ -31,7 +31,7 @@ public static void main(String[] args) {
3131
SWTGraphics graphics = new SWTGraphics(gc);
3232
PrinterGraphics printGraphics = new PrinterGraphics(graphics, printer);
3333

34-
printGraphics.scale((double) printer.getDPI().x / Display.getDefault().getDPI().x);
34+
printGraphics.scale(printer.getDPI().x / DOTS_PER_INCH);
3535
printGraphics.setFont(font);
3636
printGraphics.drawString("Hello world", 50, 50); //$NON-NLS-1$
3737
printGraphics.dispose();

org.eclipse.gef/src/org/eclipse/gef/internal/ui/rulers/RulerFigure.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
package org.eclipse.gef.internal.ui.rulers;
1414

1515
import org.eclipse.swt.SWT;
16-
import org.eclipse.swt.widgets.Display;
1716

1817
import org.eclipse.draw2d.ColorConstants;
1918
import org.eclipse.draw2d.Figure;
@@ -52,6 +51,7 @@ public class RulerFigure extends Figure {
5251
* paintFigure(Graphics) method.
5352
*/
5453
private static final int BORDER_WIDTH = 3;
54+
private static final float DOTS_PER_INCH = 96.0f;
5555

5656
private boolean horizontal;
5757
private int unit;
@@ -78,7 +78,7 @@ protected double getDPU() {
7878
case RulerProvider.UNIT_PIXELS -> dpu = 1.0;
7979
case RulerProvider.UNIT_CUSTOM -> dpu = rulerProvider.getCustomRulerDPU();
8080
default -> {
81-
dpu = transposer.t(new Dimension(Display.getCurrent().getDPI())).height;
81+
dpu = DOTS_PER_INCH;
8282
if (getUnit() == RulerProvider.UNIT_CENTIMETERS) {
8383
dpu = dpu / 2.54;
8484
}

0 commit comments

Comments
 (0)