diff --git a/core/src/processing/awt/PGraphicsJava2D.java b/core/src/processing/awt/PGraphicsJava2D.java index f824479fd..c387653c7 100644 --- a/core/src/processing/awt/PGraphicsJava2D.java +++ b/core/src/processing/awt/PGraphicsJava2D.java @@ -250,7 +250,6 @@ public class PGraphicsJava2D extends PGraphics { @Override public PSurface createSurface() { return surface = new PSurfaceAWT(this); -// return new PSurfaceAWT(this); } @@ -2066,9 +2065,43 @@ public class PGraphicsJava2D extends PGraphics { } - @Override - public FontMetrics getFontMetrics(Font font) { - return (g2 != null) ? g2.getFontMetrics(font) : super.getFontMetrics(font); +// /** +// * Convenience method to get a legit FontMetrics object. Where possible, +// * override this any renderer subclass so that you're not using what's +// * returned by getDefaultToolkit() to get your metrics. +// */ +// @SuppressWarnings("deprecation") +// public FontMetrics getFontMetrics(Font font) { // ignore +// Frame frame = parent.frame; +// if (frame != null) { +// return frame.getToolkit().getFontMetrics(font); +// } +// return Toolkit.getDefaultToolkit().getFontMetrics(font); +// } +// +// +// /** +// * Convenience method to jump through some Java2D hoops and get an FRC. +// */ +// public FontRenderContext getFontRenderContext(Font font) { // ignore +// return getFontMetrics(font).getFontRenderContext(); +// } + + Toolkit toolkit; + + @SuppressWarnings("deprecation") + protected FontMetrics getFontMetrics(Font font) { + if (toolkit == null) { + try { + Canvas canvas = (Canvas) surface.getNative(); + toolkit = canvas.getToolkit(); + } catch (Exception e) { + // May error out if it's a PSurfaceNone or similar + toolkit = Toolkit.getDefaultToolkit(); + } + } + return toolkit.getFontMetrics(font); + //return (g2 != null) ? g2.getFontMetrics(font) : super.getFontMetrics(font); } diff --git a/core/src/processing/awt/PSurfaceAWT.java b/core/src/processing/awt/PSurfaceAWT.java index 0d1aebb3f..c2934df1f 100644 --- a/core/src/processing/awt/PSurfaceAWT.java +++ b/core/src/processing/awt/PSurfaceAWT.java @@ -520,6 +520,11 @@ public class PSurfaceAWT extends PSurfaceNone { } +// public Toolkit getToolkit() { +// return canvas.getToolkit(); +// } + + /** Set the window (and dock, or whatever necessary) title. */ @Override public void setTitle(String title) { diff --git a/core/src/processing/core/PGraphics.java b/core/src/processing/core/PGraphics.java index 16e08ae39..6621a8022 100644 --- a/core/src/processing/core/PGraphics.java +++ b/core/src/processing/core/PGraphics.java @@ -26,16 +26,11 @@ package processing.core; import java.awt.Color; -import java.awt.Font; -import java.awt.FontMetrics; -import java.awt.Frame; import java.awt.Image; -import java.awt.Toolkit; -import java.awt.font.FontRenderContext; +import java.util.Map; import java.util.HashMap; import java.util.WeakHashMap; -import processing.awt.PSurfaceAWT; import processing.opengl.PGL; import processing.opengl.PShader; @@ -799,7 +794,7 @@ public class PGraphics extends PImage implements PConstants { public PSurface createSurface() { // ignore - return surface = new PSurfaceAWT(this); + return surface = new PSurfaceNone(this); } @@ -4928,27 +4923,27 @@ public class PGraphics extends PImage implements PConstants { */ - /** - * Convenience method to get a legit FontMetrics object. Where possible, - * override this any renderer subclass so that you're not using what's - * returned by getDefaultToolkit() to get your metrics. - */ - @SuppressWarnings("deprecation") - public FontMetrics getFontMetrics(Font font) { // ignore - Frame frame = parent.frame; - if (frame != null) { - return frame.getToolkit().getFontMetrics(font); - } - return Toolkit.getDefaultToolkit().getFontMetrics(font); - } - - - /** - * Convenience method to jump through some Java2D hoops and get an FRC. - */ - public FontRenderContext getFontRenderContext(Font font) { // ignore - return getFontMetrics(font).getFontRenderContext(); - } +// /** +// * Convenience method to get a legit FontMetrics object. Where possible, +// * override this any renderer subclass so that you're not using what's +// * returned by getDefaultToolkit() to get your metrics. +// */ +// @SuppressWarnings("deprecation") +// public FontMetrics getFontMetrics(Font font) { // ignore +// Frame frame = parent.frame; +// if (frame != null) { +// return frame.getToolkit().getFontMetrics(font); +// } +// return Toolkit.getDefaultToolkit().getFontMetrics(font); +// } +// +// +// /** +// * Convenience method to jump through some Java2D hoops and get an FRC. +// */ +// public FontRenderContext getFontRenderContext(Font font) { // ignore +// return getFontMetrics(font).getFontRenderContext(); +// } @@ -7934,7 +7929,7 @@ public class PGraphics extends PImage implements PConstants { // WARNINGS and EXCEPTIONS - static protected HashMap warnings; + static protected Map warnings; /** diff --git a/core/src/processing/opengl/PJOGL.java b/core/src/processing/opengl/PJOGL.java index ddfb8e0c0..ed84e33a3 100644 --- a/core/src/processing/opengl/PJOGL.java +++ b/core/src/processing/opengl/PJOGL.java @@ -26,6 +26,7 @@ package processing.opengl; import java.awt.Font; import java.awt.FontMetrics; import java.awt.Shape; +import java.awt.Toolkit; import java.awt.font.FontRenderContext; import java.awt.font.GlyphVector; import java.awt.geom.PathIterator; @@ -1192,16 +1193,34 @@ public class PJOGL extends PGL { } + /** + * Convenience method to get a legit FontMetrics object. Where possible, + * override this any renderer subclass so that you're not using what's + * returned by getDefaultToolkit() to get your metrics. + */ + @SuppressWarnings("deprecation") + private FontMetrics getFontMetrics(Font font) { // ignore + return Toolkit.getDefaultToolkit().getFontMetrics(font); + } + + + /** + * Convenience method to jump through some Java2D hoops and get an FRC. + */ + private FontRenderContext getFontRenderContext(Font font) { // ignore + return getFontMetrics(font).getFontRenderContext(); + } + @Override protected int getFontAscent(Object font) { - return pg.getFontMetrics((Font) font).getAscent(); + return getFontMetrics((Font) font).getAscent(); } @Override protected int getFontDescent(Object font) { - return pg.getFontMetrics((Font) font).getDescent(); + return getFontMetrics((Font) font).getDescent(); } @@ -1209,7 +1228,7 @@ public class PJOGL extends PGL { protected int getTextWidth(Object font, char[] buffer, int start, int stop) { // maybe should use one of the newer/fancier functions for this? int length = stop - start; - FontMetrics metrics = pg.getFontMetrics((Font) font); + FontMetrics metrics = getFontMetrics((Font) font); return metrics.charsWidth(buffer, start, length); } @@ -1394,7 +1413,7 @@ public class PJOGL extends PGL { public FontOutline(char ch, Font font) { char textArray[] = new char[] { ch }; - FontRenderContext frc = pg.getFontRenderContext(font); + FontRenderContext frc = getFontRenderContext(font); GlyphVector gv = font.createGlyphVector(frc, textArray); Shape shp = gv.getOutline(); iter = shp.getPathIterator(null); diff --git a/core/todo.txt b/core/todo.txt index 36975ab7c..db87da3b2 100644 --- a/core/todo.txt +++ b/core/todo.txt @@ -1,4 +1,4 @@ -0238 (3.0b1) +0238 (3.0a11) X add note about headless exceptions that points to Github X resize children[] so that getChildren() returns a correctly-sized array X https://github.com/processing/processing/issues/3347 @@ -117,6 +117,8 @@ _ update wiki/docs to say "don't override sketchXxxx() methods" beta +X move Java2D and JavaFX classes to their own packages +_ make notes about this in the README _ run only the necessary pieces on the EDT _ in part because FX doesn't even use the EDT _ re-check the Linux frame visibility stuff diff --git a/todo.txt b/todo.txt index aebffe4a2..4128ce034 100644 --- a/todo.txt +++ b/todo.txt @@ -1,4 +1,4 @@ -0238 (3.0b1) +0238 (3.0a11) X Re-enable the display menu in Preferences after display added X Previously, the checkbox menu stayed disabled (though it updated the list) X sketch.isReadOnly returns false for examples coming from multiple modes @@ -86,6 +86,7 @@ _ deactivate step, continue, stop when not running? _ update EditorButton rollover label when pressing shift or alt _ disable the debug toggle menu while running _ otherwise could run in one mode, then try to stop in another +_ recent menu gets huge with other p5 versions on osx pde/build