diff --git a/core/src/main/java/com/github/weisj/darklaf/graphics/GraphicsUtil.java b/core/src/main/java/com/github/weisj/darklaf/graphics/GraphicsUtil.java index c278ae41..1adf0352 100644 --- a/core/src/main/java/com/github/weisj/darklaf/graphics/GraphicsUtil.java +++ b/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,18 +46,11 @@ 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 - : RenderingHints.VALUE_TEXT_ANTIALIAS_OFF); - } + g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, + enableAA ? RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HBGR + : RenderingHints.VALUE_TEXT_ANTIALIAS_OFF); } return config; } diff --git a/core/src/main/java/com/github/weisj/darklaf/task/FontDefaultsInitTask.java b/core/src/main/java/com/github/weisj/darklaf/task/FontDefaultsInitTask.java index de22524b..dd9655a1 100644 --- a/core/src/main/java/com/github/weisj/darklaf/task/FontDefaultsInitTask.java +++ b/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); }