From: Kevin Lamonte Date: Mon, 11 Nov 2019 01:48:52 +0000 (-0600) Subject: enable antialiasing X-Git-Url: https://git.nikiroo.be/?a=commitdiff_plain;h=7ed28054941adbb9e7f2b4487fa9d2325b12a752;p=fanfix-jexer.git enable antialiasing --- diff --git a/src/jexer/backend/ECMA48Terminal.java b/src/jexer/backend/ECMA48Terminal.java index 0389f3d..ad643f4 100644 --- a/src/jexer/backend/ECMA48Terminal.java +++ b/src/jexer/backend/ECMA48Terminal.java @@ -28,6 +28,9 @@ */ package jexer.backend; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.RenderingHints; import java.awt.image.BufferedImage; import java.io.BufferedReader; import java.io.ByteArrayOutputStream; @@ -3300,7 +3303,13 @@ public class ECMA48Terminal extends LogicalScreen newImage = new BufferedImage(cells.size() * getTextWidth(), getTextHeight(), BufferedImage.TYPE_INT_ARGB); - java.awt.Graphics gr = newImage.getGraphics(); + Graphics gr = newImage.getGraphics(); + if (gr instanceof Graphics2D) { + ((Graphics2D) gr).setRenderingHint(RenderingHints.KEY_ANTIALIASING, + RenderingHints.VALUE_ANTIALIAS_ON); + ((Graphics2D) gr).setRenderingHint(RenderingHints.KEY_RENDERING, + RenderingHints.VALUE_RENDER_QUALITY); + } gr.drawImage(image, 0, 0, newImage.getWidth(), newImage.getHeight(), null, null); gr.dispose(); @@ -3624,7 +3633,13 @@ public class ECMA48Terminal extends LogicalScreen newImage = new BufferedImage(cells.size() * getTextWidth(), getTextHeight(), BufferedImage.TYPE_INT_ARGB); - java.awt.Graphics gr = newImage.getGraphics(); + Graphics gr = newImage.getGraphics(); + if (gr instanceof Graphics2D) { + ((Graphics2D) gr).setRenderingHint(RenderingHints.KEY_ANTIALIASING, + RenderingHints.VALUE_ANTIALIAS_ON); + ((Graphics2D) gr).setRenderingHint(RenderingHints.KEY_RENDERING, + RenderingHints.VALUE_RENDER_QUALITY); + } gr.drawImage(image, 0, 0, newImage.getWidth(), newImage.getHeight(), null, null); gr.dispose(); @@ -3887,7 +3902,13 @@ public class ECMA48Terminal extends LogicalScreen newImage = new BufferedImage(cells.size() * getTextWidth(), getTextHeight(), BufferedImage.TYPE_INT_ARGB); - java.awt.Graphics gr = newImage.getGraphics(); + Graphics gr = newImage.getGraphics(); + if (gr instanceof Graphics2D) { + ((Graphics2D) gr).setRenderingHint(RenderingHints.KEY_ANTIALIASING, + RenderingHints.VALUE_ANTIALIAS_ON); + ((Graphics2D) gr).setRenderingHint(RenderingHints.KEY_RENDERING, + RenderingHints.VALUE_RENDER_QUALITY); + } gr.drawImage(image, 0, 0, newImage.getWidth(), newImage.getHeight(), null, null); gr.dispose(); diff --git a/src/jexer/backend/SwingTerminal.java b/src/jexer/backend/SwingTerminal.java index eb1616b..37f99d5 100644 --- a/src/jexer/backend/SwingTerminal.java +++ b/src/jexer/backend/SwingTerminal.java @@ -36,6 +36,7 @@ import java.awt.Graphics2D; import java.awt.Graphics; import java.awt.Insets; import java.awt.Rectangle; +import java.awt.RenderingHints; import java.awt.Toolkit; import java.awt.event.ComponentEvent; import java.awt.event.ComponentListener; @@ -1238,6 +1239,15 @@ public class SwingTerminal extends LogicalScreen // Draw the background rectangle, then the foreground character. assert (cell.isImage()); + + // Enable anti-aliasing + if (gr instanceof Graphics2D) { + ((Graphics2D) gr).setRenderingHint(RenderingHints.KEY_ANTIALIASING, + RenderingHints.VALUE_ANTIALIAS_ON); + ((Graphics2D) gr).setRenderingHint(RenderingHints.KEY_RENDERING, + RenderingHints.VALUE_RENDER_QUALITY); + } + gr.setColor(cell.getBackground()); gr.fillRect(xPixel, yPixel, textWidth, textHeight); @@ -1310,10 +1320,19 @@ public class SwingTerminal extends LogicalScreen cellColor.setBackColor(cell.getForeColor()); } + // Enable anti-aliasing + if (gr instanceof Graphics2D) { + ((Graphics2D) gr).setRenderingHint(RenderingHints.KEY_ANTIALIASING, + RenderingHints.VALUE_ANTIALIAS_ON); + ((Graphics2D) gr).setRenderingHint(RenderingHints.KEY_RENDERING, + RenderingHints.VALUE_RENDER_QUALITY); + } + // Draw the background rectangle, then the foreground character. gr2.setColor(attrToBackgroundColor(cellColor)); gr2.fillRect(gr2x, gr2y, textWidth, textHeight); + // Handle blink and underline if (!cell.isBlink() || (cell.isBlink() && cursorBlinkVisible)