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

textAlign(RIGHT) problem with PDF export at small pt sizes

$
0
0
Hi all

The code below writes text from a file to columns, backwards from the bottom right of the screen, and outputs to PDF.

I'd like to work with quite small pt sizes, but anything below 5pt doesn't justify right correctly - this is what 2pt looks like:


At least it's being consistent, but I can't tell what the problem is (number of spaces for instance - although it's a monotype font) or how to fix it.

Incidentally, although it's hard to tell because of the small pt size, I don't think processing has the same issue when it just renders to the window.

I suppose I could just use larger pt sizes and then scale the PDF down, but I've annoyed myself with the problem now.

Any help much appreciated

P

  1. import processing.pdf.*;

  2. String[] textData;

  3. float pointSize = 2;
  4. float leading = 3;
  5. float xBorder;
  6. float yBorder;
  7. float x;
  8. float y;
  9. int widthMax;

  10. PFont f;
  11. int grey = 0;

  12. void setup(){
  13.   
  14.   size(400, 400, PDF, "test.pdf");                       
  15.   println("Width and height are " + width);
  16.   f = createFont("c:/windows/fonts/cour.ttf", pointSize, true);
  17.   
  18.   textData = loadStrings("text.txt");  // populate array
  19.   println("There are " + textData.length + " lines");
  20.     
  21. }

  22. void draw(){
  23.   background(255);
  24.   textAlign(RIGHT);
  25.   textFont(f, pointSize);                 
  26.   fill(grey,grey,grey);
  27.   xBorder = 10;
  28.   yBorder = 20;
  29.   
  30.   x = width - xBorder;
  31.   y = height - yBorder; 
  32.     
  33.   for(int i = 0; i < textData.length; i++){
  34.     widthMax = max(widthMax, int(textWidth(textData[i])));
  35.     text(textData[i], x, y);
  36.     y = y - leading;
  37.     if(y <= yBorder){
  38.       x = x - widthMax - xBorder;
  39.       y = height - yBorder;
  40.     }
  41.   }
  42.   noLoop();
  43.   
  44.   println("The maximum width is " + widthMax);
  45.   println("Finished.");
  46.   exit();  
  47. }


  48.  


Viewing all articles
Browse latest Browse all 1768

Trending Articles