You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
textAscent() rendering issue post-changes in Processing 4.3 #21
After the processing/processing4@c57069f update to use calculated text height instead of OS ascent for vertical centering, the textAscent() example seems to be broken in Processing 4.3. The function no longer aligns correctly with the top of the letter 'd' as described in the official documentation.
In Processing 4.3, the horizontal line is rendered below the top of the letter 'd'.
In Processing 4.2, the line was above the top of the letter 'd'.
Neither version aligns with the official documentation.
Steps to Reproduce
Run the provided textAscent() example code in both Processing 4.2 and 4.3.
Observe the misalignment of the horizontal line with the letter 'd'.
Compare the output with the expected outcome from the documentation.
Your Environment
Processing version: 4.3
Operating System and OS version: MacOS 13.4 (22F66)
Upon further investigation, it appears that the issue lies with the example provided rather than the textAscent() function itself. The use of the scalar in the example code seems to be causing the observed misalignment.
The example can be simplified like so:
size(400, 400);
floatbase = height * 0.75;
textSize(128); // Set initial text sizefloata = textAscent(); // Calc ascentline(0, base-a, width, base-a);
text("dp", 0, base); // Draw text on baselinetextSize(256); // Increase text sizea = textAscent(); // Recalc ascentline(160, base-a, width, base-a);
text("dp", 160, base); // Draw text on baseline
Below is a more advanced example showing that textAscent() works correctly for all fonts, without scalar adjustment:
PFontcurrentFont;
String[] fontList;
intfontIndex = 0;
voidsetup() {
size(400, 400);
frameRate(2);
fontList = PFont.list();
printArray(fontList);
}
voiddraw() {
background(150); // Clear the screen every frame// Get the next font from the listStringfontName = fontList[fontIndex];
currentFont = createFont(fontName, 256);
textFont(currentFont);
floatbase = height * 0.75;
translate(0,base);
textSize(128); // Set initial text sizefloata = textAscent(); // Calculate ascentline(0, -a, width, -a);
text("dp", 0, 0); // Draw text on baselinetextSize(256); // Increase text sizea = textAscent(); // Recalculate ascentline(160, -a, width, -a);
text("dp", 160, 0); // Draw text on baseline// Move to the next font for the next framefontIndex = (fontIndex + 1) % fontList.length;
}
Activity
SableRaf commentedon Aug 3, 2023
Upon further investigation, it appears that the issue lies with the example provided rather than the
textAscent()function itself. The use of the scalar in the example code seems to be causing the observed misalignment.The example can be simplified like so:
Below is a more advanced example showing that textAscent() works correctly for all fonts, without scalar adjustment:
SableRaf commentedon Aug 3, 2023
The following example shows that both
textAscent()andtextDescent()work without the need for scaling, on different fonts, and at various font sizes: