Skip to content

Commit

Permalink
fix(gui): apply render hints for line numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
skylot committed Oct 28, 2018
1 parent a3464d7 commit 58993b9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public void mouseClicked(MouseEvent e) {
int result = fontChooser.showDialog(JadxSettingsWindow.this);
if (result == JFontChooser.OK_OPTION) {
Font font = fontChooser.getSelectedFont();
LOG.info("Selected Font : {}", font);
LOG.debug("Selected Font: {}", font);
settings.setFont(font);
mainWindow.updateFont(font);
mainWindow.loadSettings();
Expand Down
15 changes: 15 additions & 0 deletions jadx-gui/src/main/java/jadx/gui/ui/codearea/LineNumbers.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class LineNumbers extends JPanel implements CaretListener {
private static final long serialVersionUID = -4978268673635308190L;

private static final int NUM_HEIGHT = Integer.MAX_VALUE - 1000000;
private static final Map<?, ?> DESKTOP_HINTS = (Map<?, ?>) Toolkit.getDefaultToolkit().getDesktopProperty("awt.font.desktophints");

private CodeArea codeArea;
private boolean useSourceLines = true;
Expand Down Expand Up @@ -92,6 +93,7 @@ private void setPreferredWidth() {
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.setFont(codeArea.getFont());
applyRenderHints(g);

FontMetrics fontMetrics = codeArea.getFontMetrics(codeArea.getFont());
Insets insets = getInsets();
Expand Down Expand Up @@ -119,6 +121,19 @@ public void paintComponent(Graphics g) {
}
}

private void applyRenderHints(Graphics g) {
if (g instanceof Graphics2D) {
Graphics2D g2d = (Graphics2D) g;
if (DESKTOP_HINTS != null) {
g2d.setRenderingHints(DESKTOP_HINTS);
} else {
g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
g2d.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
}
}
}

private boolean isCurrentLine(int rowStartOffset) {
int caretPosition = codeArea.getCaretPosition();
Element root = codeArea.getDocument().getDefaultRootElement();
Expand Down

0 comments on commit 58993b9

Please sign in to comment.