ofTrueTypeFont resolution

OK so this is something that has been KILLING me with openFrameworks for a long time, and I almost tried to see if I could compile a different font handling library because of it.

Fonts don’t look right with ofTrueTypeFont. I mock things up in photoshop and the font sizes are just way off when I put them into OF. Also any smaller type (body type) just looks terrible, its really off, sort of like when you have a font in photoshop that isn’t on whole pixels.

I did some searching a month or two on the forums, really just seeing if there was any hope, and I came across this discussion between Moka and Arturo in the linux forum:

http://forum.openframeworks.cc/t/aliasedpixelfonts-ubuntu/2515/2

Basically the default font resolution for freetype is 96dpi. Why, I have no clue, but this explains everything. Screens/OSs use 72dpi for fonts, and fonts are designed for 72dpi. The change is super simple,

change
FT_Set_Char_Size( face, fontsize << 6, fontsize << 6, 96, 96);

to

FT_Set_Char_Size( face, fontsize << 6, fontsize << 6, 72, 72);

and everything looks super crisp and perfect.

This is a really frustrating problem but it has a super simple fix, its the first thing I do every time I download a new release of OF. Putting this change into future releases makes a lot of sense I think. If there is a reason for 96dpi, I think 72dpi should be default and there should be a simple method for changing it (setResolution(int resolution) or something like that).

Hope that makes sense
-Steve

seems really interesting !

But where does this change has to be done and does it work also with the new compiled version of OF ?

Yea totally it should work with every version,

You can change the compiled version of OF, it depends on which OS, i’m not sure about linux/windows but in XCode you can just double click the compiled project inside your project and it’ll open up the core. You can change this and next time you compile any app it’ll recompile the core. So sweet.

The change needs to be made within the ofTrueTypeFont.cpp (or .h, currently reinstalling xcode after a bad experience with 3.2 iphone sdk and OF but thats another story)

-Steve

I tested it (on mac and pc) but the quality is still bad, only the size is smaller.
Maybe it works only with certain fonts ?

I think the quality issue you are seeing is to do with the extra pixels we put in the texture to prevent clipping of the edges of the font. We pad the texture with a couple of extra pixels and then compensate for it when we draw.

You can see an example of what the type would look like if we didn’t do this here:
http://forum.openframeworks.cc/t/ofxsvg-/3250/3

Look at the top of the letters of “svg.setup” in the FTGL ( freetype GL ) example.
Also the top of the ‘o’ in ofSetCircleResolution - you can see a clipping of the type.

The side effect of our fix is that there is a small amount of stretching which goes on which results in a slightly fuzzier image.

I think there is a way to do this without the stretching - we’ll put this on the list for 062 / 007.

Theo

Awesome, thanks Theo. Yea the 72dpi seems to work a lot better for me but there still is some weirdness, I figured there was some reason for the 96dpi since the default is 72dpi and its going out of its way to declare it.

Look forward to seeing it!

-Steve