@@ -195,8 +195,11 @@ public PFont(Font font, boolean smooth, char charset[]) {
195195 lazyMetrics = lazyGraphics .getFontMetrics ();
196196 lazySamples = new int [mbox3 * mbox3 ];
197197
198- ascent = lazyMetrics .getAscent ();
199- descent = lazyMetrics .getDescent ();
198+ // These values are terrible/unusable. Verified again for Processing 1.1.
199+ // They vary widely per-platform and per-font, so instead we'll use the
200+ // calculate-by-hand method of measuring pixels in characters.
201+ //ascent = lazyMetrics.getAscent();
202+ //descent = lazyMetrics.getDescent();
200203
201204 if (charset != null ) {
202205 // charset needs to be sorted to make index lookup run more quickly
@@ -239,6 +242,28 @@ public PFont(Font font, boolean smooth, char charset[]) {
239242// }
240243// }
241244 }
245+
246+ // If not already created, just create these two characters to calculate
247+ // the ascent and descent values for the font. This was tested to only
248+ // require 5-10 ms on a 2.4 GHz MacBook Pro.
249+ // In versions 1.0.9 and earlier, fonts that could not display d or p
250+ // used the max up/down values as calculated by looking through the font.
251+ // That's no longer valid with the auto-generating fonts, so we'll just
252+ // use getAscent() and getDescent() in such (minor) cases.
253+ if (ascent == 0 ) {
254+ if (font .canDisplay ('d' )) {
255+ new Glyph ('d' );
256+ } else {
257+ ascent = lazyMetrics .getAscent ();
258+ }
259+ }
260+ if (descent == 0 ) {
261+ if (font .canDisplay ('p' )) {
262+ new Glyph ('p' );
263+ } else {
264+ descent = lazyMetrics .getDescent ();
265+ }
266+ }
242267 }
243268
244269
0 commit comments