fix(gui): use FontUtils.getCompositeFont() that supports CJK (PR #2751)

fix: use FontUtils.getCompositeFont() that supports CJK
This commit is contained in:
ewt45
2026-01-21 01:58:08 +08:00
committed by GitHub
parent 220a2198a1
commit c677901aa5
5 changed files with 17 additions and 11 deletions
@@ -3,7 +3,6 @@ package jadx.gui.report;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
@@ -119,7 +118,7 @@ public class ExceptionDialog extends JDialog {
JTextArea messageArea = new JTextArea();
TextStandardActions.attach(messageArea);
messageArea.setEditable(false);
messageArea.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 12));
messageArea.setFont(mainWindow.getSettings().getCodeFont().deriveFont(12f));
messageArea.setForeground(Color.BLACK);
messageArea.setBackground(Color.WHITE);
@@ -7,6 +7,7 @@ import javax.swing.UIManager;
import com.formdev.flatlaf.FlatLaf;
import com.formdev.flatlaf.fonts.inter.FlatInterFont;
import com.formdev.flatlaf.fonts.jetbrains_mono.FlatJetBrainsMonoFont;
import com.formdev.flatlaf.util.FontUtils;
import jadx.gui.settings.JadxSettingsData;
import jadx.gui.utils.UiUtils;
@@ -31,8 +32,8 @@ public class FontSettings {
public FontSettings() {
int defFontSize = 13;
Font defUiFont = new Font(FlatInterFont.FAMILY, Font.PLAIN, defFontSize);
Font defCodeFont = new Font(FlatJetBrainsMonoFont.FAMILY, Font.PLAIN, defFontSize);
Font defUiFont = FontUtils.getCompositeFont(FlatInterFont.FAMILY, Font.PLAIN, defFontSize);
Font defCodeFont = FontUtils.getCompositeFont(FlatJetBrainsMonoFont.FAMILY, Font.PLAIN, defFontSize);
uiFontAdapter = new FontAdapter(defUiFont);
codeFontAdapter = new FontAdapter(defCodeFont);
smaliFontAdapter = new FontAdapter(defCodeFont);
@@ -15,6 +15,7 @@ import org.drjekyll.fontchooser.FontChooser;
import org.jetbrains.annotations.Nullable;
import jadx.gui.settings.JadxSettings;
import jadx.gui.utils.FontUtils;
import jadx.gui.utils.NLS;
public class JadxFontDialog extends JDialog {
@@ -42,7 +43,7 @@ public class JadxFontDialog extends JDialog {
setVisible(true);
Font selectedFont = fontChooser.getSelectedFont();
if (selected && !selectedFont.equals(currentFont)) {
return selectedFont;
return FontUtils.getCompositeFont(selectedFont.getFamily(), selectedFont.getStyle(), selectedFont.getSize());
}
return null;
}
@@ -58,7 +58,6 @@ import javax.swing.UIManager;
import javax.swing.WindowConstants;
import javax.swing.event.TreeExpansionEvent;
import javax.swing.event.TreeWillExpandListener;
import javax.swing.plaf.FontUIResource;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.tree.DefaultTreeModel;
@@ -1573,7 +1572,7 @@ public class MainWindow extends JFrame {
Font defaultUiFont = UIManager.getFont("defaultFont");
Font uiFont = settings.getUiFont();
if (!uiFont.equals(defaultUiFont)) {
UIManager.put("defaultFont", new FontUIResource(uiFont));
UIManager.put("defaultFont", uiFont);
setFont(uiFont);
needUpdateUI = true;
}
@@ -3,8 +3,6 @@ package jadx.gui.utils;
import java.awt.Font;
import java.io.InputStream;
import javax.swing.text.StyleContext;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -23,8 +21,7 @@ public class FontUtils {
int style = parseFontStyle(parts[1]);
int size = Integer.parseInt(parts[2]);
StyleContext sc = StyleContext.getDefaultStyleContext();
Font font = sc.getFont(family, style, size);
Font font = FontUtils.getCompositeFont(family, style, size);
if (font == null) {
throw new JadxRuntimeException("Font not found: " + fontDesc);
}
@@ -95,6 +92,15 @@ public class FontUtils {
return true;
}
/**
* https://github.com/JFormDesigner/FlatLaf/issues/923
* When changing fonts, use font.deriveFont() or FontUtils.getCompositeFont
* instead of new Font(), otherwise FlatLaf's CJKs support will be lost
*/
public static Font getCompositeFont(String family, int style, int size) {
return com.formdev.flatlaf.util.FontUtils.getCompositeFont(family, style, size);
}
private FontUtils() {
}
}