Browse Source

Setup font rendering hints in UIDefaults.

Skip kerning for macOS < 10.14.
pull/170/head v2.1.1
weisj 5 years ago
parent
commit
e629714fc8
  1. 14
      core/src/main/java/com/github/weisj/darklaf/graphics/GraphicsUtil.java
  2. 21
      core/src/main/java/com/github/weisj/darklaf/task/FontDefaultsInitTask.java

14
core/src/main/java/com/github/weisj/darklaf/graphics/GraphicsUtil.java

@ -25,7 +25,6 @@
package com.github.weisj.darklaf.graphics;
import java.awt.*;
import java.util.Map;
import com.github.weisj.darklaf.util.PropertyValue;
import com.github.weisj.darklaf.util.SystemInfo;
@ -36,6 +35,8 @@ import com.github.weisj.darklaf.util.SystemInfo;
*/
public final class GraphicsUtil {
public static final String DESKTOP_HINTS_KEY = "awt.font.desktophints";
private GraphicsUtil() {}
public static GraphicsContext setupAntialiasing(final Graphics g2) {
@ -45,19 +46,12 @@ public final class GraphicsUtil {
public static GraphicsContext setupAntialiasing(final Graphics g2, final boolean enableAA,
final boolean ignoreSystemSettings) {
GraphicsContext config = new GraphicsContext(g2);
if (g2 instanceof Graphics2D) {
if (ignoreSystemSettings && g2 instanceof Graphics2D) {
Graphics2D g = (Graphics2D) g2;
Toolkit tk = Toolkit.getDefaultToolkit();
Map<?, ?> map = (Map<?, ?>) tk.getDesktopProperty("awt.font.desktophints");
if (map != null && !ignoreSystemSettings) {
g.addRenderingHints(map);
} else {
g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
enableAA
? RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HBGR
enableAA ? RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HBGR
: RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
}
}
return config;
}

21
core/src/main/java/com/github/weisj/darklaf/task/FontDefaultsInitTask.java

@ -37,6 +37,7 @@ import javax.swing.plaf.UIResource;
import com.github.weisj.darklaf.DarkLaf;
import com.github.weisj.darklaf.PropertyLoader;
import com.github.weisj.darklaf.graphics.GraphicsUtil;
import com.github.weisj.darklaf.theme.Theme;
import com.github.weisj.darklaf.theme.info.FontSizeRule;
import com.github.weisj.darklaf.uiresource.DarkFontUIResource;
@ -64,6 +65,23 @@ public class FontDefaultsInitTask implements DefaultsInitTask {
patchMacOSFonts(defaults);
}
applyFontRule(currentTheme, defaults);
setupRenderingHints(defaults);
}
private void setupRenderingHints(final UIDefaults defaults) {
if (!SystemInfo.isMacOSMojave) {
Toolkit toolkit = Toolkit.getDefaultToolkit();
Map<?, ?> desktopHints = (Map<?, ?>) toolkit.getDesktopProperty(GraphicsUtil.DESKTOP_HINTS_KEY);
Object aaHint = (desktopHints == null) ? null : desktopHints.get(RenderingHints.KEY_TEXT_ANTIALIASING);
if (aaHint != null
&& aaHint != RenderingHints.VALUE_TEXT_ANTIALIAS_OFF
&& aaHint != RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT) {
defaults.put(RenderingHints.KEY_TEXT_ANTIALIASING, aaHint);
defaults.put(RenderingHints.KEY_TEXT_LCD_CONTRAST,
desktopHints.get(RenderingHints.KEY_TEXT_LCD_CONTRAST));
}
}
}
private void loadFontProperties(final UIDefaults defaults) {
@ -83,7 +101,8 @@ public class FontDefaultsInitTask implements DefaultsInitTask {
private Font macOSFontFromFont(final Font font) {
String fontName = SystemInfo.isMacOSCatalina ? MAC_OS_CATALINA_FONT_NAME : MAC_OS_FONT_NAME;
Font macFont = new Font(fontName, font.getStyle(), font.getSize()).deriveFont(ENABLE_KERNING);
Font macFont = new Font(fontName, font.getStyle(), font.getSize());
if (SystemInfo.isMacOSMojave) macFont = macFont.deriveFont(ENABLE_KERNING);
if (font instanceof UIResource) {
macFont = new DarkFontUIResource(macFont);
}

Loading…
Cancel
Save