Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
Posts: 15
Registered: ‎11-17-2011
My Device: Playbook
My Carrier: Vodafone
Accepted Solution

Using custom fonts with the NDK

Hi. I'm developing a simple game with the NDK and would like to know if anyone knows how i can load a custom font to the playbook to use in my game. I've tried copying it with the rest of the resources and loading it from there, but when I try to load the font with the "FT_New_Face" function I get an error, and the error code that it returns is 1. I tried with different fonts ( ttf and otf ) and the result is always the same. Does anyone know how i can solve this, or even if this is possible? Thanks.
Developer
Posts: 541
Registered: ‎05-17-2009
My Device: Not Specified

Re: Using custom fonts with the NDK

Just to confirm, I tried using bbutil_load_font() and bbutil_render_text() with my packaged TTF fonts and get "Error loading font."

 

Scott

Retired
Posts: 36
Registered: ‎10-26-2011
My Device: RIM Developer
My Carrier: Rogers

Re: Using custom fonts with the NDK

Hey superdirt.

 

I suspect you did not specify a proper path to your ttf/otf. How does your bar-descriptor source look like for your font asset?

 

And what path do you specify for bbutil_load_font?

Developer
Posts: 15
Registered: ‎11-17-2011
My Device: Playbook
My Carrier: Vodafone

Re: Using custom fonts with the NDK

Hi dtomilovskiy

 

In my case, I loaded the font as a normal resource. In my bar-descriptor.xml file, the reference to the font is as follows:

    <asset path="resources/BPdotsSquare.otf">BPdotsSquare.otf</asset>

 

and the line of code i'm using to load the font is this one:

        _font = bbutil_load_font("/app/native/BPdotsSquare.otf", 15, dpi);

 

After calling the bbutil_load_font function, I get the error that superdirt described "Error loading font.". I dug a little inside the bbutil_load_font function, and the point where it fails is when calling the FT_New_Face function.

 

I don't know if this is relevant or not, but I'm trying to run this on the Simulator.

 

Nuno Castro

Developer
Posts: 541
Registered: ‎05-17-2009
My Device: Not Specified

Re: Using custom fonts with the NDK

Line in bar-descriptor:

 

<asset path="BILLH___.TTF">BILLH___.TTF</asset>

 

Code for loading:

 

	fontbig = bbutil_load_font("/app/native/BILLH___.TTF", 35, dpi);

 

 This gives me the error:

Error loading font /app/native/BILLH___.TTF

 

 

Scott

Developer
Posts: 541
Registered: ‎05-17-2009
My Device: Not Specified

Re: Using custom fonts with the NDK

I found the problem on my end, a typo. The path should contain no leading "/":

 

"app/native/BILLH___.TTF"

 

 

Scott

Highlighted
Developer
Posts: 15
Registered: ‎11-17-2011
My Device: Playbook
My Carrier: Vodafone

Re: Using custom fonts with the NDK

After seeing your post I checked my code and had the same typo.

 

Thanks for the insight  Smiley Happy

 

Nuno Castro