added a plausibility check to the dpi calculation

This commit is contained in:
hneemann 2017-06-07 13:36:07 +02:00
parent 6606a7aae0
commit 1b032b7975

View File

@ -372,7 +372,16 @@ public final class Keys {
private static int getDefaultScreenResolution() {
try {
return Toolkit.getDefaultToolkit().getScreenResolution();
int dpi = Toolkit.getDefaultToolkit().getScreenResolution();
// plausibility check
int widthInPixel = Toolkit.getDefaultToolkit().getScreenSize().width;
int widthInInch = widthInPixel / dpi;
// most people don't use a screen larger than 27 inch, so the resolution is presumably wrong
if (widthInInch > 27)
dpi = widthInPixel / 27;
return dpi;
} catch (HeadlessException e) {
return 95;
}