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 14b76e86..702f5789 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"; @@ -43,14 +47,17 @@ public interface FlatSystemProperties * Default {@code true} */ String UI_SCALE_ENABLED = "flatlaf.uiScale.enabled"; - - /** - * Specifies whether values smaller than 1.0f are allowed for the custom scale factor. + + /** + * 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_DOWNSCALE_ENABLED = "flatlaf.uiDowncale.enabled"; + String UI_SCALE_ALLOW_SCALE_DOWN = "flatlaf.uiScale.allowScaleDown"; /** * Specifies whether Ubuntu font should be used on Ubuntu Linux. 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 53a539c8..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 ) { @@ -257,10 +257,6 @@ public class UIScale private static boolean isUserScalingEnabled() { return FlatSystemProperties.getBoolean( FlatSystemProperties.UI_SCALE_ENABLED, true ); } - - private static boolean isDownscalingEnabled() { - return FlatSystemProperties.getBoolean( FlatSystemProperties.UI_DOWNSCALE_ENABLED, false ); - } /** * Applies a custom scale factor given in system property "flatlaf.uiScale" @@ -278,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 ) ); } @@ -326,11 +322,18 @@ public class UIScale /** * Sets the user scale factor. */ - private static void setUserScaleFactor( float scaleFactor ) { - if( ( !isDownscalingEnabled() && scaleFactor <= 1f ) || scaleFactor <= 0f ) - 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;