diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatSystemProperties.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatSystemProperties.java index 5397983a..74950ad1 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatSystemProperties.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatSystemProperties.java @@ -16,6 +16,8 @@ package com.formdev.flatlaf; +import com.formdev.flatlaf.util.UIScale; + /** * Defines/documents own system properties used in FlatLaf. * @@ -32,6 +34,8 @@ public interface FlatSystemProperties * To replace the Java 9+ system scale factor, use system property "sun.java2d.uiScale", * which has the same syntax as this one. *

+ * Since FlatLaf 1.1.2: Scale factors less then 100% are allowed. + *

* Allowed Values e.g. {@code 1.5}, {@code 1.5x}, {@code 150%} or {@code 144dpi} (96dpi is 100%)
*/ String UI_SCALE = "flatlaf.uiScale"; @@ -44,6 +48,17 @@ public interface FlatSystemProperties */ String UI_SCALE_ENABLED = "flatlaf.uiScale.enabled"; + /** + * Specifies whether values smaller than 100% are allowed for the user scale factor + * (see {@link UIScale#getUserScaleFactor()}). + *

+ * Allowed Values {@code false} and {@code true}
+ * Default {@code false} + * + * @since 1.1.2 + */ + String UI_SCALE_ALLOW_SCALE_DOWN = "flatlaf.uiScale.allowScaleDown"; + /** * Specifies whether Ubuntu font should be used on Ubuntu Linux. * By default, if not running in a JetBrains Runtime, the Liberation Sans font 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 d2e9c269..258adc57 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 @@ -180,7 +180,7 @@ public class UIScale // apply custom scale factor specified in system property "flatlaf.uiScale" float customScaleFactor = getCustomScaleFactor(); if( customScaleFactor > 0 ) { - setUserScaleFactor( customScaleFactor ); + setUserScaleFactor( customScaleFactor, false ); return; } @@ -230,7 +230,7 @@ public class UIScale } else newScaleFactor = computeScaleFactor( font ); - setUserScaleFactor( newScaleFactor ); + setUserScaleFactor( newScaleFactor, true ); } private static float computeScaleFactor( Font font ) { @@ -274,7 +274,7 @@ public class UIScale if( scaleFactor == fontScaleFactor ) return font; - int newFontSize = Math.round( (font.getSize() / fontScaleFactor) * scaleFactor ); + int newFontSize = Math.max( Math.round( (font.getSize() / fontScaleFactor) * scaleFactor ), 1 ); return new FontUIResource( font.deriveFont( (float) newFontSize ) ); } @@ -322,11 +322,18 @@ public class UIScale /** * Sets the user scale factor. */ - private static void setUserScaleFactor( float scaleFactor ) { - if( scaleFactor <= 1f ) - scaleFactor = 1f; - else // round scale factor to 1/4 - scaleFactor = Math.round( scaleFactor * 4f ) / 4f; + private static void setUserScaleFactor( float scaleFactor, boolean normalize ) { + if( normalize ) { + if( scaleFactor < 1f ) { + scaleFactor = FlatSystemProperties.getBoolean( FlatSystemProperties.UI_SCALE_ALLOW_SCALE_DOWN, false ) + ? Math.round( scaleFactor * 10f ) / 10f // round small scale factor to 1/10 + : 1f; + } else if( scaleFactor > 1f ) // round scale factor to 1/4 + scaleFactor = Math.round( scaleFactor * 4f ) / 4f; + } + + // minimum scale factor + scaleFactor = Math.max( scaleFactor, 0.1f ); float oldScaleFactor = UIScale.scaleFactor; UIScale.scaleFactor = scaleFactor;