-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
textAscent() rendering issue post-changes in Processing 4.3 #21
Comments
Upon further investigation, it appears that the issue lies with the example provided rather than the The example can be simplified like so: size(400, 400);
float base = height * 0.75;
textSize(128); // Set initial text size
float a = textAscent(); // Calc ascent
line(0, base-a, width, base-a);
text("dp", 0, base); // Draw text on baseline
textSize(256); // Increase text size
a = textAscent(); // Recalc ascent
line(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: PFont currentFont;
String[] fontList;
int fontIndex = 0;
void setup() {
size(400, 400);
frameRate(2);
fontList = PFont.list();
printArray(fontList);
}
void draw() {
background(150); // Clear the screen every frame
// Get the next font from the list
String fontName = fontList[fontIndex];
currentFont = createFont(fontName, 256);
textFont(currentFont);
float base = height * 0.75;
translate(0,base);
textSize(128); // Set initial text size
float a = textAscent(); // Calculate ascent
line(0, -a, width, -a);
text("dp", 0, 0); // Draw text on baseline
textSize(256); // Increase text size
a = textAscent(); // Recalculate ascent
line(160, -a, width, -a);
text("dp", 160, 0); // Draw text on baseline
// Move to the next font for the next frame
fontIndex = (fontIndex + 1) % fontList.length;
} |
The following example shows that both PFont currentFont;
String[] fontList;
int fontIndex = 0;
String[] words = {"apple", "banana", "cherry", "date", "elderberry", "fig", "grape"}; // Sample words, feel free to add more
int baseFontSize = 128;
int paddingLeft = 20;
void setup() {
size(800, 400);
frameRate(1);
fontList = PFont.list();
}
void draw() {
background(230); // Clear the screen every frame
// Get the next font from the list
String fontName = fontList[fontIndex];
currentFont = createFont(fontName, 256);
textFont(currentFont);
float base = height * 0.5;
float fontSize = baseFontSize - random(baseFontSize/2);
fill(10);
textSize(fontSize);
float a = textAscent(); // Calculate ascent
float d = textDescent(); // Calculate descent
float h = a+d; // Calculate text height
translate(0,base);
stroke(#C93737);
line(0,0,width,0); // Base line
line(0, -a, width, -a); // Ascent line
line(0, d, width, d); // Descent line
String randomWord = words[int(random(words.length))]; // Randomly select a word
text(randomWord, paddingLeft, 0); // Draw text on baseline
// Move to the next font for the next frame
fontIndex = (fontIndex + 1) % fontList.length;
} |
Description
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.Expected Behavior
The horizontal line generated from the
textAscent()
example should align with the top of the letter 'd' as shown in the documentation: https://processing.org/reference/textAscent_.html.Current Behavior
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
textAscent()
example code in both Processing 4.2 and 4.3.Your Environment
Screenshots
Expected outcome (from textAscent() documentation)
textAscent() example on Processing 4.2
textAscent() example on Processing 4.3
The text was updated successfully, but these errors were encountered: