Skip to content

Commit

Permalink
Linux: fixed slightly different font size (or letter width) used to p…
Browse files Browse the repository at this point in the history
…aint HTML text when default font family is _Cantarell_ (e.g. on Fedora) (issue #912)

the removed use of floating point font size is similar to what is done in JDK for GTK Look and Feel:
- https://bugs.openjdk.org/browse/JDK-6979979
- openjdk/jdk@306f12d
  • Loading branch information
DevCharly committed Dec 4, 2024
1 parent 84bd208 commit 3f33543
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ FlatLaf Change Log
- Theme Editor: Fixed using color picker on secondary screen.
- Fixed detection of Windows 11 if custom exe launcher does not specify Windows
10+ compatibility in application manifest. (issue #916)
- Linux: Fixed slightly different font size (or letter width) used to paint HTML
text when default font family is _Cantarell_ (e.g. on Fedora). (issue #912)


## 3.5.2

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ else if( lword.startsWith( "extra-" ) || lword.startsWith( "ultra-" ) )
if( logicalFamily != null )
family = logicalFamily;

return createFontEx( family, style, size, dsize );
return createFontEx( family, style, size );
}

/**
Expand All @@ -121,9 +121,9 @@ else if( lword.startsWith( "extra-" ) || lword.startsWith( "ultra-" ) )
* E.g. family 'URW Bookman Light' is not found, but 'URW Bookman' is found.
* If still not found, then font of family 'Dialog' is returned.
*/
private static Font createFontEx( String family, int style, int size, double dsize ) {
private static Font createFontEx( String family, int style, int size ) {
for(;;) {
Font font = createFont( family, style, size, dsize );
Font font = FlatLaf.createCompositeFont( family, style, size );

if( Font.DIALOG.equals( family ) )
return font;
Expand All @@ -135,15 +135,15 @@ private static Font createFontEx( String family, int style, int size, double dsi
// - character width is zero (e.g. font Cantarell; Fedora; Oracle Java 8)
FontMetrics fm = StyleContext.getDefaultStyleContext().getFontMetrics( font );
if( fm.getHeight() > size * 2 || fm.stringWidth( "a" ) == 0 )
return createFont( Font.DIALOG, style, size, dsize );
return FlatLaf.createCompositeFont( Font.DIALOG, style, size );

return font;
}

// find last word in family
int index = family.lastIndexOf( ' ' );
if( index < 0 )
return createFont( Font.DIALOG, style, size, dsize );
return FlatLaf.createCompositeFont( Font.DIALOG, style, size );

// check whether last work contains some font weight (e.g. Ultra-Bold or Heavy)
String lastWord = family.substring( index + 1 ).toLowerCase( Locale.ENGLISH );
Expand All @@ -155,15 +155,6 @@ private static Font createFontEx( String family, int style, int size, double dsi
}
}

private static Font createFont( String family, int style, int size, double dsize ) {
Font font = FlatLaf.createCompositeFont( family, style, size );

// set font size in floating points
font = font.deriveFont( style, (float) dsize );

return font;
}

private static double getGnomeFontScale() {
// do not scale font here if JRE scales
if( isSystemScaling() )
Expand Down Expand Up @@ -257,7 +248,7 @@ private static Font getKDEFont() {
if( size < 1 )
size = 1;

return createFont( family, style, size, dsize );
return FlatLaf.createCompositeFont( family, style, size );
}

@SuppressWarnings( "MixedMutabilityReturnType" ) // Error Prone
Expand Down

0 comments on commit 3f33543

Please sign in to comment.