|
Viewing 1 to (7 Total) Default font and Chinese font |
Total Posts: 35
Joined: October 10, 2011
|
Hi folks,
I've just did some tests on displaying Chinese characters on Android devices but without luck.
My test project is MineHx (multi-density demo).
The first approach is just replacing the assets font with a Chinese truetype font file, however when I was testing the package on device I got following error message in console:
E/GameActivity(19963): java.io.IOException
I/GetFontFile1(19963): Could not load font fonts_bradbunr_ttf.
E/GameActivity(19963): java.io.IOException
I/GetFontFile1(19963): Could not load font fonts_bradbunr_ttf.
Since the sample works well with the original English font, so is it because NME does not load TTF files contains Chinese? or because the file is too large (>3M)?
My second test is trying to use the default Chinese font on device, but this time I got another error message: "E/GameActivity(18407): java.io.FileNotFoundException: Times
E/GameActivity(18407): java.io.FileNotFoundException: /system/fonts/DroidSerif-Regular.ttf", and even ASCII characters didn't show.
I took a look at my ROM's "system/fonts" folder and found that the above-mentioned file does absent, it seems NME made some assumption that is not always true (e.g. The rom is customized). And I think DroidSerif-Regular.ttf should not be the default font for my device since it does not contain Chinese charset. On my device it is "system/fonts/DroidSansFallback.ttf".
Is it possible for NME to auto-detect the device's default font?
Tags:
Posted on November 01, 2011 at 1:26 AM
|
|
|
Total Posts: 2140
Joined: August 25, 2011
|
Re: Default font and Chinese font
What code are you using to load the font? Is it being embedded with your project?
If the file is embedded as "assets/MyFontFile.ttf", you should use:
var font = Assets.getFont ("assets/MyFontFile.ttf"); var format = new TextFormat (font.fontName);
If you would prefer to use a generic font, you can try "_sans", "_serif" or "_typewriter"
Posted on November 01, 2011 at 10:21 PM
|
Total Posts: 35
Joined: October 10, 2011
|
Re: Default font and Chinese font
Thanks for your reply!
Here's the code (is it your code?):
HowToPlayTitle = new TextField ();
HowToPlayTitle.defaultTextFormat = new TextFormat (Assets.getFont ("fonts/BradBunR.ttf").fontName, 66 * Utils.screenDensity, 0xB1D22D);
HowToPlayTitle.embedFonts = true;
This code works well with original english-only font.
The first thing I tried is just simply replacing "fonts/BradBunR.ttf" with another ttf file that contains Chinese charset, without any code changes, that still works on Flash but in Android it caused following error output:
E/GameActivity( 337): java.io.IOException
I/GetFontFile1( 337): Could not load font fonts_bradbunr_ttf.
Posted on November 01, 2011 at 10:46 PM
|
Total Posts: 2140
Joined: August 25, 2011
|
Re: Default font and Chinese font
So you deleted ../Assets/fonts/BradBunR.ttf and put in your own font, and renamed it?
You can also try putting your own file in the same directory, and using its name instead, to see if that works.
Posted on November 01, 2011 at 11:00 PM
|
Total Posts: 35
Joined: October 10, 2011
|
Re: Default font and Chinese font
Yes you're right, that's my approach.
Just tried again at your advise, but got same result. This does not work for both Android emulator and real device.
Console output:
E/GameActivity( 609): java.io.IOException
I/GetFontFile1( 609): Could not load font fonts_fangsong_ttf.
Posted on November 01, 2011 at 11:28 PM
|
Total Posts: 2140
Joined: August 25, 2011
|
Re: Default font and Chinese font
Could you look in your build directory, under ../android/bin/assets, and see if there is a file called "fonts_fangsong_ttf"?
Posted on November 01, 2011 at 11:54 PM
|
Total Posts: 35
Joined: October 10, 2011
|
Re: Default font and Chinese font
Yes the file is there, and I also took a look into the output apk file (with 7-zip) and confirmed that the file is included.
Posted on November 02, 2011 at 6:30 AM
|