How to add font to be used by my app ?

Hi all,

is it possible to load certain font file along with my application in android. if so , please help me to know the steps to do so.

thanks

Abdul

Hi Abdul,

Please see this important guide:

http://www.coronalabs.com/blog/2013/01/16/faq-wednesday-custom-fonts/

Hi Brent,

thanks for your reply. i tried that but it did not work very well for me. When adding the following code and include the font “comics.ttf” in the project folder, I got small font even it is 50… is this the right way … do you mean resource

[lua]

local font =“comics”

CustFont = display.newText( “DroidSerif”, 40, 20,font, 50 )

[/lua]

regards

Abdul

If you put comics.ttf in your folder with your main.lua, then your code should work fine on an Android device.  However, you have to install the font in Windows and OS-X/Mac and restart Corona SDK if you want the simulator to use the font.  If you’re building for iOS,  you have to add something to your build.settings before iOS will use it.

Rob

Abdul,

One more thing on top of what Rob just said.  You can sometimes get into trouble with fonts if the file name and the internal name for the font differ.  

Sometimes, on devices, you’ll have the font in the right place and have made the proper changes (iOS requires changes to build.settings, whereas with Android you simply drop the font in the root folder of the game) to load the font, but Corona sees it as having a different name than the one given by the filename.  This can be very frustrating.

However, there is a solution.  

  1. Grab my ‘Font Dumper’ utility (just a $1) here: https://sellfy.com/p/1TKC/ 
  2. Drop your fonts in the root folder of the app. 
  3. Build the app.
  4. Install it on your Android device.
  5. Run the app.
  6. Find  your font in the list.
  7. In your game, use that exact spelling of the font.
  8. Problem Solved!

https://www.youtube.com/watch?v=qVaakYO-b6Y

PS - The core of my code is this little snippet:

local sysFonts = native.getFontNames() for k,v in pairs( sysFonts ) do -- Do something with the list: print(k,v) end

My tool simply adds bells and whistles, like making an IFC and listing all the fonts as well as showing them in action. 

You can totally do this on your own if you have the time.

Thanks Rob , after installing the font in my machine and restart corona sdk, it worked… 

roaminggamer,

 

i am not sure if i get your point, do you mean if the device has already that font then it will cause an issue ? also your link for the tool is not working,

thx

Abdul

Abdul,

  1. Fixed link.  Thanks.

  2. No, I mean sometimes the font gets loaded, but the name does not match the file name as you would expect it to.  Thus you have trouble getting Corona to use it.  Corona knows about the font, but you’ve (in this example) assumed the name is the same as the filename prefix when it isn’t.

A common case of this I’ve seen is dashed ‘-’ names.  The filename has no dashes, but the internal font name does.

Hi Abdul,

Please see this important guide:

http://www.coronalabs.com/blog/2013/01/16/faq-wednesday-custom-fonts/

Hi Brent,

thanks for your reply. i tried that but it did not work very well for me. When adding the following code and include the font “comics.ttf” in the project folder, I got small font even it is 50… is this the right way … do you mean resource

[lua]

local font =“comics”

CustFont = display.newText( “DroidSerif”, 40, 20,font, 50 )

[/lua]

regards

Abdul

If you put comics.ttf in your folder with your main.lua, then your code should work fine on an Android device.  However, you have to install the font in Windows and OS-X/Mac and restart Corona SDK if you want the simulator to use the font.  If you’re building for iOS,  you have to add something to your build.settings before iOS will use it.

Rob

Abdul,

One more thing on top of what Rob just said.  You can sometimes get into trouble with fonts if the file name and the internal name for the font differ.  

Sometimes, on devices, you’ll have the font in the right place and have made the proper changes (iOS requires changes to build.settings, whereas with Android you simply drop the font in the root folder of the game) to load the font, but Corona sees it as having a different name than the one given by the filename.  This can be very frustrating.

However, there is a solution.  

  1. Grab my ‘Font Dumper’ utility (just a $1) here: https://sellfy.com/p/1TKC/ 
  2. Drop your fonts in the root folder of the app. 
  3. Build the app.
  4. Install it on your Android device.
  5. Run the app.
  6. Find  your font in the list.
  7. In your game, use that exact spelling of the font.
  8. Problem Solved!

https://www.youtube.com/watch?v=qVaakYO-b6Y

PS - The core of my code is this little snippet:

local sysFonts = native.getFontNames() for k,v in pairs( sysFonts ) do -- Do something with the list: print(k,v) end

My tool simply adds bells and whistles, like making an IFC and listing all the fonts as well as showing them in action. 

You can totally do this on your own if you have the time.

Thanks Rob , after installing the font in my machine and restart corona sdk, it worked… 

roaminggamer,

 

i am not sure if i get your point, do you mean if the device has already that font then it will cause an issue ? also your link for the tool is not working,

thx

Abdul

Abdul,

  1. Fixed link.  Thanks.

  2. No, I mean sometimes the font gets loaded, but the name does not match the file name as you would expect it to.  Thus you have trouble getting Corona to use it.  Corona knows about the font, but you’ve (in this example) assumed the name is the same as the filename prefix when it isn’t.

A common case of this I’ve seen is dashed ‘-’ names.  The filename has no dashes, but the internal font name does.