Android Custom Font Drama

So its really fun trying to build apps when you don’t have a dozen different android devices to test on. Even more fun is when you have none!

Anyway, from what I learned in researching fonts is that in iOS you say “myfont” and in Android you say “myfont.ttf”. Of course you can’t really test it in the Simulator since it behaves like iOS.

So I put my .apk out tonight to find out if the fonts were working (along with other things to test) and I have two reports. One person says they are seeing the custom font. Another tester said they saw what looks like Droid Sans, the native.defaultFont on Android (I think)

Is there some magic font formula for Android? Have you seen fonts work on one device and not another?
[import]uid: 19626 topic_id: 23282 reply_id: 323282[/import]

Actually almost everyone is reporting seeing Droid Sans instead of my custom font. Guess I’m going to have to spring for an Android device sooner than later.

[import]uid: 19626 topic_id: 23282 reply_id: 93168[/import]

@Rob ,sure is great to have an Android device to test things on, but for me was a pleasure let you a hand after so many times you doing the same for me and many others here at our CoronaSDK Community.

Thanks for that and feel at home to ask me about Android tests. :slight_smile:
Cheers,
Rodrigo. [import]uid: 89165 topic_id: 23282 reply_id: 93188[/import]

Best way to be sure it works on Android is to get Font Forge and edit the font information so that “font family”, “font name” and the actual file name all match. That is, if you have a font named “CoolFont” make sure the filename is CoolFont.ttf, then edit the file with font forge and change the fields Font Family and Font Name to CoolFont as well. Guaranteed to work* :slight_smile:

PS: Font Forge looks hideous but it’s actually a very good program.

*unless I forgot something. [import]uid: 61899 topic_id: 23282 reply_id: 93287[/import]

Have you tried it without the .ttf on the end? iOS fonts need you to use the actual font name, whereas android just needs the filename.

In one of my apps i was struggling with custom fonts for android, all i had to do was take the .ttf off and it all started working fine.

The font i used was LucidaConsole.ttf, so i just put that in the main directory with all the lua files and just called the font using “LucidaConsole”. [import]uid: 69826 topic_id: 23282 reply_id: 93290[/import]

But does that mean that on iOS I have to reference the file as “font.ttf” instead of just “font” if I’m changing the names?

[import]uid: 19626 topic_id: 23282 reply_id: 93291[/import]

No you shouldn’t put the .ttf on the end on iOS. That will break it i think, or it will just display the default Helvetica instead.

For iOS i did this in the build.settings.

UIAppFonts =   
{   
 "LucidaConsole.ttf",   
},  

Then i used that font with… “Lucida Console” in my display.newTexts. Double clicking the font your using on a Mac will open it in font book and you can see the fonts actual name, if you don’t reference its full name it won’t work at all.

For Android i didn’t have to edit the buid.settings at all. All i did was have my “LucidaConsole.ttf” file in the main directory, and i could use it with “LucidaConsole” in the display.newTexts.
Does that make sense? I’ve never been all that great at explaining things lol.
If you want another android device for testing, you could always send the .apk my way and i can see if it works on my android. [import]uid: 69826 topic_id: 23282 reply_id: 93293[/import]

In normal cases, if you do put the extension on it will break it.

But in the example of using fontforge to change the internal name of the fonts to match the filename, then the name that iOS would need to use would have to match that string which if I follow the fontforge advice about will now include the .ttf…

I’m going to try it without the .ttf on Android and see if that fixes it.

[import]uid: 19626 topic_id: 23282 reply_id: 93300[/import]

Could you not just detect which platform the app is running on and then just substitute in a different font name? [import]uid: 69826 topic_id: 23282 reply_id: 93305[/import]

That’s what I was trying to do and it’s not working on Android. [import]uid: 19626 topic_id: 23282 reply_id: 93309[/import]

Any resolution to this? Just delivered alpha builds to my client, which look great on his iOS devices, not so on Android. Sounds like a font issue from his description.

I’m not sure what is meant by “trying it without .ttf” - you mean renaming the font file without a suffix? [import]uid: 58455 topic_id: 23282 reply_id: 109058[/import]

Custom fonts have always been a challenge. Android is even more so, and the Kindle Fire seems to face the greatest challenges, but at the end of the day to work on all platforms.

  1. Use **VALID** True-Type fonts. If the font has problems, it’s likely the device won’t display them.

  2. Make sure the internal font name matches the file name exactly: Case sensitive. The file system on the simulator is not case sensitive in most cases, but it is on the devices.

  3. You should not need to put the .ttf on the display.newText() listing for the font: display.newText(“some text”, 0, 0, “MyCustomFontName”, 32) should work on all devices.

  4. For device fonts, keep in mind that Android does not have a license for “Helvetica” and several other Apple fonts where as a very similar font, Arial is on my iPhone and is a safer cross-platform font to use (if like me you can’t stand Droid Sans, the native.systemFont on Android)
    [import]uid: 19626 topic_id: 23282 reply_id: 109071[/import]