Custom Font problems

Hi,

i try to use custom, embeded fonts, but it does not work.

I have uses the FontSerializer and with the BinaryBuilder i have created the .cpp and .h file. That files I have included in my project and like to use that font e.g. for a label text.

Here a sample code (i found in the forum).

Font* myNewFont = NULL;
MemoryInputStream font_stream(MyFont::MyFont_ttf, MyFont::MyFont_ttfSize, false);
Typeface* typeFace = new CustomTypeface (font_stream);
myNewFont = new Font (typeFace);
 

aLabel->setFont(*typeFace);

But the label did not use this font to render the text.

What do I wrong? 

Thanks

If you have no glyph in your font, then a fallback font will be used anyway.

If you used the font serialiser, then why is it called "MyFont.ttf"?

Anyway, nowadays I'd actually recommend using this instead: http://www.juce.com/forum/topic/embedded-font-support

If you used the font serialiser, then why is it called "MyFont.ttf"?

I have used the original font file name with extension for the generated.

Anyway, nowadays I'd actually recommend using this instead: http://www.juce.com/forum/topic/embedded-font-support

I will try this way now.

 

Thanks!

This works very well!

I have spend two days to read across the forum and tried X-ways - but/and this I did not find in your api docu.

Thanks a lot!!!

Good point - I'll add a note somewhere about this..

I have tested it on iOS, but it's not working. Is there also an easy way to get it working on iOS?

Are you sure? iOS uses the same code as for OSX.

Little moment, i have only tested it with Linux and iOS yet.

Yes, on OSX it works (tested on 10.9).

Excuse me! There was some out commented code for IOS!

It works!!

Hi monotomy,

 

can you share with us how you made it ?

 

Thanks,

Paulo

Hi Paulo,

sorry, I was a week offline.

You simply add the font as binary resource to a gui file/class with the introjucer and then use the resource like this:

a_label->setFont( 
  Typeface::createSystemTypefaceFor(
    font_added_as_resource_in_jucer_ttf,
    font_added_as_resource_in_jucer_ttfSize ) );

Thats all.
Does this help?

Cheers

1 Like