Skip to content

Commit 9f18cab

Browse files
committed
bring back older style ascent/descent values
1 parent 61b2012 commit 9f18cab

2 files changed

Lines changed: 33 additions & 4 deletions

File tree

core/src/processing/core/PFont.java

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

todo.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@ X updated about.jpg
44
X Cannot find PDF library
55
X http://dev.processing.org/bugs/show_bug.cgi?id=1473
66
X new examples.zip
7+
o Fixes for invoking Processing from arbitrary locations
8+
X already fixed with earlier code
9+
X http://dev.processing.org/bugs/show_bug.cgi?id=1214
10+
X bring back old-style textAscent()
11+
X needs to just quickly run characters d and p
12+
X only takes a couple ms, so no problem
713

8-
_ bring back old-style textAscent()
9-
_ needs to just quickly run characters H and q or whatever
1014
_ pdf library
1115
_ throw an error with the black boxes
1216
_ throw an error if loading fonts from a file, and not using mode(SHAPE)

0 commit comments

Comments
 (0)