mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
clean up some font handling
This commit is contained in:
@@ -23,10 +23,6 @@
|
||||
|
||||
package processing.opengl;
|
||||
|
||||
import processing.core.PApplet;
|
||||
import processing.core.PGraphics;
|
||||
|
||||
import java.awt.Font;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.nio.Buffer;
|
||||
@@ -37,6 +33,10 @@ import java.nio.IntBuffer;
|
||||
import java.nio.ShortBuffer;
|
||||
import java.util.Arrays;
|
||||
|
||||
import processing.core.PApplet;
|
||||
import processing.core.PGraphics;
|
||||
|
||||
|
||||
/**
|
||||
* Processing-OpenGL abstraction layer. Needs to be implemented by subclasses
|
||||
* using specific OpenGL-Java bindings.
|
||||
@@ -2105,25 +2105,18 @@ public abstract class PGL {
|
||||
|
||||
|
||||
// TODO: the next three functions shouldn't be here...
|
||||
// Uses 'Object' so that the API can be used w/ Android Typeface objects
|
||||
|
||||
protected int getFontAscent(Font font) {
|
||||
return 0;
|
||||
}
|
||||
abstract protected int getFontAscent(Object font);
|
||||
|
||||
|
||||
protected int getFontDescent(Font font) {
|
||||
return 0;
|
||||
}
|
||||
abstract protected int getFontDescent(Object font);
|
||||
|
||||
|
||||
protected int getTextWidth(Font font, char buffer[], int start, int stop) {
|
||||
return 0;
|
||||
}
|
||||
abstract protected int getTextWidth(Object font, char[] buffer, int start, int stop);
|
||||
|
||||
|
||||
protected Font getDerivedFont(Font font, float size) {
|
||||
return null;
|
||||
}
|
||||
abstract protected Object getDerivedFont(Object font, float size);
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
|
||||
@@ -4,7 +4,6 @@ import java.awt.Canvas;
|
||||
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;
|
||||
@@ -1194,32 +1193,29 @@ public class PJOGL extends PGL {
|
||||
|
||||
|
||||
@Override
|
||||
protected int getFontAscent(Font font) {
|
||||
@SuppressWarnings("deprecation")
|
||||
FontMetrics metrics = Toolkit.getDefaultToolkit().getFontMetrics(font);
|
||||
return metrics.getAscent();
|
||||
protected int getFontAscent(Object font) {
|
||||
return pg.getFontMetrics((Font) font).getAscent();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected int getFontDescent(Object font) {
|
||||
FontMetrics metrics = Toolkit.getDefaultToolkit().getFontMetrics((Font)font);
|
||||
// FontMetrics metrics = pg.parent.getFontMetrics((Font)font);
|
||||
return metrics.getDescent();
|
||||
return pg.getFontMetrics((Font) font).getDescent();
|
||||
}
|
||||
|
||||
|
||||
protected int getTextWidth(Object font, char buffer[], int start, int stop) {
|
||||
@Override
|
||||
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.parent.getFontMetrics((Font)font);
|
||||
FontMetrics metrics = Toolkit.getDefaultToolkit().getFontMetrics((Font)font);
|
||||
FontMetrics metrics = pg.getFontMetrics((Font) font);
|
||||
return metrics.charsWidth(buffer, start, length);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected Object getDerivedFont(Object font, float size) {
|
||||
return ((Font)font).deriveFont(size);
|
||||
|
||||
return ((Font) font).deriveFont(size);
|
||||
}
|
||||
|
||||
|
||||
@@ -1388,18 +1384,17 @@ public class PJOGL extends PGL {
|
||||
|
||||
@Override
|
||||
protected FontOutline createFontOutline(char ch, Object font) {
|
||||
return new FontOutline(ch, font);
|
||||
return new FontOutline(ch, (Font) font);
|
||||
}
|
||||
|
||||
|
||||
protected class FontOutline implements PGL.FontOutline {
|
||||
PathIterator iter;
|
||||
|
||||
public FontOutline(char ch, Object font) {
|
||||
public FontOutline(char ch, Font font) {
|
||||
char textArray[] = new char[] { ch };
|
||||
// Graphics2D graphics = (Graphics2D) pg.parent.frame.getGraphics();
|
||||
FontRenderContext frc = pg.getFontRenderContext((Font)font);
|
||||
GlyphVector gv = ((Font)font).createGlyphVector(frc, textArray);
|
||||
FontRenderContext frc = pg.getFontRenderContext(font);
|
||||
GlyphVector gv = font.createGlyphVector(frc, textArray);
|
||||
Shape shp = gv.getOutline();
|
||||
iter = shp.getPathIterator(null);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user