mirror of
https://github.com/processing/processing4.git
synced 2026-02-10 00:59:40 +01:00
excising nearly all AWT from PGraphics
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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<String, Object> warnings;
|
||||
static protected Map<String, Object> warnings;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user