Forums » C++ Framework » How to use custom font(ttf)? »
| kan don | How to use custom font(ttf)? | ||||
|---|---|---|---|---|---|
|
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.. It work fine at cocos2d-iPhone. Is there anything I missed? NanumMyeongjo.ttf (3.6 MB) |
||||
| Zhe Wang | RE: How to use custom font(ttf)? | ||||
|
Added by Zhe Wang about 2 years ago
cocos2d-iphone uses FontLabel as third-party library to parse the custom ttf file. Keep it simple and stupid. |
||||
| Isaac Ashdown | RE: How to use custom font(ttf)? | ||||
|
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)? | ||||
|
Added by Zhe Wang about 2 years ago
@Isaac Ashdown Keep it simple and stupid. |
||||
| Isaac Ashdown | RE: How to use custom font(ttf)? | ||||
|
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: |
||||
| Isaac Ashdown | RE: How to use custom font(ttf)? | ||||
|
Added by Isaac Ashdown about 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)? | ||||
|
Added by Zhe Wang about 2 years ago
@Isaac Ashdown Keep it simple and stupid. |
||||
| Sergio Abraham Martinez Rodriguez | RE: How to use custom font(ttf)? | ||||
|
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? |
||||
| Minggo Zhang | RE: How to use custom font(ttf)? | ||||
|
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)? | ||||
|
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)? | ||||
|
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. There are not many other options to this one, right? |
||||
| Isaac Ashdown | RE: How to use custom font(ttf)? | ||||
|
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)? | ||||
|
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. Keep it simple and stupid. |
||||
| Minggo Zhang | RE: How to use custom font(ttf)? | ||||
|
Added by Minggo Zhang almost 2 years ago
I will have a test. |
||||
| Zhe Wang | RE: How to use custom font(ttf)? | ||||
|
Added by Zhe Wang almost 2 years ago
Update feature #347. Keep it simple and stupid. |
||||
| Isaac Ashdown | RE: How to use custom font(ttf)? | ||||
|
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, |
||||
| Zhe Wang | RE: How to use custom font(ttf)? | ||||
|
Added by Zhe Wang almost 2 years ago
OK, I reopen issue #347 for win32 port. Keep it simple and stupid. |
||||
| Minggo Zhang | RE: How to use custom font(ttf)? | ||||
|
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)? | ||||
|
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)? | ||||
|
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)? | ||||
|
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)? | ||||
|
Added by Milda Genius almost 2 years ago
I use it in this way: 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 Is this right way on Android? |
||||
| Zhe Wang | RE: How to use custom font(ttf)? | ||||
|
Added by Zhe Wang almost 2 years ago
@Issaac Ashdown @Milda Genius
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. Keep it simple and stupid. |
||||
| Milda Genius | RE: How to use custom font(ttf)? | ||||
|
Added by Milda Genius almost 2 years ago
@Walzer Wang 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). @Issaac Ashdown |
||||
| Zhe Wang | RE: How to use custom font(ttf)? | ||||
|
Added by Zhe Wang almost 2 years ago
Hi, all, Keep it simple and stupid. |

