hello world, drawString and accents

Hello.
I’m just diving into the world of openframeworks and while trying a hello world, I had a small problem.

I tried the following:

  
  
franklin.loadFont("verdana.ttf", 18, true, true);  
franklin.drawString("Olá Mundo!", 10, 10);  
  

But instead of the “á” with an accent mark I got a square.
I know I could do something like:

  
  
franklin.drawString("Ol\xEF Mundo!!",10,10);  
  

But is there a better solution? I read that some people have used FTGL, but since most of the posts I read about it were quite old, I was wondering if that is in fact the best solution.

Thank you for your help,
HEMOglobina

I have an explanation, because I had the same problem :

I suppose the text format of your source file is UTF-8.
But the format drawString uses is Latin 1

So you have to save your source file in Latin 1 format (look into some preferences) or load your strings from a text file that is saved as Latin 1

Hello bernard!
Thanks a lot! It worked really well! Really appreciated!

thanks a lot! i had been struggling with this for quite a while. :wink:

That’s a coincidence!

A couple of hours ago I was having fun with fonts / utf8 as well. I’m not sure what the status of utf8, fonts, text-layout is in openFrameworks, though as far as I can find there is the ofTrueTypeFont and some experiments with FTGL.

Yesterday I tried FTGL and I’ve to say it works quite okay though I’m having some problemns with positioning the text nicely :). FTGL even has wordwrap features though they don’t make use of the position which you can pass to layout->Render().

So I did some googling and I’ve to say I’m a bit surprised about the state of text-rendering. It seems to be a not so trivial thing. There is a nice write up on the state of text-rendering from 18 jan 2010: http://behdad.org/text/

The most promising and active solution seems to be url http=[http://www.pango.org]pango[/url] together with
url http=[http://www.cairographics.org/]cairo[/url]. I know Todd has started an ofxCairo addon which worked very nice last time I used it, though I’m not sure what the status is now or if someone started with a ofxPango?

Greetings
Roxlu

[quote author=“roxlu”]
Yesterday I tried FTGL and I’ve to say it works quite okay though I’m having some problemns with positioning the text nicely :slight_smile:
Meanwhile I will keep my eyes open for Cairo and Pango.
Thanks!
HEMOglobina

Hello,

I know this is an old topic but anyway.

I am having the same problem: I am using ofTrueTypeFont and want to display some characters like “üõäš” and so on.

Does any body has an easy way to do this?

Cheers!

I´m not sure if this is the easiest way but you can replace ofTrueTypeFont with ofxTrueTypeFontUC by using this addon:

https://github.com/hironishihara/ofxTrueTypeFontUC

That will give you a font object with Unicode support with the same methods as ofTrueTypeFont. You also need to change the “Text encoding” settings of your document to “UTF-8” to make it work. In Xcode if you try to paste the text “üõäš” into the document it will prompt a dialog offering that option or check the utilities panel on the right.

After all that you can do:

  
font.drawString("üõäš", xpos, ypos);  

Assuming the ttf font you have loaded contains those characters.

Hi Pelayo,

Thanks for this: I tried the addon and it works perfectly!