Skip to content

Alternative to Device.getDPI() ? #2925

@Phillipus

Description

@Phillipus

Now that Device.getDPI() is deprecated what is the recommended way to get the current display DPI?

42c3226 and #2872

In our RCP app we call Device.getDPI() like this for scaling fonts depending on OS:

int DPI = Display.getCurrent().getDPI().y;
FontData fd = new FontData("fontname");
float factor = (float)96 / DPI;
int newHeight = (int)(fd.getHeight() * factor);
fd.setHeight(newHeight);

In earlier versions of SWT Device.getDPI() would return different values on Windows depending on scale:

225% = 108 DPI
200% = 96 DPI
175% = 84 DPI
150% = 144 DPI
125% = 120 DPI
100% = 96 DPI

It seems that in recent versions of SWT the DPI on Windows is always returned as 96 so that makes things easier.

But what about Mac? That can be 72 DPI or perhaps something else. What is the recommended way to determine DPI?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions