diff --git a/app/src/processing/app/tools/CreateFont.java b/app/src/processing/app/tools/CreateFont.java index 1ef55c2c0..ac1341f1e 100644 --- a/app/src/processing/app/tools/CreateFont.java +++ b/app/src/processing/app/tools/CreateFont.java @@ -277,7 +277,6 @@ public class CreateFont extends JFrame implements Tool { try { Font instance = table.get(list[selection]); font = instance.deriveFont(Font.PLAIN, fontSize); - //PFont f = new PFont(font, smooth, all ? null : PFont.CHARSET); PFont f = new PFont(font, smooth, charSelector.getCharacters()); // the editor may have changed while the window was open @@ -339,8 +338,8 @@ class SampleComponent extends JComponent { } public void paintComponent(Graphics g) { -// System.out.println("smoothing set to " + smooth); Graphics2D g2 = (Graphics2D) g; + g2.setColor(Color.WHITE); Dimension dim = getSize(); g2.fillRect(0, 0, dim.width, dim.height); @@ -355,10 +354,17 @@ class SampleComponent extends JComponent { parent.smooth ? RenderingHints.VALUE_ANTIALIAS_ON : RenderingHints.VALUE_ANTIALIAS_OFF); + g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, + parent.smooth ? + RenderingHints.VALUE_INTERPOLATION_BICUBIC : + RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR); + + // don't do this, it will reset the drawing settings //super.paintComponent(g2); + Font font = getFont(); int ascent = g2.getFontMetrics().getAscent(); -// System.out.println(f.getName()); + g2.setFont(font); g2.drawString(text, 5, dim.height - (dim.height - ascent) / 2); } diff --git a/core/src/processing/core/PFont.java b/core/src/processing/core/PFont.java index dcc7924a0..3f7e691c2 100644 --- a/core/src/processing/core/PFont.java +++ b/core/src/processing/core/PFont.java @@ -181,6 +181,9 @@ public class PFont implements PConstants { protected FontMetrics lazyMetrics; protected int[] lazySamples; + // Debugging for https://github.com/processing/processing4/issues/278 + private final boolean DEBUG_P4_0278 = false; + /** * @nowebref @@ -249,12 +252,20 @@ public class PFont implements PConstants { smooth ? RenderingHints.VALUE_ANTIALIAS_ON : RenderingHints.VALUE_ANTIALIAS_OFF); + // adding this for post-1.0.9 lazyGraphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, smooth ? RenderingHints.VALUE_TEXT_ANTIALIAS_ON : RenderingHints.VALUE_TEXT_ANTIALIAS_OFF); + // Trying to track down https://github.com/processing/processing4/issues/278 + // But at least on macOS, it's still smooth when this is called from Create Font. + lazyGraphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, + smooth ? + RenderingHints.VALUE_INTERPOLATION_BICUBIC : + RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR); + lazyGraphics.setFont(font); lazyMetrics = lazyGraphics.getFontMetrics(); lazySamples = new int[mbox3 * mbox3]; @@ -320,7 +331,7 @@ public class PFont implements PConstants { /** - * Adds an additional parameter that indicates the font came from a file, + * Adds a parameter that indicates the font came from a file, * not a built-in OS font. * * @nowebref @@ -728,7 +739,7 @@ public class PFont implements PConstants { // six element array received from the Java2D path iterator float[] iterPoints = new float[6]; - // array passed to createGylphVector + // array passed to createGlyphVector char[] textArray = new char[] { ch }; //Graphics2D graphics = (Graphics2D) this.getGraphics(); @@ -1034,6 +1045,12 @@ public class PFont implements PConstants { protected Glyph(char c) { + if (DEBUG_P4_0278 && c == 'd') { + System.out.println(lazyGraphics.getRenderingHint(RenderingHints.KEY_ANTIALIASING)); + System.out.println(lazyGraphics.getRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING)); + System.out.println(lazyGraphics.getRenderingHint(RenderingHints.KEY_INTERPOLATION)); + } + int mbox3 = size * 3; lazyGraphics.setColor(Color.white); lazyGraphics.fillRect(0, 0, mbox3, mbox3); @@ -1060,6 +1077,16 @@ public class PFont implements PConstants { } } + if (DEBUG_P4_0278 && c == 'd') { + for (int y = minY; y <= maxY; y++) { + for (int x = minX; x <= maxX; x++) { + int sample = lazySamples[y * mbox3 + x] & 0xff; + System.out.format("%3d ", sample); + } + System.out.println(); + } + } + if (!pixelFound) { minX = minY = 0; maxX = maxY = 0;