From 4f4a3132c523c2b19d6f55dbddf9beaa1805b573 Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Wed, 4 Dec 2024 13:06:11 +0100 Subject: [PATCH] UIScale: - do not use "defaultFont" if current Laf is not FlatLaf - support custom font size divider to calculate user scale factor from font size (for special use in JFormDesigner) --- .../java/com/formdev/flatlaf/util/UIScale.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/util/UIScale.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/util/UIScale.java index f318d8ef..01c17ab6 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/util/UIScale.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/util/UIScale.java @@ -33,6 +33,7 @@ import javax.swing.plaf.DimensionUIResource; import javax.swing.plaf.FontUIResource; import javax.swing.plaf.InsetsUIResource; import javax.swing.plaf.UIResource; +import com.formdev.flatlaf.FlatLaf; import com.formdev.flatlaf.FlatSystemProperties; /** @@ -188,7 +189,9 @@ public class UIScale // because even if we are on a HiDPI display it is not sure // that a larger font size is set by the current LaF // (e.g. can avoid large icons with small text) - Font font = UIManager.getFont( "defaultFont" ); + Font font = null; + if( UIManager.getLookAndFeel() instanceof FlatLaf ) + font = UIManager.getFont( "defaultFont" ); if( font == null ) font = UIManager.getFont( "Label.font" ); @@ -244,6 +247,16 @@ public class UIScale } private static float computeScaleFactor( Font font ) { + String customFontSizeDivider = System.getProperty( "flatlaf.uiScale.fontSizeDivider" ); + if( customFontSizeDivider != null ) { + try { + float fontSizeDivider = Math.max( Integer.parseInt( customFontSizeDivider ), 10 ); + return font.getSize() / fontSizeDivider; + } catch( NumberFormatException ex ) { + // ignore + } + } + // default font size float fontSizeDivider = 12f;