Skip to content

Commit

Permalink
Linux: Fixed font problems when running on Oracle Java 8 (OpenJDK 8 i…
Browse files Browse the repository at this point in the history
…s not affected):

- oversized text if system font is "Inter" (issue #427)
- missing text if system font is "Cantarell" (on Fedora)
  • Loading branch information
DevCharly committed Nov 24, 2021
1 parent 6c0b122 commit 7dac382
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -28,7 +29,7 @@
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;
Expand Down Expand Up @@ -121,14 +122,25 @@ private static Font createFontEx( String family, int style, int size, double dsi
for(;;) {
Font font = createFont( family, style, size, dsize );

if( Font.DIALOG.equals( family ) )
return font;

// 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( 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();
Expand Down

0 comments on commit 7dac382

Please sign in to comment.