Ubuntu Linux: fixed poorly rendered font (2nd attempt) (issue #105)

This commit is contained in:
Karl Tauber
2020-05-23 11:06:24 +02:00
parent c7a8d1e1b7
commit c4c6faa943
3 changed files with 11 additions and 7 deletions

View File

@@ -419,7 +419,7 @@ public abstract class FlatLaf
// using StyleContext.getFont() here because it uses // using StyleContext.getFont() here because it uses
// sun.font.FontUtilities.getCompositeFontUIResource() // sun.font.FontUtilities.getCompositeFontUIResource()
// and creates a composite font that is able to display all Unicode characters // and creates a composite font that is able to display all Unicode characters
Font font = new StyleContext().getFont( family, style, size ); Font font = StyleContext.getDefaultStyleContext().getFont( family, style, size );
return (font instanceof FontUIResource) ? (FontUIResource) font : new FontUIResource( font ); return (font instanceof FontUIResource) ? (FontUIResource) font : new FontUIResource( font );
} }

View File

@@ -75,9 +75,11 @@ class LinuxFontPolicy
} }
// Ubuntu font is rendered poorly (except if running in JetBrains VM) // Ubuntu font is rendered poorly (except if running in JetBrains VM)
// --> use default Java font // --> use Liberation Sans font
if( family.startsWith( "Ubuntu" ) && !SystemInfo.IS_JETBRAINS_JVM ) if( family.startsWith( "Ubuntu" ) &&
family = "sans"; !SystemInfo.IS_JETBRAINS_JVM &&
!Boolean.parseBoolean( System.getProperty( "flatlaf.useUbuntuFont" ) ) )
family = "Liberation Sans";
// scale font size // scale font size
double dsize = size * getGnomeFontScale(); double dsize = size * getGnomeFontScale();

View File

@@ -22,6 +22,7 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import javax.swing.*; import javax.swing.*;
import javax.swing.text.DefaultEditorKit; import javax.swing.text.DefaultEditorKit;
import javax.swing.text.StyleContext;
import com.formdev.flatlaf.FlatLaf; import com.formdev.flatlaf.FlatLaf;
import com.formdev.flatlaf.demo.extras.*; import com.formdev.flatlaf.demo.extras.*;
import com.formdev.flatlaf.demo.intellijthemes.*; import com.formdev.flatlaf.demo.intellijthemes.*;
@@ -83,7 +84,7 @@ class DemoFrame
String fontFamily = e.getActionCommand(); String fontFamily = e.getActionCommand();
Font font = UIManager.getFont( "defaultFont" ); Font font = UIManager.getFont( "defaultFont" );
Font newFont = new Font( fontFamily, font.getStyle(), font.getSize() ); Font newFont = StyleContext.getDefaultStyleContext().getFont( fontFamily, font.getStyle(), font.getSize() );
UIManager.put( "defaultFont", newFont ); UIManager.put( "defaultFont", newFont );
FlatLaf.updateUI(); FlatLaf.updateUI();
@@ -140,8 +141,9 @@ class DemoFrame
// add font families // add font families
fontMenu.addSeparator(); fontMenu.addSeparator();
ArrayList<String> families = new ArrayList<>( Arrays.asList( ArrayList<String> families = new ArrayList<>( Arrays.asList(
"Arial", "Comic Sans MS", "Courier New", "DejaVu Sans", "Dialog", "Monospaced", "Arial", "Cantarell", "Comic Sans MS", "Courier New", "DejaVu Sans",
"Noto Sans", "Roboto", "SansSerif", "Segoe UI", "Serif", "Tahoma", "Ubuntu", "Verdana" ) ); "Dialog", "Liberation Sans", "Monospaced", "Noto Sans", "Roboto",
"SansSerif", "Segoe UI", "Serif", "Tahoma", "Ubuntu", "Verdana" ) );
if( !families.contains( currentFamily ) ) if( !families.contains( currentFamily ) )
families.add( currentFamily ); families.add( currentFamily );
families.sort( String.CASE_INSENSITIVE_ORDER ); families.sort( String.CASE_INSENSITIVE_ORDER );