Confused about font names on Android... Can you please help?

Hi, 

Another aha moment for me hopefully.

Android-izing your app has a great code sample to provide font choices by platform to your app at runtime. This sample assigns fonts on Android with the following call : 

if ( device.isAndroid ) then font.normal = “Droid Sans” end

Another excellent document from CL, Custom Fonts FAQ at http://www.coronalabs.com/blog/2013/01/16/faq-wednesday-custom-fonts/

say : In Android the font name is the file name (minus the file extension).

CustFont = display.newText( “PTSerif-Regular”, 40, 20, “PTF55F”, 24 )

PTF55F being the font name that should be used if one wants to see “PTSerif-Regular” font used. 

So the second document seems to contradict the first document and the sample provided there. 

Can someone kindly set this right? Will the following work? 

CustFont = display.newText( “my little text shown in Droid Sans”, 40, 20, “Droid Sans”, 24 )

And if it will not, due to the reason outlined in the second document (FAQ) then how do I go about finding the font file names on an Android device?

The native.getFontNames() call seems to be returning the long name and not the file name. 

Thank you very much for your help. Regards,

Kerem

Bumping this one up in hope of some input. Since posting this I have also come to discover some other peculiarities… Fonts are driving me crazy… 

native.systemFontBold on a Samsung Galaxy Captivate defaults to a non-bold font. No idea why. According to font list on the device there are bold fonts but I’m not sure why the native.systemFontBold is not equating to one of them.

When I use the approach outlined in the Androidizing your app tutorial as in … 

local font = {}
font.normal = “Helvetica”
font.bold = “Helvetica Bold”
font.italic = “Helvetica Oblique”

and use font.bold on an iPhone 4 the text appears blank! Simulator is ok in iPhone 4 mode… native.systemFontBold works fine on the iPhone 4 and I do actually see results. So I guess Helvetica Bold does not exist on iPhone 4.

