From 33a25304bf9d2d78e57f98cd306d4e41fe2d96dd Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Tue, 18 Jul 2017 17:25:25 +0200 Subject: [PATCH] Hi-DPI: tentative auto DPI detection for Linux See #6472 #4376 --- .../src/processing/app/linux/Platform.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/arduino-core/src/processing/app/linux/Platform.java b/arduino-core/src/processing/app/linux/Platform.java index b91de378105..8c507234795 100644 --- a/arduino-core/src/processing/app/linux/Platform.java +++ b/arduino-core/src/processing/app/linux/Platform.java @@ -25,8 +25,11 @@ import processing.app.PreferencesData; import processing.app.legacy.PConstants; +import java.awt.Font; import java.io.File; +import javax.swing.UIManager; + /** * Used by Base for platform-specific tweaking, for instance finding the @@ -117,4 +120,19 @@ public void openFolder(File file) throws Exception { public String getName() { return PConstants.platformNames[PConstants.LINUX]; } + + private int detectedDpi = -1; + + @Override + public int getSystemDPI() { + if (detectedDpi != -1) + return detectedDpi; + + // we observed that JMenu fonts in java follows the + // System DPI settings, so we compare it to the standard + // font size (12) to obtain a rough estimate of DPI. + Font menuFont = UIManager.getFont("Menu.font"); + detectedDpi = menuFont.getSize() * 96 / 12; + return detectedDpi; + } }