Cant use Custom .ttf fonts in v 2.1.5 / 2.2.1 / 3.0

Well i hav used this(1) guide as well as this(2)to use my custom font “Flavors-Regular”(you can search it on net) but i am unable to use it…
I am on a mac developing for iOS…desparately used versions 2.1.5 / 2.2.1 / 3.0 for this to be working…but to no relief…
i have updated my Info.plist with “fonts/Flavors-Regular.ttf”…

i have used this code to use the font in a label :

CCLabelTTF* pLabel = CCLabelTTF::create("Hello World","Flavors-Regular",24);

Link (1) : http://www.cocos2d-x.org/wiki/How_to_Use_Custom_TTF_Font_on_iOS
Link (2) : http://cocos2d-x.org/forums/6/topics/46513

What’s the problem ?

Did you include the font in your Resources folder ?

Can you post a link to the font so we can test with it ?

yup its in the Resources folder…and in the Info.plist as well…

Here’s the link :

Try to rename it Flavors.ttf

For a reason I do not know, iOS is finicky with fonts name. It has to match what’s shown in FontBook (try to open the ttf then install the font. It should give you warnings. If you open the font, you should see the “real name” iOS wants).

That way, it works for me on iOS (running v2.2).

I am having the same issue (using Cocos2D-X 3.0 / iOS)

I can use the “Market Felt.ttf” font included by default in the project, but not my font.

I am able to load the “Market Felt.ttf” font using only the font name or the whole path

auto label = LabelTTF::create("Hello World", "Marker Felt", 24);
and
auto label = LabelTTF::create("Hello World", "fonts/Marker Felt.ttf", 24);

Why the “Market Felt.ttf” font is not in the info.plist? And why is it found?

As rammehta, I have updated my info.plist with the path to my font and I have it under the “Resources/fonts” path. Any ideas?

I haven’t tested yet this issue in other platforms.

@Fradow wrote:

Try to rename it Flavors.ttf

For a reason I do not know, iOS is finicky with fonts name. It has to match what’s shown in FontBook (try to open the ttf then install the font. It should give you warnings. If you open the font, you should see the “real name” iOS wants).

That way, it works for me on iOS (running v2.2).

I haven’t had any luck renaming my font that way…

Here is my font: https://www.dropbox.com/s/y2vo2ygo6wyqmet/HelveticaNeueLTPro-UltLt.ttf

iOS (as any OS) package some default fonts. You don’t want to use them for a cross-platform project, because it varies by device (it’s always better to include your tff. That way no surprise).

@vns what’s the font you are using ?

Thanks for the answer. I edited my previous post with a link to my font.

I renamed it “Helvetica Neue LT Pro.ttf”. Works perfectly. Did you try with that file name ? Is the font included in your project ? Not only in the Resources folder, but in the right panel “target membership” in Xcode.

Yes, I tried with that file name.

This is what I am doing:

  • I drag & drop the font into the fonts folder in XCode, I check “Destination: Copy…” and “Add to targets: iOS”
  • Then I eddit the Info.plist for iOS, Fonts provided by application: item0 = “fonts/Helvetica Neue LT Pro.ttf”
  • Finally I try to use it:
    auto label = LabelTTF::create("Hello World", "Helvetica Neue LT Pro", 24);

I have checked that the font is packaged into the bundle, Copy Bundle Resources: “fonts/Helvetica Neue LT Pro.ttf …in …Resources/fonts”

I have tried with other font that I am using in a regular iOS project with the same result.

Thank you again for your help

I can’t really help you anymore. I do the exact same steps, and it works.

@Fradow …i havnt tried it…but can we actually rename the font !! ??

Also i have looked up in the fontbook and i remember somewhere i read that we need to use the PostScript name of the font for using it in the project…

Anyways thnks for the help mate…always appreciated !!

You can rename the file name easily. Changing what you call the PostScript name (didn’t know the name), on the other hand, may be me complicated, since you have to edit the ttf file directly.

@vns wrote:

  • Then I eddit the Info.plist for iOS, Fonts provided by application: item0 = “fonts/Helvetica Neue LT Pro.ttf”

the right string in the Info.plist is “Helvetica Neue LT Pro.ttf”, the “fonts/” part is not needed. Now is working for me :slight_smile:

Thank you very much for the help!