question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Scaled Fonts and Icons should be supported for Ribbons

See original GitHub issue

Version 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:

UnscaledFonts

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: SomeFontsScaled

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:closed
  • Created 2 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
kirill-grouchnikovcommented, Nov 7, 2021

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.

1reaction
kirill-grouchnikovcommented, Nov 9, 2021

The crash in checkResizePoliciesConsistency has been addressed

Read more comments on GitHub >

github_iconTop Results From Across the Web

Icons & Text on Ribbon too large in Outlook
Icons & Text on Ribbon too large in Outlook. How can I adjust the icon and text size on the ribbon in Outlook...
Read more >
How to change Ribbon font size in Outlook in windows 7/8/10?
If you are currently working in Windows 7, you can change the Ribbon font size in Outlook with following steps: Step 1: Go...
Read more >
Change Ribbon Icon & Font Size - Greg Maxey
The size of your ribbon icons and font is determined primarily by your screen resolution. If you change the resolution, everything (i.e., ribbon...
Read more >
How to Make Fonts & Icons in Outlook Smaller
Click the "Make Text and Other Items Larger or Smaller" link. You can choose the default display size of most Windows user interface...
Read more >
Change ribbon menu and pathfinder fonts - ST6 and WIN7
Change ribbon menu and pathfinder fonts - ST6 and WIN7 ... icon font size.jpg ... Aside from that, you can use the Windows...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found