Quantcast
Channel: Processing Forum
Viewing all articles
Browse latest Browse all 1768

Re : Scaling text

$
0
0
The alignment is working, but some fonts won't say how many pixels they increase in size correctly, so the alignment is not adjusting properly. You can get the textAscent, apply a calc on it, then use this as the start position for your Y. Also note this behaviour changes if you use P2D, P3D or OPENGL.

textAscent(). http://processing.org/reference/textAscent_.html

Here is my suggestion to start fixing this:

  1. void draw(){
  2.   calculateFFT();
  3.  
  4.   background(0);
  5.  
  6.   smooth(8);
  7.   textFont(Header, Channel[4]);
  8.  
  9.   fill(255);
  10.   textAlign(CENTER,CENTER);
  11.   float yStartPos = calculateAscent(Channel[4]);
  12.   text("H", (width/2), yStartPos);
  13. }

  14. float calculateAscent(float value) {
  15.   float base = height / 2;
  16.   float scalar = 0.1; // Different for each font, change this until you get the result you want
  17.  
  18.   float a = textAscent() * scalar;  // Calc ascent
  19.   stroke(100); // for the reference line
  20.   line(0,base-a,width,base-a); // ref purposes
  21.   return base-a;
  22. }

Viewing all articles
Browse latest Browse all 1768

Trending Articles