Scaled Fonts and Icons should be supported for Ribbons
See original GitHub issueVersion of Radiance (latest release is 5.0.0)
5.0.0
Sub-project (Common, Animation, Theming, Component, …)
Component
Version of Java (current minimum is 9)
11
Version of OS
Linux Mint 20.1
The issue you’re experiencing (expected vs actual, screenshot, stack trace etc)
I develop Open Source Mind Map Editor Freeplane, https://sourceforge.net/projects/freeplane/ https://github.com/freeplane/freeplane
Currently, we are evaluating if we can improve its usability by replacing old school menus and toolbars with ribbon UI.
To support HiDPI monitors Freeplane lets user to set its monitor size and replaces all fonts by fonts with bigger sizes. The sizes are calculated from monitor size entered by a user and monitor resolution available from graphics environment. This solution works on all OS (Linux, MacOS, Windows) and with all Java versions. Java’s own HiDpi support introduced with Java 9 for Linux and Windows seems to support only integer number scaling factors (1, 2 or 3). The solution used in Freeplane calculates all font sizes so that effectively it allows more steps in between.
So I tried to check how the latest Radiance Ribbon works with changed UI fonts by modifying BasicCheckRibbon from the component demo used as a starting point.
Unscaled fonts looked very small:
At first I fixed all Java UI fonts similar to Freeplane as follows:
private static void scaleDefaultUIFonts(double scalingFactor) {
Set<Object> keySet = UIManager.getLookAndFeelDefaults().keySet();
Set<Font> scaledFonts = new HashSet<>();
Object[] keys = keySet.toArray(new Object[keySet.size()]);
final UIDefaults uiDefaults = UIManager.getDefaults();
final UIDefaults lookAndFeelDefaults = UIManager.getLookAndFeel().getDefaults();
for (Object key : keys) {
if (isFontKey(key)) {
Font font = uiDefaults.getFont(key);
if (font != null && ! scaledFonts.contains(font)) {
font = scaleFontInt(font, scalingFactor);
UIManager.put(key, font);
lookAndFeelDefaults.put(key, font);
scaledFonts.add(font);
}
}
}
}
private static boolean isFontKey(Object key) {
return key != null && key.toString().toLowerCase().endsWith("font");
}
public static Font scaleFontInt(Font font, double additionalFactor) {
return font.deriveFont(font.getStyle(), Math.round(font.getSize2D() * additionalFactor));
}
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> {
scaleDefaultUIFonts(1.6);
JFrame.setDefaultLookAndFeelDecorated(true);
RadianceThemingCortex.GlobalScope.setSkin(new GeminiSkin());
Some fonts became scaled, but not all of them:
I discovered that font sizes of the other fonts are controlled by font policies and tried to add
RadianceThemingCortex.GlobalScope.setFontPolicy(RadianceCommonCortex.getScaledFontPolicy(1.6f));
at the end of the last code fragment.
In this configuration, Radiance threw an exception
Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException: Inconsistent preferred widths
Ribbon band 'Document' has the following resize policies
org.pushingpixels.radiance.component.api.ribbon.resize.CoreRibbonResizePolicies$Mirror with preferred width 586
org.pushingpixels.radiance.component.api.ribbon.resize.CoreRibbonResizePolicies$Mid2Low with preferred width 298
org.pushingpixels.radiance.component.api.ribbon.resize.CoreRibbonResizePolicies$High2Mid with preferred width 183
org.pushingpixels.radiance.component.api.ribbon.resize.CoreRibbonResizePolicies$High2Low with preferred width 104
org.pushingpixels.radiance.component.api.ribbon.resize.CoreRibbonResizePolicies$IconRibbonBandResizePolicy with preferred width 111
org.pushingpixels.radiance.component.api.ribbon.resize.CoreRibbonResizePolicies$High2Low with pref width 104 is followed by resize policy org.pushingpixels.radiance.component.api.ribbon.resize.CoreRibbonResizePolicies$IconRibbonBandResizePolicy with larger pref width
I tried to analyze the code and found that Command Button Preferred Sizes are calculated using hardcoded numbers e.g.
@Override
public int getPreferredIconSize(JCommandButton commandButton) {
return ComponentUtilities.getScaledSize(32, commandButton.getFont().getSize(), 2.0f, 4);
}
It means that currently icon and font sizes can only be scaled by factor of 2 under Linux using -Dsun.java2d.uiScale=2, but fractional scaling is not supported for Linux and MacOS, only for Windows.
Are there chances it could be improved on the radiance side? Could we work on this issue together?
Best regards, Dimitry
Issue Analytics
- State:
- Created 2 years ago
- Comments:10 (6 by maintainers)
Top GitHub Comments
Development of version 6.0 starts tomorrow. Here’s what I’m going to start with on this issue.
I’ll add a slider to some of the component demos (command buttons, command button strips, and the main ribbon demo). The slider will change the font policy with
RadianceCommonCortex.getScaledFontPolicy
on a sliding scale from 1.0 to let’s say 3.0, with stops at every 0.1. Whatever layout bugs get found along the way, will be addressed starting from the lowest level - the command buttons, and then going “up the stack” so to speak, to command button strips, command button panels and the various parts of the ribbon.The crash in
checkResizePoliciesConsistency
has been addressed