Windows: fixed rendering of Unicode characters (issue #81)

This commit is contained in:
Karl Tauber
2020-04-09 11:53:11 +02:00
parent 4da0c342f8
commit 9eaee8d2c4
3 changed files with 20 additions and 7 deletions

View File

@@ -1,6 +1,12 @@
FlatLaf Change Log FlatLaf Change Log
================== ==================
## 0.30
- Windows: Fixed rendering of Unicode characters. Previously not all Unicode
characters were rendered on Windows. (issue #81)
## 0.29 ## 0.29
- Linux: Fixed scaling if `GDK_SCALE` environment variable is set or if running - Linux: Fixed scaling if `GDK_SCALE` environment variable is set or if running

View File

@@ -54,6 +54,7 @@ import javax.swing.plaf.ColorUIResource;
import javax.swing.plaf.FontUIResource; import javax.swing.plaf.FontUIResource;
import javax.swing.plaf.UIResource; import javax.swing.plaf.UIResource;
import javax.swing.plaf.basic.BasicLookAndFeel; import javax.swing.plaf.basic.BasicLookAndFeel;
import javax.swing.text.StyleContext;
import javax.swing.text.html.HTMLEditorKit; import javax.swing.text.html.HTMLEditorKit;
import com.formdev.flatlaf.util.SystemInfo; import com.formdev.flatlaf.util.SystemInfo;
import com.formdev.flatlaf.util.UIScale; import com.formdev.flatlaf.util.UIScale;
@@ -324,7 +325,7 @@ public abstract class FlatLaf
if( SystemInfo.IS_WINDOWS ) { if( SystemInfo.IS_WINDOWS ) {
Font winFont = (Font) Toolkit.getDefaultToolkit().getDesktopProperty( "win.messagebox.font" ); Font winFont = (Font) Toolkit.getDefaultToolkit().getDesktopProperty( "win.messagebox.font" );
if( winFont != null ) if( winFont != null )
uiFont = new FontUIResource( winFont ); uiFont = createCompositeFont( winFont.getFamily(), winFont.getStyle(), winFont.getSize() );
} else if( SystemInfo.IS_MAC ) { } else if( SystemInfo.IS_MAC ) {
String fontName; String fontName;
@@ -335,7 +336,8 @@ public abstract class FlatLaf
// default font on older systems (see com.apple.laf.AquaFonts) // default font on older systems (see com.apple.laf.AquaFonts)
fontName = "Lucida Grande"; fontName = "Lucida Grande";
} }
uiFont = new FontUIResource( fontName, Font.PLAIN, 13 );
uiFont = createCompositeFont( fontName, Font.PLAIN, 13 );
} else if( SystemInfo.IS_LINUX ) { } else if( SystemInfo.IS_LINUX ) {
Font font = LinuxFontPolicy.getFont(); Font font = LinuxFontPolicy.getFont();
@@ -343,7 +345,7 @@ public abstract class FlatLaf
} }
if( uiFont == null ) if( uiFont == null )
return; uiFont = createCompositeFont( Font.SANS_SERIF, Font.PLAIN, 12 );
uiFont = UIScale.applyCustomScaleFactor( uiFont ); uiFont = UIScale.applyCustomScaleFactor( uiFont );
@@ -365,6 +367,14 @@ public abstract class FlatLaf
defaults.put( "defaultFont", uiFont ); defaults.put( "defaultFont", uiFont );
} }
static FontUIResource createCompositeFont( String family, int style, int size ) {
// using StyleContext.getFont() here because it uses
// sun.font.FontUtilities.getCompositeFontUIResource()
// and creates a composite font that is able to display all Unicode characters
Font font = new StyleContext().getFont( family, style, size );
return (font instanceof FontUIResource) ? (FontUIResource) font : new FontUIResource( font );
}
/** /**
* Adds the default color palette for action icons and object icons to the given UIDefaults. * Adds the default color palette for action icons and object icons to the given UIDefaults.
* <p> * <p>

View File

@@ -29,7 +29,6 @@ import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import java.util.logging.Level; import java.util.logging.Level;
import javax.swing.text.StyleContext;
import com.formdev.flatlaf.util.StringUtils; import com.formdev.flatlaf.util.StringUtils;
import com.formdev.flatlaf.util.SystemInfo; import com.formdev.flatlaf.util.SystemInfo;
import com.formdev.flatlaf.util.UIScale; import com.formdev.flatlaf.util.UIScale;
@@ -90,9 +89,7 @@ class LinuxFontPolicy
} }
private static Font createFont( String family, int style, int size, double dsize ) { private static Font createFont( String family, int style, int size, double dsize ) {
// using StyleContext.getFont() here because it uses Font font = FlatLaf.createCompositeFont( family, style, size );
// sun.font.FontUtilities.getCompositeFontUIResource()
Font font = new StyleContext().getFont( family, style, size );
// set font size in floating points // set font size in floating points
font = font.deriveFont( style, (float) dsize ); font = font.deriveFont( style, (float) dsize );