Custom fonts in Android is driving me nuts!

Dev Platform: Windows
Target OS: Android
Build: 696

I have a font called nobile.ttf. It is in the project folder and has been installed in the Windows font folder.

According to the documentation, the full filename is necessary for Android:

display.newText("HELLO WORLD",0,0,"nobile.ttf",28)  

However, when I run it in the simulator even with View As set to an Android device, I get a “could not load font” warning. BUT, if I replace this line with:

display.newText("HELLO WORLD",0,0,"Nobile",28)  

…it works fine in the simulator for Android devices, even though, according to the docs, it would not load the font on a phone.

Am I right in thinking that the simulator does not work correctly in this way for Android? In other words, if I were to build for an Android phone, I’d need to put the “ttf” on the end even though it throws an error in the simulator? So, every time I want to test on a device, I have to change the font names?
[import]uid: 95579 topic_id: 18402 reply_id: 318402[/import]

I haven’t actually used custom fonts on Android yet so can’t help you there, but can tell you that yes the Simulator ( even viewed as Android ) will not act as if an Android device. If you call the system.getInfo() function you can see that you are running on OSX/Windows not Android.

As for having to swap out the name from simulator to device, you could just have a variable that is changed depending on what you are running on, something like this:

[code]

local fontName = system.getInfo( “platformName” ) == “Android” and “nobile.ttf” or “Nobile”

– then just display your text later on like this
display.newText( “HELLO WORLD”, 0 , 0, fontName, 28 )

[/code] [import]uid: 5833 topic_id: 18402 reply_id: 70563[/import]

I’m very confused with custom fonts…

The font “Harrowprint” works ok for me in simulator and in Android (Samsung Galaxy Tab 10.1), but I want to use other font “LTZapfino One” and it doesn’t work in Android but OK in simulator with the same call to display.newText().

I use the fontname (not the filename).

Regards,

J.O.C.F.
Inkubica Labs [import]uid: 70922 topic_id: 18402 reply_id: 70570[/import]

I am also fighting custom fonts. But this is simply because some fonts seem to be corrupted. Tried two different custom fonts, one was working, one not (working on windows, word, but not in simulator and on the device). [import]uid: 90610 topic_id: 18402 reply_id: 70572[/import]

Thanks Graham, that explains it. Not much of a simulator if it doesn’t simulate the target OS!! What a waste of a morning.

[import]uid: 95579 topic_id: 18402 reply_id: 70576[/import]