Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

How to add font to be used by my app ?
Started by alzaabi98 Aug 01 2014 09:08 AM

6 replies to this topic
android font
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

alzaabi98

[GLOBAL: userInfoPane.html]
alzaabi98
  • Starter
  • PipPipPipPipPipPip
  • 280 posts
  • Jedi

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



[TOPIC: post.html]
#2

Brent Sorrentino

[GLOBAL: userInfoPane.html]
Brent Sorrentino
  • Corona Staff
  • 4,465 posts
  • Jedi


[TOPIC: post.html]
#3

alzaabi98

[GLOBAL: userInfoPane.html]
alzaabi98
  • Starter
  • PipPipPipPipPipPip
  • 280 posts
  • Jedi

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

 

local font ="comics"
CustFont = display.newText( "DroidSerif", 40, 20,font, 50 )
 
 
regards
Abdul


[TOPIC: post.html]
#4

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Corona Staff
  • 9,969 posts
  • Jedi

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



[TOPIC: post.html]
#5

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Enterprise
  • PipPipPipPipPipPip
  • 666 posts
  • Jedi

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!

 

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.


Edited by roaminggamer, 02 August 2014 - 12:47 PM.


[TOPIC: post.html]
#6

alzaabi98

[GLOBAL: userInfoPane.html]
alzaabi98
  • Starter
  • PipPipPipPipPipPip
  • 280 posts
  • Jedi

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



[TOPIC: post.html]
#7

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Enterprise
  • PipPipPipPipPipPip
  • 666 posts
  • Jedi

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.




[topic_controls]
[/topic_controls]



Also tagged with one or more of these keywords: android, font