benfry / processing4

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

difference in text position with processing 4.3, JAVA2D vs P2D #768

Closed clankill3r closed 1 year ago

clankill3r commented 1 year ago

Processing 4.2:

mask_4 2

Processing 4.3:

mask_4 3

Ok, I will skip the part explaining that I'm an idiot.

The above difference comes from the following revision in 4.3:

"Use calculated text height instead of OS ascent for better vertical centering. Note: this may cause some sketches to look slightly different if textAlign(..., CENTER) is being used." https://github.com/processing/processing4/issues/739

Which is amazing it has been fixed! Downside is that for OpenGL it's still like the old way. Looking at the code it seems an easy fix (same as the fix for JAVA2D), which is commenting most code so it's just using super.textAscent();

https://github.com/processing/processing4/blob/c57069fdca888e614bf52caa4cb7999277ae32e0/core/src/processing/opengl/PGraphicsOpenGL.java#L3430C14-L3430C14

If such a fix would be implemented, then one extra thing that could be considered is deprecating the following two functions in PJOGL.java:

 @Override
  protected int getFontAscent(Object font) {
    return getFontMetrics((Font) font).getAscent();
  }

  @Override
  protected int getFontDescent(Object font) {
    return getFontMetrics((Font) font).getDescent();
  }
benfry commented 1 year ago

Ok, all set for the next release; probably 4.3.1.