kan don How to use custom font(ttf)?
Posts 12
Added by kan don about 2 years ago

I was try use different font call "NanumMyeongjo.ttf" and it didn't work.

I put "NanumMyeongjo.ttf" file into Resource and here are code..
CCLabelTTF* pLabel = CCLabelTTF::labelWithString("Font Test", "NanumMyeongjo.ttf", 30);

It work fine at cocos2d-iPhone.

Is there anything I missed?
thankq.

Zhe Wang RE: How to use custom font(ttf)?
Posts 1642
Location Amoy, China
Added by Zhe Wang about 2 years ago

cocos2d-iphone uses FontLabel as third-party library to parse the custom ttf file.
But we haven't implement this feature on cocos2d-x yet.
Issue #347 is created 1 month ago, but we still have no time to do it.

Enjoy Coding, Enjoy Life.

Isaac Ashdown RE: How to use custom font(ttf)?
Posts 61
Added by Isaac Ashdown about 2 years ago

FYI, I would also like to request this feature - especially as skia seems to be crashing on my archos 101...

Zhe Wang RE: How to use custom font(ttf)?
Posts 1642
Location Amoy, China
Added by Zhe Wang about 2 years ago

@Isaac Ashdown
It hears so bad. skia crashes. AFAIK, both GUI system & webkit on android use either skia or opengles for rendering.
I saw your post in another thread, so odd.

Enjoy Coding, Enjoy Life.

Isaac Ashdown RE: How to use custom font(ttf)?
Posts 61
Added by Isaac Ashdown about 2 years ago

Sorry to be so vague - I was referring to the discussion we've been having in this thread:

http://www.cocos2d-x.org/boards/10/topics/1269

Isaac Ashdown RE: How to use custom font(ttf)?
Posts 61
Added by Isaac Ashdown almost 2 years ago

So, is there any chance of getting a schedule on this? Would like to start localisation but its pretty difficult with bitmap fonts...

Zhe Wang RE: How to use custom font(ttf)?
Posts 1642
Location Amoy, China
Added by Zhe Wang almost 2 years ago

@Isaac Ashdown
After evaluating freetype library, we are clear that it cannot replace FontLabel directly. FreeType is too low-level for our usage.
We had to find new ways to render custom fonts. Do you have any suggestions?

Enjoy Coding, Enjoy Life.

Sergio Abraham Martinez Rodriguez RE: How to use custom font(ttf)?
Posts 19
Added by Sergio Abraham Martinez Rodriguez almost 2 years ago

Walzer, I am having a translation done to chinese for Mashemup, i would like to keep the current look of the game, so i guess i need to get the bitmap from the ttf.

Did freetype give you too much trouble to compile? :D

Minggo Zhang RE: How to use custom font(ttf)?
Posts 1641
Added by Minggo Zhang almost 2 years ago

It is not compiling trouble, the freetype is too low level to use, such as the layout, alignment and so on.

Sergio Abraham Martinez Rodriguez RE: How to use custom font(ttf)?
Posts 19
Added by Sergio Abraham Martinez Rodriguez almost 2 years ago

Ic... well, i think i will use, i need to create the look of my custom fonts so i already integrated cximage to use some of the features and to be able to access the bitmaps directly and modify them and add some stroke and effects to them.

Sergio Abraham Martinez Rodriguez RE: How to use custom font(ttf)?
Posts 19
Added by Sergio Abraham Martinez Rodriguez almost 2 years ago

After playing with the freetype library, i understand now what you mean by too low level.

It works and i get the bits done since i only need to extract a few characters although it is really a lot of work to have it generic.
At least on my case i dont need much of it so i guess i will use it.

There are not many other options to this one, right?

Isaac Ashdown RE: How to use custom font(ttf)?
Posts 61
Added by Isaac Ashdown almost 2 years ago

