Skip to content

Commit c57069f

Browse files
committed
Use calculated text height instead of OS ascent for better vertical centering (fixes #739)
1 parent fb20a17 commit c57069f

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

core/src/processing/awt/PGraphicsJava2D.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1873,10 +1873,16 @@ public float textAscent() {
18731873
defaultFontOrDeath("textAscent");
18741874
}
18751875

1876+
// This value is dreadfully inaccurate and inconsistent, and especially
1877+
// so for the default font. Switching to use our built-in calculation since
1878+
// our most common use case is likely textAlign(CENTER, CENTER) with the
1879+
// default font, and it needs to work well there. [fry 230716]
1880+
/*
18761881
Font font = (Font) textFont.getNative();
18771882
if (font != null) {
18781883
return g2.getFontMetrics(font).getAscent();
18791884
}
1885+
*/
18801886
return super.textAscent();
18811887
}
18821888

@@ -1886,10 +1892,12 @@ public float textDescent() {
18861892
if (textFont == null) {
18871893
defaultFontOrDeath("textDescent");
18881894
}
1895+
/*
18891896
Font font = (Font) textFont.getNative();
18901897
if (font != null) {
18911898
return g2.getFontMetrics(font).getDescent();
18921899
}
1900+
*/
18931901
return super.textDescent();
18941902
}
18951903

todo.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
1293 (4.2.1)
22
X `NullPointerException` when background exceeds color range when writing PDF
33
X https://github.com/processing/processing4/issues/740
4+
X Use calculated text height instead of OS ascent for better vertical centering
5+
X https://github.com/processing/processing4/issues/739
46

57
sampottinger
68
X Syntax error highlighting placement / width incorrect

0 commit comments

Comments
 (0)