Custom Fonts for Android

I want to use a custom font for my Android application.

I've looked through the forums and some posts say that listing the custom font in the build.setting is not necessary. So, I used this code:

1
2
start = display.newText("Get Started",0,0,"Harrowprint.ttf", 26)
start:setTextColor(0,0,0)

Have you tested on your device, it doesn't work in the Simulator but it does work on the device =)

local text =display.newText( "HELLO", 10, 20, "Harrowprint", 26 )
text:setTextColor(00, 00, 0)

You have to use the font name not the font file name. Usually drop the ttf is enough, but on some fonts the file is different to the name. Just import the font into your OS and check its name in Word or something.

It's been a few days since I've posted to this topic; I know it's bad etiquette.

So, for anyone that comes across this post, custom fonts DO work with the simulator for Windows. You have to install the custom font to your machine and then you can view your custom font.

Now, if only Corona would let me update my app in the marketplace...

Font issues on Android

I still have not figured out how to use a custom font for Android although I have been successful with a custom iPhone font. Lots of reading on these forums don't seem to help.

I used the Android SDK "adb" utility to do a logcat and load the log directly from the Android device and there is a message that the font could not be loaded.
I suppose it could be a problem with the font file itself but it loads in an iPhone and on my Mac.

The log message:

1
  I/System.out( 3266): WARNING: Could not load font Brady Bunch Remastered. Using default.

Its annoying i know!

Get a font utility like fontforge and open the ttf file, and check or edit its name. It may be that android doesnt like the spaces. Also depending on how the font is stored it may need a -Regular or -Bold suffix etc.

For example I'm using Monofonto.ttf but my code looks like this:

Bonus.text2 = display.newText( "LITE", 0, 0, "Monofonto-Regular", 14*2 )

Does the font file reside in the root folder of the Android project when you do the build?

Yes, root folder.

Thanks.

When I find the answer I will post it here to maybe help others.

This mobile development stuff is like trying to reach into a bowl of Jello and pick it up by squeezing. I had similar "fun" with some Xcode / Objective-C development last year. It was not any easier trying to load this first Xcode project to Apple. It is good Google does not charge by the query. That project alone would have meant bankruptcy. Squeezing harder does not seem to help with this stuff or Jello. :-))

Corona is a "dream" compared to Xcode. Now all I need is to figure out how to improve my promotion so I can get some decent sales.

Yep in the end this was pretty easy.

I installed FontForge from the suggestion in this thread (using MacPorts) and renamed the font to a simple name with no spaces. I made the font name match the actual file name (minus the file extension). I changed all of the references in the LUA code to use this new simpler font name (without extension) and simply put the TTF file in the root of the project. Like magic it just worked. No build.settings changes were required.

I looked around for other font editors but most were not cheap. The downside is you must compile FontForge from source, although that did not turn out to be hard just a bit time (and disk space) consuming.

If you want to use FontForge here are some hints:

Use the ELEMENT command in FontForge and select FONT INFO. Modify the file names and save the file in the native SFD format if you want. FontForge cannot directly save to TTF even if that is what you load. Use the command FILE / GENERATE FONTS to create the TTF file.

Apparently the font file I started with has a few errors that FontForge warned about but I saved anyway and it worked. I might circle back later to see if I can fix them.

I had not used MacPorts before but because FontForge is now only distributed as source this made the install fairly easy. Installing MacPorts itself was fairly easy and quick. The number of dependencies for FontForge was VERY large on my machine. It took over an hour for MacPorts to download and install all of the parts but it went without incident and with a single INSTALL command for FontForge. I am using a MacBook with the lasted version of Snow Leopard. I think many of the dependencies were probably because I had never installed anything with MacPorts and the fact that FontForge requires X11. I am not a fan of X11 but it works pretty good in FontForge.

So I am now going to get a few more fonts to complete my Android app so I can substitute for a few that I routinely use in my iPhone apps.

I picked up a cool freeware font here based on a link in another font post on this forum:
http://www.dafont.com

I hope this helps somebody.

OK found an answer to my font problem on Android with Windows build
I was using a font file called ravie.ttf and was referencing the file OK but was using "Ravie" as the font name in the code as this is what the font is called however it wouldn't work. I changes to "ravie" and it now works....seems font names as a bit hit and miss

Anyway happy to have it no working :)

Hi, everybody. Thanks for the suggestions that have already appeared in this thread. With your help, I have managed to successfully loaded custom fonts in my Android app (though this took much more work than on an iOS build - like others on this thread, I eventually had to simplify my font's name within the TTF file to a single word with no special characters).

However, I cannot get native WebViews of local HTML files to display that same font, which is something I'm able to do in iOS by using the HTML tag <font face="myFont">. Has anybody had any luck using custom fonts within local HTML files on Android? If you can shed any light, I'd be most grateful.

Thanks,
Jason

I'm having trouble with the final font. For example I'm using the font, Digital Dream Fat for that analog look.

When I'm in fontforge, I go to font info, remove all the spaces from the font name and lowercase all uppercases.
Save the file as SFD -> digitaldreafat.sfd
then generate font to TTF -> digitaldreamfat.ttf
The new font loads up when installed and double clicked in Windows just fine. It even works as a valid font in Microsoft Word.
It even appears in the master list generated from native.getFontNames() on the bottom.

But when copied to the project folder; called in the script I receive:
Warning: could not load font digitaldreamfat. Using default font.

I would love to say my script is bad, but it's the same script that could get the original font to work on the Simulator. Am I saving it wrong in FontForge, or is this a Windows conversion error?

views:3495 update:2011/10/8 15:12:54
corona forums © 2003-2011