Skip to content

Commit 0039c19

Browse files
committed
getting font metrics from default toolkit
1 parent 618cc72 commit 0039c19

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

core/src/processing/opengl/PJOGL.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import java.awt.Canvas;
44
import java.awt.Font;
55
import java.awt.FontMetrics;
6-
import java.awt.Graphics2D;
76
import java.awt.Shape;
87
import java.awt.Toolkit;
98
import java.awt.font.FontRenderContext;
@@ -1196,26 +1195,25 @@ protected void disableTexturing(int target) {
11961195

11971196
@Override
11981197
protected int getFontAscent(Font font) {
1199-
//FontMetrics metrics = pg.parent.getFontMetrics(font);
12001198
@SuppressWarnings("deprecation")
12011199
FontMetrics metrics = Toolkit.getDefaultToolkit().getFontMetrics(font);
12021200
return metrics.getAscent();
12031201
}
12041202

12051203

12061204
protected int getFontDescent(Object font) {
1205+
FontMetrics metrics = Toolkit.getDefaultToolkit().getFontMetrics((Font)font);
12071206
// FontMetrics metrics = pg.parent.getFontMetrics((Font)font);
1208-
// return metrics.getDescent();
1209-
return 0;
1207+
return metrics.getDescent();
12101208
}
12111209

12121210

12131211
protected int getTextWidth(Object font, char buffer[], int start, int stop) {
12141212
// maybe should use one of the newer/fancier functions for this?
1215-
// int length = stop - start;
1213+
int length = stop - start;
12161214
// FontMetrics metrics = pg.parent.getFontMetrics((Font)font);
1217-
// return metrics.charsWidth(buffer, start, length);
1218-
return 0;
1215+
FontMetrics metrics = Toolkit.getDefaultToolkit().getFontMetrics((Font)font);
1216+
return metrics.charsWidth(buffer, start, length);
12191217
}
12201218

12211219

@@ -1399,8 +1397,8 @@ protected class FontOutline implements PGL.FontOutline {
13991397

14001398
public FontOutline(char ch, Object font) {
14011399
char textArray[] = new char[] { ch };
1402-
Graphics2D graphics = (Graphics2D) pg.parent.frame.getGraphics();
1403-
FontRenderContext frc = graphics.getFontRenderContext();
1400+
// Graphics2D graphics = (Graphics2D) pg.parent.frame.getGraphics();
1401+
FontRenderContext frc = pg.getFontRenderContext((Font)font);
14041402
GlyphVector gv = ((Font)font).createGlyphVector(frc, textArray);
14051403
Shape shp = gv.getOutline();
14061404
iter = shp.getPathIterator(null);

0 commit comments

Comments
 (0)