Bug in ofxTrueTypeFontUC

I first want to say that ofxTrueTypeFontUC is an amazing addon to get unicode characters rendering on screen in OpenFrameworks. I am having some difficulty getting it to do exactly what I want though. Specifically, I can’t figure out how to use more than one font at a time because it seems like ofxTrueTypeFontUC renders text using the chronologically-last font that was loaded into any ofxTrueTypeFontUC object and even then weirdness abounds. I only get the letter ‘p’ to render from the first chronological font that is loaded.

IE. Suppose that ‘italic.ttf’ and ‘bold.ttf’ are font files.

  
  
ofxTrueTypeFontUC italicFont;  
ofxTrueTypeFontUC boldFont;  
  
italicFont.loadFont("italic.ttf");  
boldFont.loadFont("bold.ttf");  
  
italicFont.drawString("[http://en.wikipedia.org/wiki/William-Shatner",0,0](http://en.wikipedia.org/wiki/William-Shatner",0,0));  
boldFont.drawString("[http://en.wikipedia.org/wiki/William-Shatner",0,0](http://en.wikipedia.org/wiki/William-Shatner",0,0));  
  

renders:

http://en.wikipedia.org/wiki/William_Shatner
http://en.wikipedia.org/wiki/William_Shatner

instead of what I would have expected:

http://e[i]n.wikipedia.org/wiki/William_Shatner[/i]
htt[b]p://en.wikipedia.org/wiki/William_Shatner[/b]

The only partial-solution I was able to find was using ofxTrueTypeFontUC.reload() prior to drawing a given string. Although this prints with the correct font it dramatically slows rendering with even a little text with different fonts and and eventually crashes after a few minutes.

Have you found a solution? I’m faced with the same problem.

I’m trying to load a same font but at different sizes, so my solution is to use ofScale() everytime I draw texts at another size, but it has an awkward effect especially with serif font.

i had no problem with this on a recent project (running OF0.8 on osx) – successfully used fonts for bold, italics and normal text.

feel free to post some code …

This is the simplest code to show the bug.

testApp.h

class testApp : public ofBaseApp{
    /* definitions */
    ofxTrueTypeFontUC font1;
    ofxTrueTypeFontUC font2;
};

testApp.cpp

void testApp::setup(){
    font1.loadFont("Arial Bold.ttf", 32);
    font2.loadFont("Arial.ttf", 32);
}

void testApp::draw(){
    font1.drawString("Arial Bold", 300, 300);
    font2.drawString("Arial", 300, 340);
}

And this is the result.

When I change the setup() to this

void testApp::setup(){
    font2.loadFont("Arial.ttf", 32);
    font1.loadFont("Arial Bold.ttf", 32);
}

the result is like this.

I’m running oF0.8 on OS X Mavericks.

@kokinomura, presumably you’re using the latest version of the add-on? feel free to send the add-on over for me to test out (though i have an identical setup).

what happens if you use ofTrueTypeFont?

Thank you @mantissa, it’s the latest version. If I use ofTrueTypeFont, it works. But I want to draw Japanese strings, so I need ofxTrueTypeFontUC.<a class=“attachment”

And this is the source files of ofxTrueTypeFontUC I’m using.

ofxTrueTypeFontUC_src.zip (11.0 KB)

I guess the problem is a global variable FT_Face face in ofxTrueTypeFontUC.cpp.

So I commented out this line.

static FT_Face face;

And I added that in ofxTrueTypeFontUC::Impl class definition.

class ofxTrueTypeFontUC::Impl {
    /* definitions */
    FT_Face face;
}

Then it works though I’m not 100% sure. Can someone test it?

@koki it looks like i was the one running an older version of ofxTrueTypeFontUC. indeed, when i run this attached version (which looks like it was updated about a month ago) i get the behavior you described.

i wasn’t able to get the add-on to compile with the changes you recommended – but i can share with you the earlier version that i was using. src.zip (10.3 KB)

i recommend reaching out to the developer and describing the problem.

Thank you @mantissa, what you attached is like a version I changed, and it works well.

I will contact the developer.

Thanks

Hello. I’ve just fixed it. Thank you for letting me know!