Loading...
Logo
Processing Forum
On any sketch I make, text looks absolutely horrible unless I create something larger than intended size (like 96 for size 48) and use that font, shrunk down, to create text. And if I shrink it down too much, it begins to display incorrectly again.

Characters are not only overly pixelated and blurry, they also clip the top and left sides of the text off.
Am I doing something wrong? It's only sketches that I create, sketches on the website look fine, and I get the same results when I use the same font and the same size as the examples.

The following code produced this image for me:
Any idea what I'm doing wrong?
Copy code
  1. void setup(){
  2. size(100, 100, P2D);
  3. PFont f = createFont("ArialMT-16", 16, true);
  4. textFont(f,16);
  5. fill(0);
  6. noLoop();
  7. }
  8. void draw(){
  9.   background(255);
  10.   text("example",16,16);
  11. }

  12. void mousePressed() 
  13. {
  14.   save("failtext.tif");
  15. }

Replies(8)

I think that the problem here is that particular font- it doesn't seem to like displaying at small sizes.
If you increase the size, or try a different font, it should look better.
I don't have time to test it right now, but I will get back to you as soon as I can.
if you use JAVA2D, the font will be displayed correctly.

size(100, 100, JAVA2D); // or just size(100, 100);



if you still want to use P2D, than you could insert

textMode(SCREEN);

inside setup(). but as far as i can remember this can slow down the sketch very much.
That solved the problem, thanks.
The ArialMT-16 name is strange... Perhaps it isn't found on the system and using a default font.
With createFont, I use names as seen in font selectors, like "Arial", "Tahoma", "Lucida Sans Unicode", "Bitstream Vera Sans Mono", and so on.
I guess the "-16" should prevent it from recognizing it as ArialMT (not sure what I was thinking there), but it produced the same result as creating a size 16 ArialMT font and loading it from the font selector.
Your answer is strange. Either you use createFont("ArialMT", 16), or a loadFont("ArialMT-16.vlw") if you generated the font beforehand.
As said, in Java2D mode, the former redraws the font on each use, can be slower, but works well if you use several sizes.
Sorry for the confusion. I initially noticed this problem in a much larger project where I had generated the font beforehand and used load font. I didn't want to include the entire thing, so I made this for an example then just copied and pasted the loadFont() line, changed it to createFont, added the size, and removed the .vlw but didn't think to remove the '-16' from the end.

I'm not really sure why this even works, maybe createFont() can recognize the font name and ignore the size denotation.
Another tip is to put this in your setup().
 
hint(ENABLE_NATIVE_FONTS);
 
This tries to use the Java2D fonts.