diff --git a/CHANGELOG.md b/CHANGELOG.md index 80ccabbb..ad39c4ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,14 @@ FlatLaf Change Log ================== +## 1.6.5-SNAPSHOT + +- Linux: Fixed font problems when running on Oracle Java 8 (OpenJDK 8 is not + affected): + - oversized text if system font is "Inter" (issue #427) + - missing text if system font is "Cantarell" (on Fedora) + + ## 1.6.4 #### Fixed bugs diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/LinuxFontPolicy.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/LinuxFontPolicy.java index b20fba54..837f5052 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/LinuxFontPolicy.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/LinuxFontPolicy.java @@ -17,6 +17,7 @@ package com.formdev.flatlaf; import java.awt.Font; +import java.awt.FontMetrics; import java.awt.GraphicsConfiguration; import java.awt.GraphicsEnvironment; import java.awt.Toolkit; @@ -28,7 +29,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.StringTokenizer; - +import javax.swing.text.StyleContext; import com.formdev.flatlaf.util.LoggingFacade; import com.formdev.flatlaf.util.StringUtils; import com.formdev.flatlaf.util.SystemInfo; @@ -121,14 +122,25 @@ class LinuxFontPolicy for(;;) { Font font = createFont( family, style, size, dsize ); - // if the font family does not match any font on the system, "Dialog" family is returned - if( !"Dialog".equals( font.getFamily() ) || "Dialog".equals( family ) ) + if( Font.DIALOG.equals( family ) ) return font; + // if the font family does not match any font on the system, "Dialog" family is returned + if( !Font.DIALOG.equals( font.getFamily() ) ) { + // check for font problems + // - font height much larger than expected (e.g. font Inter; Oracle Java 8) + // - 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 font; + } + // find last word in family int index = family.lastIndexOf( ' ' ); if( index < 0 ) - return createFont( "Dialog", style, size, dsize ); + return createFont( Font.DIALOG, style, size, dsize ); // check whether last work contains some font weight (e.g. Ultra-Bold or Heavy) String lastWord = family.substring( index + 1 ).toLowerCase();