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)

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
- 306f12db9e
This commit is contained in:
Karl Tauber
2024-12-04 17:18:33 +01:00
parent 84bd2088f2
commit 3f33543cee
2 changed files with 9 additions and 15 deletions

View File

@@ -20,6 +20,9 @@ FlatLaf Change Log
- Theme Editor: Fixed using color picker on secondary screen. - Theme Editor: Fixed using color picker on secondary screen.
- Fixed detection of Windows 11 if custom exe launcher does not specify Windows - Fixed detection of Windows 11 if custom exe launcher does not specify Windows
10+ compatibility in application manifest. (issue #916) 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 ## 3.5.2

View File

@@ -111,7 +111,7 @@ class LinuxFontPolicy
if( logicalFamily != null ) if( logicalFamily != null )
family = logicalFamily; family = logicalFamily;
return createFontEx( family, style, size, dsize ); return createFontEx( family, style, size );
} }
/** /**
@@ -121,9 +121,9 @@ class LinuxFontPolicy
* E.g. family 'URW Bookman Light' is not found, but 'URW Bookman' is found. * 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. * 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(;;) { for(;;) {
Font font = createFont( family, style, size, dsize ); Font font = FlatLaf.createCompositeFont( family, style, size );
if( Font.DIALOG.equals( family ) ) if( Font.DIALOG.equals( family ) )
return font; return font;
@@ -135,7 +135,7 @@ class LinuxFontPolicy
// - character width is zero (e.g. font Cantarell; Fedora; Oracle Java 8) // - character width is zero (e.g. font Cantarell; Fedora; Oracle Java 8)
FontMetrics fm = StyleContext.getDefaultStyleContext().getFontMetrics( font ); FontMetrics fm = StyleContext.getDefaultStyleContext().getFontMetrics( font );
if( fm.getHeight() > size * 2 || fm.stringWidth( "a" ) == 0 ) 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; return font;
} }
@@ -143,7 +143,7 @@ class LinuxFontPolicy
// find last word in family // find last word in family
int index = family.lastIndexOf( ' ' ); int index = family.lastIndexOf( ' ' );
if( index < 0 ) 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) // check whether last work contains some font weight (e.g. Ultra-Bold or Heavy)
String lastWord = family.substring( index + 1 ).toLowerCase( Locale.ENGLISH ); String lastWord = family.substring( index + 1 ).toLowerCase( Locale.ENGLISH );
@@ -155,15 +155,6 @@ class LinuxFontPolicy
} }
} }
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() { private static double getGnomeFontScale() {
// do not scale font here if JRE scales // do not scale font here if JRE scales
if( isSystemScaling() ) if( isSystemScaling() )
@@ -257,7 +248,7 @@ class LinuxFontPolicy
if( size < 1 ) if( size < 1 )
size = 1; size = 1;
return createFont( family, style, size, dsize ); return FlatLaf.createCompositeFont( family, style, size );
} }
@SuppressWarnings( "MixedMutabilityReturnType" ) // Error Prone @SuppressWarnings( "MixedMutabilityReturnType" ) // Error Prone