Drawing special characters with ofTrueTypeFont

Hi All !

I’m loading some dynamic text from an XML file and rendering it to the screen in windows 7 using code::blocks on release 007. I’m drawing paragraph text using ofxTextSuite which is using ofTrueTypeFont for the actual rendering. I’m loading a full character set but I’m having a troubling time drawing the “em dash” http://www.fileformat.info/info/unicode/char/2014/index.htm . After looking through the forums I saw that several people had trouble with other more exotic characters such as Chinese or Japanese typefaces and their solution was to use ofxFTGL. My question is : can I draw these special characters using ofTrueTypeFont ? Or is this an inherent limitation and would it be more beneficial / better handled by something like ofxFTGL ? I’m just worried I’ll loose out on all the great paragraph text feature of ofxTextSuite if I have to switch.

Thanks for your feedback !

Hi !

Maybe it’s too late for you, but I’ve just stumbled upon a similar problem.

Basically, ofTrueTypeFont loads the 256 first characters in the font file, ordered by unicode code. It works fine for most of the ascii characters, but for a couple of special symbols (including the em dash) their unicode value and their ascii value mismatch and therefore it will draw the wrong character.

You can fix it by slightly modifying ofTrueTypeFont (by replacing the ascii value of the special character by its unicode value, when FT_Load_Glyph is called)

I can post my fix if needed…

ofTrueTypeFont assumes the Latin-1 (ISO-8859-1) string encoding. To support the full unicode character set would require re-programming the way ofTrueTypeFont loads fonts so that it can dynamically load and unload characters, as there are >110,000 unicode characters.

for a really good primer on character sets see this article “The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)” http://www.joelonsoftware.com/articles/Unicode.html

Thanks for the article Damian ! I didn’t really have a good grasp on how character sets worked before but now I think I’m starting to get it.

Just to precise what I was saying, in Windows-1252 coding (sometimes called (wrongly) ANSI), the range 80 to 9F is used to code special symbols (including the em dash, curly quotes, euro sign,…) rather than non printable characters.
To me, it was sort of unsettling that when I loaded the font using the ‘full characterset’ and then asking it to display one of those special character which lays in the 80-9F range (in the Windows-1252 encoding) it wasn’t displayed properly even though it wasnt a fancy utf-8 character coded on multiple bytes.

Then it makes sense that for something as interoprable as oF, using a windows encoding shouldn’t be the expected behaviour. But anyway, my point was that just with a couple of tweaks, you can have certain useful symbols ‘working’ while keeping ofTrueTypeFont/ofxTextSuite. The drawback is that handling the Windows-1252 encoding accross different computers might be tricky.

Hmm. That’s an interesting point silverbahamut. The project I had originally intended this for had it’s copy changed to not include special characters. It looks like to develop a more complete localization mechanism I might have to veer away from ofxTextSuite and ofTrueTypeFont. The forums tell me that ofxFTGL has pretty good character support so I’ll probably start there.

i agree that ofTrueTypeFont should be smarter about character sets. the biggest issue is that the way strings are encoded in C++ is not very smart, and that a lot of us don’t actually understand how character sets work.

there’s an issue on github about it here: https://github.com/openframeworks/openFrameworks/issues/1468