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
- import processing.pdf.*;
- String[] textData;
- float pointSize = 2;
- float leading = 3;
- float xBorder;
- float yBorder;
- float x;
- float y;
- int widthMax;
- PFont f;
- int grey = 0;
- void setup(){
- size(400, 400, PDF, "test.pdf");
- println("Width and height are " + width);
- f = createFont("c:/windows/fonts/cour.ttf", pointSize, true);
- textData = loadStrings("text.txt"); // populate array
- println("There are " + textData.length + " lines");
- }
- void draw(){
- background(255);
- textAlign(RIGHT);
- textFont(f, pointSize);
- fill(grey,grey,grey);
- xBorder = 10;
- yBorder = 20;
- x = width - xBorder;
- y = height - yBorder;
- for(int i = 0; i < textData.length; i++){
- widthMax = max(widthMax, int(textWidth(textData[i])));
- text(textData[i], x, y);
- y = y - leading;
- if(y <= yBorder){
- x = x - widthMax - xBorder;
- y = height - yBorder;
- }
- }
- noLoop();
- println("The maximum width is " + widthMax);
- println("Finished.");
- exit();
- }
1