Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Text appears oversized on Elementary OS Linux distribution #427

Closed
dprietob opened this issue Nov 17, 2021 · 4 comments
Closed

Text appears oversized on Elementary OS Linux distribution #427

dprietob opened this issue Nov 17, 2021 · 4 comments
Milestone

Comments

@dprietob
Copy link

I dont know if this bug appears on others Linux distributions, but specifically on Elementary OS 6, button texts and labels appears oversized:

oversized

This issue not occur when Metal or Nimbus LAFs (for example) are configured:

metal
nimbus

I thought the error might be because canberra-gtk module was missing on my system (it was the only console error I had while debugging), but I installed it and the result is still the same.

Some idea about what's happening?

@DevCharly
Copy link
Collaborator

For some reason, the computed font size is too large 😕

Nimbus and Metal use fixed size fonts (which may result in too small text if screen is scaled).
FlatLaf uses the same approach as GTKLookAndFeel to compute a "useful" font size.

Do you have the also too large font when using GTKLookAndFeel?
Which Java version do you use?

To better understand the problem, can you please run the following program and post the output?

import java.awt.*;
import javax.swing.*;
import com.formdev.flatlaf.FlatLightLaf;

public class FlatLinuxFontInfo
{
    public static void main( String[] args ) {
        SwingUtilities.invokeLater( () -> {
            System.out.println( "Java version:   " + System.getProperty( "java.version" ) );
            System.out.println( "Java vendor:    " + System.getProperty( "java.vendor" ) );

            System.out.println( "Gtk FontName:   " + Toolkit.getDefaultToolkit().getDesktopProperty( "gnome.Gtk/FontName" ) );
            System.out.println( "Xft DPI:        " + Toolkit.getDefaultToolkit().getDesktopProperty( "gnome.Xft/DPI" ) );
            System.out.println( "Transform:      " + GraphicsEnvironment.getLocalGraphicsEnvironment()
                .getDefaultScreenDevice().getDefaultConfiguration()
                .getNormalizingTransform() );

            FlatLightLaf.setup();
            System.out.println( "Default Font:   " + UIManager.getFont( "defaultFont" ) );
        } );
    }
}

@DevCharly
Copy link
Collaborator

Could you please also run FlatScreenInfo and post the output?
(This is a single-file program that can be compiled/run without any other FlatLaf code or dependencies.
Since Java 11, you can run this program from source with: java FlatScreenInfo.java)

Thanks.

@dprietob
Copy link
Author

dprietob commented Nov 18, 2021

Hi! Thanks to answering so quickly.

I think this errors its caused by my JDK version. When I opened this issue, I had Oracle's JDK 17 installed on my system and my app looks like this when I forced GTK LAF:

gtk_oracle

Due to some errors trying execute FlatScreenInfo on terminal, I changed JDK 17 from Oracle to OpenJDK 17, and...

gtk_openjdk

This is how my app looks like now with GTK LAF running with OpenJDK, and this is how looks like with FlatLAF (dark theme):

flatlaf_openjdk

I send you the info shown by FlatScreenInfo and FlatLinuxFontInfo running on Oracle's JDK and on OpenJDK if it helps you (both version show the same):

FlatScreenInfo

Scale factors:  100%
Java version:   17.0.1
Java vendor:    Oracle Corporation

ID:      :0.0 (main)
Size:    1920 x 1080 / -1 Bit / 60 Hz
Bounds:  1920 x 1080 / x 0 / y 0
Insets:  left 0 / right 0 / top 30 / bottom 0
Scale:   1.0

FlatLinuxFontInfo

Java version:   17.0.1
Java vendor:    Oracle Corporation
Gtk FontName:   Inter 9
Xft DPI:        98304
Transform:      AffineTransform[[1.333333333333333, 0.0, 0.0], [0.0, 1.336842105263158, 0.0]]
Default Font:   javax.swing.plaf.FontUIResource[family=Inter,name=Inter,style=plain,size=12]

DevCharly added a commit that referenced this issue Dec 4, 2021
…s not affected):

- oversized text if system font is "Inter" (issue #427)
- missing text if system font is "Cantarell" (on Fedora)
@DevCharly
Copy link
Collaborator

Was able to reproduce the issue with Oracle JDK 8 and font "Inter" on Linux.

Seems that Oracle's JDK has problems with this font.
Although the java.awt.Font object has size 15, the java.awt.FontMetrics returns a height of 41...

To avoid this problem in the future, I've added a check that uses a fallback font for this cases.

@DevCharly DevCharly added this to the 1.6.5 milestone Dec 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants