benfry / processing4

Processing 4.x releases for Java 17
https://processing.org
Other
1.35k stars 239 forks source link

Text mis-aligned when scaling and using `textSize()` with `P2D` #425

Open Santarii opened 2 years ago

Santarii commented 2 years ago

Expected Behavior

If I use the scale function and then use the textSize function to reverse that scaling, I expect to get the same result as just rendering the text without any scaling.

Current Behavior

In the default renderer the text is lower than it should be when scaled up then sized back down. In P2D the space between characters also changes.

Steps to Reproduce

float scale = 1;

void setup() {
  size(1920, 1080, P2D);
  textFont(createFont("Consolas", 256));
}

void draw() {
  scale += 1;
  scale(scale);
  background(0);
  textAlign(LEFT, TOP);
  textSize(256f/scale);
  text("Wow", 0, 0);
}

This code renders text, and each frame increases the scale, but the scale is exactly reversed with the textSize function. If the bug didn't exist, this would look like stationary unchanging text, however this is not the case.

Your Environment

Possible Causes / Solutions

It seems to not just be small values in textSize, even reasonable values mess with the alignment a bit, though very small values have a more significant effect.

Santarii commented 2 years ago

I should add that the behaviour is also inconsistent from the last version I was using of Processing 3, 3.5.4.

For certain values of scale (in particular for the value I was using in a project I was trying to port over) you get very different results.

Removing the scale incrementing line and initialising scale to 1080:

Processing 4:

image

Processing 3:

image

Processing 3 was much closer to correct for this specific scale value but it still had the same issues for other values.

benfry commented 1 year ago

Probably the same issue: https://github.com/processing/processing4/issues/700