You can embed a custom font in your app. This feature’s been in for a little while, but wasn’t documented. So I thought it’d be worth bringing it to your attention.
[import]uid: 54 topic_id: 2289 reply_id: 302289[/import]
You can embed a custom font in your app. This feature’s been in for a little while, but wasn’t documented. So I thought it’d be worth bringing it to your attention.
[import]uid: 54 topic_id: 2289 reply_id: 302289[/import]
Please provide an example showing a complete build.settings file for Android that includes a custom font. Or point to a reference that explains all the elements of the build settings.
Here was my wild guess trying to adapt the iphone version shown in the ansca example for embedding font
settings =
{
androidPermissions =
{
“android.permission.INTERNET”
},
android =
{
plist =
{
UIAppFonts =
{
“VeraMono.ttf”
}
},
},
} [import]uid: 10016 topic_id: 2289 reply_id: 8156[/import]
You don’t need an entry on Android. I updated the docs to reflect that. [import]uid: 54 topic_id: 2289 reply_id: 8163[/import]
That explains why I was going through the docs yesterday, noticed it and thought… whoah I didn’t know you could do that! [import]uid: 7849 topic_id: 2289 reply_id: 8177[/import]
Can anyone verify that this works on an actual device? Following the instructions here I can see and use my custom font in the Corona Sim and the Xcode Sim, but when I build for an actual device the font is absent. (ie - buttons that use the font for text labels look correct on both sims, but on the iPhone itself the buttons are blank.)
[import]uid: 9422 topic_id: 2289 reply_id: 13044[/import]
THis works for me. In simulaator AND on my iPhone 3GS. Here is my build.settings file:
settings = {
iphone = {
plist = {
UIApplicationExitsOnSuspend = true,
UIAppFonts = {
“SFDigitalReadout-Heavy.ttf”
}
},
},
}
And in my project folder along with all source (*.lua), graphics, and sound files is:
SFDigitalReadout-Heavy.ttf [import]uid: 295 topic_id: 2289 reply_id: 13186[/import]
Yes I can also confirm it works. Though you’ll need iOS 3.2. It’s worth noting if you’re planning to support the original iphone (can’t install 3.2.), you’d be better off with bitmap text. [import]uid: 10835 topic_id: 2289 reply_id: 13189[/import]
Thanks for the confirmation, tokyodan and Ignaciolturra.
It turns out the font I was trying to use had the extention “.TTF” as opposed to “.ttf”, which is how I had it in my build.settings. I guess OSX (and the simulators) are smart enough to handle that, but iOS isn’t.
Also, Ignaciol, thanks for the heads up about the compatibility issue with original iPhone. I’m on the fence about supporting it since, currently, my game runs at about half speed on it vs. 3GS and 4. I wonder if there’s a way to detect which phone is being used and fallback to a system font if it’s an original iPhone. [import]uid: 9422 topic_id: 2289 reply_id: 13241[/import]
My custom font is now working on the devices, but there’s another problem. Text using the custom font is shifted up a few pixels. It looks particularly bad when using the font for button label text since the font creeps over the top edge of my button graphic.
I Googled around and it seems this is a problem for people trying to use custom fonts on iPhones after iOS 3, when Apple changed the UPM for fonts from 1000 to 2048. I don’t understand the problem, or what the solution might be, all I know is the font is aligned correctly in the Corona simulator and OSX, but is misaligned vertically on my iPhone. Anyone else notice their custom fonts misaligned on an actual device? Is this a bug for Ansca? [import]uid: 9422 topic_id: 2289 reply_id: 13478[/import]
is there something Im missing? I have done everything pretty much to the letter what was written here. Was the font supposed to be in a certain folder? [import]uid: 10051 topic_id: 2289 reply_id: 13615[/import]
Yes, you have to copy it to your project’s root folder as well. [import]uid: 10835 topic_id: 2289 reply_id: 14144[/import]
yes, did that as well as all the other directions to the letter
[import]uid: 10051 topic_id: 2289 reply_id: 14145[/import]
The only other thing I can think of is that you have the name of the font wrong. It’s not necessarily the name of the file, but how it shows in other programs. Try using the font in something else and see what it’s called (Also try different fonts to try and narrow down the issue). [import]uid: 10835 topic_id: 2289 reply_id: 14150[/import]
I used FONTBOOK in osx to find the font name…although I used the sample code on showing native fonts on the device, and my font wasnt in there…no matter what the name was exactly. even the harrowprint exmple font provided didnt show, and my ipad has the latest iOS ver.
[import]uid: 10051 topic_id: 2289 reply_id: 14153[/import]
Hi, following up here in case someone else has a similar problem.
Another thing to check in your build.settings file is that the UIAppFonts entry needs to be a list, even if it only has one entry. In other words, it should look like this:
UIAppFonts = {
“SFDigitalReadout-Heavy.ttf”
}
This will not work:
UIAppFonts = “SFDigitalReadout-Heavy.ttf”
[import]uid: 6787 topic_id: 2289 reply_id: 14434[/import]
Ok, so now the font finally shows up…thanks for the heads up on how to get it right in the build file, but it would appear that I am having the same issue as XenonBL where the text is fine on Corona Sim but on the device its shifted up. Is this a bug for ANSCA? I would hate to have to go through and change all this around when its just a bug to be fixed.
[import]uid: 10051 topic_id: 2289 reply_id: 15230[/import]
Dumb question: where can I find the build.settings file? Or do I create on in my project directory? [import]uid: 7472 topic_id: 2289 reply_id: 19126[/import]
@Nick: you create the build.settings file yourself in the root project directory.
[import]uid: 22457 topic_id: 2289 reply_id: 19567[/import]
dumber question, when I use a ttf font the font size is fixed, it doesn’t matter how big I make the font in display.newText, it will stay the same size. Why is it doing that? It IS the correct font, but the size is unchangable. [import]uid: 20703 topic_id: 2289 reply_id: 21103[/import]
Shaunathan, I had no trouble changing font size when using a custom font on a button. Want to paste in your code? Maybe there’s a problem there.
[import]uid: 9905 topic_id: 2289 reply_id: 21799[/import]