Problem with custom fonts (since 2.0.4) & cocos builder

Hey, I ran into a bug with with cocos builder and the new 2.0.4 release.

It works fine on android, however on ios, since you have to register your font and refer to it without the extension, it simply doesn’t work.

I’m not sure it has been reported yet. I couldn’t find it in the forum.

However, i made a liitle fix in order ot make it work by just removing the extension of the ttf file:

    CCString * CCNodeLoader::parsePropTypeFontTTF(CCNode * pNode, CCNode * pParent, CCBReader * pCCBReader) {
    CCString * fontTTF = pCCBReader->readCachedString();

    std::string tmp(fontTTF->getCString());
    if (tmp.find_last_of(".ttf") > 0) {
      return CCString::create(tmp.substr(0, tmp.find_last_of(".ttf") - 3));
    }

    // CCString * ttfEnding = CCString::create(".ttf");

    // TODO Fix me if it is wrong
    /* If the fontTTF comes with the ".ttf" extension, prepend the absolute path. 
     * System fonts come without the ".ttf" extension and do not need the path prepended. */
    /*
    if(CCBReader::endsWith(CCBReader::toLowerCase(fontTTF), ttfEnding)){
        fontTTF = CCBReader::concat(pCCBReader->getCCBRootPath(), fontTTF);
    }
     */

    return fontTTF;
}

Cheers,
BQ.

Great, save my day. And the prefix path should be removed if we put the .ttf file in a sub dir.

CCString * CCNodeLoader::parsePropTypeFontTTF(CCNode * pNode, CCNode * pParent, CCBReader * pCCBReader) {
    CCString * fontTTF = pCCBReader->readCachedString();
 #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
    return CCBReader::deletePathExtension(CCBReader::lastPathComponent(fontTTF));
#else
    return fontTTF;
#endif
}

I am using cocos 3.0 alpha2 and coco2d-x-2.1beta3. Le Yang’s fix doesn’t work. I see my custom font in cocosbuilder but on device I can’t. Do I have do something with project or plist file to support custom fonts from Cocosbuilder ?

for cocos2dx-2.1.1, the fix should change to this:

std::string CCNodeLoader::parsePropTypeFontTTF(CCNode * pNode, CCNode * pParent, CCBReader * pCCBReader) {
    std::string fontTTF = pCCBReader->readCachedString();
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
    return CCBReader::deletePathExtension(CCBReader::lastPathComponent(fontTTF.c_str()).c_str());
#else
    return fontTTF;
#endif
}

You should add font names to Info.plist, as always.

Thanks :slight_smile:

Ok. Now I have different problem. Fonts work great on device but not on simulator. Do you have any idea ?

I am using cocosbuilder 3 alpha 5. I have tried different combinations of including ttf extension and not in plist files, in actual file names etc… None of them work.

However, I do not get any logs about not finding a file or unable to load the files….

I tried searching about it, but couldn’t find anything. How do I go about debugging what the issue is?

I see that CCNodeLoader simply returns the entire path as provided in the CCB to setFontName with the full path. This will not work on iOS as iOS needs fonts to be mentioned in the plist file beforehand and just the font name for setFontName - is there a possible way in which I can get this working without having to edit source files (CCNodeLoader) ?

Thank you for answer ! :slight_smile: but I don’t have access to my old cocos2d-x project. I can’t answer on your question.