What about using the platform SDK? It seems it would be worth it, no? To be honest, without custom fonts the CCLabelTTF is fairly useless, because its pretty ugly :(

Seems at least on android it's easy enough to do, and then sending the data as just a raw bitmap to the NDK layer shouldn't be a problem. Guess it might be slow...but then if you want speed, you should use bitmap fonts anyway...

Zhe Wang RE: How to use custom font(ttf)?
Posts 1642
Location Amoy, China
Added by Zhe Wang almost 2 years ago

I agree with you, Isaac. Since we switch from skia to sdk to draw texts at 0.8.5, using sdk to support custom ttf seems feasible now.
Ming, what's your opinion?

Enjoy Coding, Enjoy Life.

Minggo Zhang RE: How to use custom font(ttf)?
Posts 1641
Added by Minggo Zhang almost 2 years ago

I will have a test.

Zhe Wang RE: How to use custom font(ttf)?
Posts 1642
Location Amoy, China
Added by Zhe Wang almost 2 years ago

Update feature #347.

Enjoy Coding, Enjoy Life.

Isaac Ashdown RE: How to use custom font(ttf)?
Posts 61
Added by Isaac Ashdown almost 2 years ago

So! I noticed this feature was closed today, so i thought I'd grab the git edge version and take a peek.

It's working very nicely on Android, which is fantastic! Thank you so much for implementing this!

However, it doesn't appear to have made any changes on the win32 version. I notice that CCImage_win32 has seen some changes, and I've stepped through the code there and taken a look. It appears to be loading the font OK, as far as I can tell, but the rendered text is the same as before. It's not a huge deal, as android is my target platform and all, I just do most of the development on win32...

Also, I was wondering - is it best practice to include the '.ttf' extension in the font name, or to leave it out?

Thanks,
Isaac

Zhe Wang RE: How to use custom font(ttf)?
Posts 1642
Location Amoy, China
Added by Zhe Wang almost 2 years ago

OK, I reopen issue #347 for win32 port.
Maybe you should leave .ttf extension as it is.

Enjoy Coding, Enjoy Life.

Minggo Zhang RE: How to use custom font(ttf)?
Posts 1641
Added by Minggo Zhang almost 2 years ago

If remove '.ttf' extension, it will be used as "xxx/yyy". I think it is not so good. You may said that, in iOS, we just use "yyy" as the font name. But as you see, the ttf files are copied into the root directory of the app. If the android use like it, the ttf files should put into a directory with specified name, fonts as example. I think it is not a good idea.

ShaoWei Li RE: How to use custom font(ttf)?
Posts 1
Added by ShaoWei Li almost 2 years ago

to Isaac Ashdown:

sorry! because fonttest's font has been installed in my computer,so i can renderer fine.

I has found the reason! I will fix it.

Thank you for your reminds!

Milda Genius RE: How to use custom font(ttf)?
Posts 105
Added by Milda Genius almost 2 years ago

to Isaac Ashdown:

I downloaded today (12.08.2011) edge version (cocos2d-cocos2d-x-cocos2d-1.0.0-x-0.9.0-185-g81ba514.zip).

Win version works great with your font, but Android version still has default font.

Can you please test today version, if works? Its really odd that version 7days older works and newest not.

Thanks.

Isaac Ashdown RE: How to use custom font(ttf)?
Posts 61
Added by Isaac Ashdown almost 2 years ago

I got the edge version yesterday and everythign was working fine. The difference is, though, that the Win32 version requires you to specify the actual font name, whereas the android version has you specify the .ttf file.

Milda Genius RE: How to use custom font(ttf)?
Posts 105
Added by Milda Genius almost 2 years ago

I use it in this way:
pRet->mLabel = CCLabelTTF::labelWithString(text.c_str(), buttonSize, CCTextAlignmentCenter, "NanumMyeongjo.ttf", 50);

This work on Win but not on Android. I think, that I specify NanumMyeongjo.ttf as file name. I checked, that ttf file is in assets
directory in apk.

Is this right way on Android?

Zhe Wang RE: How to use custom font(ttf)?
Posts 1642
Location Amoy, China
Added by Zhe Wang almost 2 years ago

@Issaac Ashdown
Thanks for your feedback. I reopen feature #347 now, we must keep the consistency on different platforms.

@Milda Genius
The key code is in YourGame/android/src/org/cocos2dx/lib/Cocos2dxBitmap.java

private static Paint newPaint(String fontName, int fontSize, int alignment)
{
    // ...

    /*
    * Set type face for paint, now it support .ttf file.
    */
    if (fontName.endsWith(".ttf")){
        // trace here
    }
}

Please trace into here, and make sure the ttf type face is created successfully.

Enjoy Coding, Enjoy Life.

Milda Genius RE: How to use custom font(ttf)?
Posts 105
Added by Milda Genius almost 2 years ago

@Walzer Wang
I found my problem. I didnt update *.java files in my project from cocos2d-x edge version :(.

So after updated, I can see custom TTF font in Android build. Great!

In this time both version Win and Android works in the same way (TTF font is identify by full file name).
So I think we can close this issue.

@Issaac Ashdown
Can you please confirm this?

Zhe Wang RE: How to use custom font(ttf)?
Posts 1642
Location Amoy, China
Added by Zhe Wang almost 2 years ago

Hi, all,
I just checked the edge version on win32, ios & android, the Font Test works well with custom TTF.
So I closed feature #347.

Enjoy Coding, Enjoy Life.


1 2 Next » (1-25/27)