benfry / processing4

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

TextAlign(RIGHT) not align in P2D and P3D #700

Closed knupel closed 1 year ago

knupel commented 1 year ago

When we use textAlign(RIGHT)in P2D or P3D with an odd argument passed to textSize() there is a little offset on right. maybe it's related to https://github.com/processing/processing4/issues/425

String [] str = new String[26];
int text_size = 6;
int interligne = 15;

void setup() {
  // size(400,800); // ok
  size(400,800, P2D); // problem when text size is odd
  // size(400,800, P3D); // problem when text size is odd
  // don(t text with JAVAFX, SVG abd PDF renderer
  frameRate(1);
  str[0] = "0";
  for(int i = 1 ; i < str.length ; i++) {
    str[i] = str[i-1] + String.valueOf(int(random(10)));
  }
  textAlign(RIGHT);

}

void draw() {
  background(0);
  show_text();
}

void show_text() {
  text_size++;
  interligne = floor(text_size * 1.4);
  if(text_size> 20) {
    text_size = 6;
  }

  println(text_size);

  textSize(text_size);
  // textAlign(LEFT); // OK
  textAlign(RIGHT); // KO > problem
  float x = width/2;
  for(int i = 0 ; i < str.length ; i++) {
    text(str[i], x, (i + 1) * interligne);
  }
  stroke(255);
  line(x, 0, x, height);
}
benfry commented 1 year ago

I think this is likely the same as #425 so we'll call it a duplicate for now.