You probably should get the free iOS app called “Fonts” (https://itunes.apple.com/us/app/fonts/id285217489?mt=8).  This will show you all the fonts installed on your device.  The name for Helvetica bold according to this app is actually “Helvetica-Bold”.

display.newText() uses the font’s internal name to identify the font, so using “Droid Sans” would be right for installed fonts.  On Windows and on the Mac, fonts need to be installed in the device for Corona to use them.  The simulator does not use build.settings  like iOS does. 

Now on Android (and perhaps iOS too) with custom fonts that you want to include with your app (not installed on the device), most people feel (and there is plenty of anecdotal evidence that this is the case) that the actual file name has to match the internal font name.  I’ve found it best to rename the file name to the internal font name where possible since it’s easier to change the the file name.  But sometimes you just can’t make a valid file name from the internal font name, so in that case you need to edit the font and change the internal name to match the file name.

Hi Rob, 

Thanks for your kind response. I got Fonts and that will be great help. 

So in the “Android-izing your app” blog entry your code reads : 

local font = {}
font.normal = “Helvetica”
font.bold = “Helvetica Bold”
font.italic = “Helvetica Oblique”

Based on what you mention above then it should read font.bold = “Helvetica-Bold”. Something to correct so other newbies like me don’t get stuck and bug you later on… 

Great suggestion on renaming custom fonts so actual name  and system name are both the same. It also sounds like a good idea to choose one font that works well on both platforms and supply it along with the app in order to ensure at all times things look the way you like. I’ll look into this. 

Update

font.bold = “DroidSans-Bold” now work well on my Samsung Galaxy Captivate. Not sure what I did wrong the first time around. So I’m all set to use Helvetica on IOS and DroidSans on Android for the time being but will continue to look for one custom font which I can supply on both platforms to ensure consistency. Thanks for all your help.

Thanks for finding that.  I’ve updated the blog post with accurate font names.  For iOS, it’s Helvetica-Bold and Helvetica-Oblique.   For Android it’s DroidSans and DroidSans-Bold.  Here is a little app I call “GetInfo” that I install on my devices to test:

local v = {} v[1] = display.newText(system.getInfo("name"),0,0, "Helvetica", 18) v[2] = display.newText(system.getInfo("model"),0,0, "Helvetica", 18) v[3] = display.newText(system.getInfo("platformName"),0,0, "Helvetica", 18) v[4] = display.newText(system.getInfo("platformVersion"),0,0, "Helvetica", 18) v[5] = display.newText(system.getInfo("build"),0,0, "Helvetica", 18) v[6] = display.newText(system.getPreference("ui", "language"),0,0, "Helvetica", 18) for i = 1, #v do     v[i]:setReferencePoint(display.TopLeftReferencePoint)     v[i].y = i \* 20     v[i].x = 10 end local fonts = native.getFontNames() local fontStr = {} local i = 1 local col = 1 local row = 1 for k, v in pairs(fonts) do --    print(k,v)     fontStr[i] = display.newText(v,0,0,v,14)     fontStr[i]:setReferencePoint(display.TopLeftReferencePoint)     fontStr[i].y = row \* 18 + 128     fontStr[i].x = 10 + (col - 1) \* 290     col = col + 1     if col \> 2 then         col = 1         row = row + 1     end     i = i + 1 end

Be aware that it will take a long time to start up on your local computer because if you’re like me there are hundreds of installed fonts. 

Thanks for sharing that code. I also did something similar with device display specifications so I will merge your code into that and post back on Code Exchange at some point. It is very useful to put something like this on your TestFlight and let your new testers run on their device so you can see ahead of time what you will be facing… I also have a small email function so the tester can send me all the details. Works great for display specs and now I will add the fonts too thanks to you. 

Bumping this one up in hope of some input. Since posting this I have also come to discover some other peculiarities… Fonts are driving me crazy… 

native.systemFontBold on a Samsung Galaxy Captivate defaults to a non-bold font. No idea why. According to font list on the device there are bold fonts but I’m not sure why the native.systemFontBold is not equating to one of them.

When I use the approach outlined in the Androidizing your app tutorial as in … 

local font = {}
font.normal = “Helvetica”
font.bold = “Helvetica Bold”
font.italic = “Helvetica Oblique”

and use font.bold on an iPhone 4 the text appears blank! Simulator is ok in iPhone 4 mode… native.systemFontBold works fine on the iPhone 4 and I do actually see results. So I guess Helvetica Bold does not exist on iPhone 4.

You probably should get the free iOS app called “Fonts” (https://itunes.apple.com/us/app/fonts/id285217489?mt=8).  This will show you all the fonts installed on your device.  The name for Helvetica bold according to this app is actually “Helvetica-Bold”.

display.newText() uses the font’s internal name to identify the font, so using “Droid Sans” would be right for installed fonts.  On Windows and on the Mac, fonts need to be installed in the device for Corona to use them.  The simulator does not use build.settings  like iOS does. 

Now on Android (and perhaps iOS too) with custom fonts that you want to include with your app (not installed on the device), most people feel (and there is plenty of anecdotal evidence that this is the case) that the actual file name has to match the internal font name.  I’ve found it best to rename the file name to the internal font name where possible since it’s easier to change the the file name.  But sometimes you just can’t make a valid file name from the internal font name, so in that case you need to edit the font and change the internal name to match the file name.

Hi Rob, 

Thanks for your kind response. I got Fonts and that will be great help. 

So in the “Android-izing your app” blog entry your code reads : 

local font = {}
font.normal = “Helvetica”
font.bold = “Helvetica Bold”
font.italic = “Helvetica Oblique”

Based on what you mention above then it should read font.bold = “Helvetica-Bold”. Something to correct so other newbies like me don’t get stuck and bug you later on… 

Great suggestion on renaming custom fonts so actual name  and system name are both the same. It also sounds like a good idea to choose one font that works well on both platforms and supply it along with the app in order to ensure at all times things look the way you like. I’ll look into this. 

Update

font.bold = “DroidSans-Bold” now work well on my Samsung Galaxy Captivate. Not sure what I did wrong the first time around. So I’m all set to use Helvetica on IOS and DroidSans on Android for the time being but will continue to look for one custom font which I can supply on both platforms to ensure consistency. Thanks for all your help.

Thanks for finding that.  I’ve updated the blog post with accurate font names.  For iOS, it’s Helvetica-Bold and Helvetica-Oblique.   For Android it’s DroidSans and DroidSans-Bold.  Here is a little app I call “GetInfo” that I install on my devices to test:

local v = {} v[1] = display.newText(system.getInfo("name"),0,0, "Helvetica", 18) v[2] = display.newText(system.getInfo("model"),0,0, "Helvetica", 18) v[3] = display.newText(system.getInfo("platformName"),0,0, "Helvetica", 18) v[4] = display.newText(system.getInfo("platformVersion"),0,0, "Helvetica", 18) v[5] = display.newText(system.getInfo("build"),0,0, "Helvetica", 18) v[6] = display.newText(system.getPreference("ui", "language"),0,0, "Helvetica", 18) for i = 1, #v do     v[i]:setReferencePoint(display.TopLeftReferencePoint)     v[i].y = i \* 20     v[i].x = 10 end local fonts = native.getFontNames() local fontStr = {} local i = 1 local col = 1 local row = 1 for k, v in pairs(fonts) do --    print(k,v)     fontStr[i] = display.newText(v,0,0,v,14)     fontStr[i]:setReferencePoint(display.TopLeftReferencePoint)     fontStr[i].y = row \* 18 + 128     fontStr[i].x = 10 + (col - 1) \* 290     col = col + 1     if col \> 2 then         col = 1         row = row + 1     end     i = i + 1 end

Be aware that it will take a long time to start up on your local computer because if you’re like me there are hundreds of installed fonts. 

Thanks for sharing that code. I also did something similar with device display specifications so I will merge your code into that and post back on Code Exchange at some point. It is very useful to put something like this on your TestFlight and let your new testers run on their device so you can see ahead of time what you will be facing… I also have a small email function so the tester can send me all the details. Works great for display specs and now I will add the fonts too thanks to you.