Embedding custom fonts

Does this work with the Windows Simulator? I am having trouble trying to get a custom font on my windows machine working. Of course this is Android only. [import]uid: 27076 topic_id: 2289 reply_id: 21991[/import]

turns out it’s the font, “linesquare rounded extended” on dafont.com it’s a free font, so you can try it yourself. Perhaps it’s a problem because it’s a .ttf. Does Corona only work with .otf?

UPDATE:

Different .ttf worked fine. Maybe it has trouble with pixelized Flash compatible fonts? [import]uid: 20703 topic_id: 2289 reply_id: 22286[/import]

Shanathan, I was able to get that linesquare rounded extended font to work in the simulator. Haven’t tried it on an iPhone.

Three things to check.

  1. Make sure you have a copy of the font in your library/fonts folder

  2. Make sure you have a build.settings file at the same level as your main.lua file. It needs to have this code in it:

[lua] iphone =
{
plist=
{
UIAppFonts = {
“linesquare_rounded_extended.ttf”,
},
},
},[/lua]

Here the file name has to exactly match the actual font file.

  1. When calling the font in your code, make sure you use the actual name of the font, as seen in FontBook and other apps. In this case, it’s “Linesquare Rounded Extended” (case is important). For example,

[lua]local debugText = display.newText(“Test message”, 24, 0, “Linesquare Rounded Extended”, 44)
debugText:setTextColor(255, 70, 70)
debugText.y = 24
debugText.x = 54[/lua]

[import]uid: 9905 topic_id: 2289 reply_id: 22314[/import]

I’ve tried all possible solutions but I can’t get my custom font working on the device, it works fine in the simulator but on the device no text will display at all :frowning: [import]uid: 35378 topic_id: 2289 reply_id: 23405[/import]

Urme, I’ve had mixed results with fonts. Some worked for me and some didn’t. See if you can get any custom fonts to work, like the Harrowprint example described here.

If you can get that one to work, then you could try your own. But I’ve found that at least 2/3 of the fonts I’ve tried didn’t work, maybe because they’re not TrueType, or some other issue. You could then zip up your project, including the font, upload it to your website, and link to it here so others can take a look. [import]uid: 9905 topic_id: 2289 reply_id: 23451[/import]

Atheros, I had trouble with certain fonts while others worked fine. Never figured out why. So best place to start is with a font that we know works and see if you can get that to work on your device. Then try replacing with other fonts. Start by downloading the Harrowprint font that’s linked from this page

http://developer.anscamobile.com/content/display-objects#Using_a_custom_font

Once you can get that one working, you at least know you have the settings correct.

I’m guessing that only Truetype fonts work… I’ve asked about this but haven’t gotten a confirmation.

[import]uid: 9905 topic_id: 2289 reply_id: 26138[/import]

Hi guyz

I have been reading this comments since morning up and down if i am missing something or not but i am yet not able to get the custom fonts on my device !!

Made changes in the build.setting file with the fonts in the root directory. which made the application work in Xcode sim but when the same thing was transferred to the Ipad the font is invisible

Dont know exactly how it would work.

If you guyz can upload a small example with the custom font which works just fine would be if a great help

Update…

I used the example provided above in my windows simulator downloading the ttf font and installed it in my fonts directory and also kept it in my root file used the exact same code provided above to test it

but the fonts wont load.

later i used a few other fonts which didnt had space in middle of their name and they were working just fine
which gives me a conclusion there is some issue with spaced name of the fonts which gives a conflict can you please confirm this back or if i am wrong can you provide solution.

Thanks and Regards
Atheros [import]uid: 35284 topic_id: 2289 reply_id: 26135[/import]

Hey David,
[lua]local text = display.newText( “Hello Harrowprint font!”, 0, 0, “Harrowprint”, 50 )[/lua]

I saw the “Harrowprint” does not have a space in the middle i am sure this will work fine i tried many fonts i wish there was a a option to attach the file i would have attached the example so that ansca people can figure out the actual reason behind it

Regards
Atheros [import]uid: 35284 topic_id: 2289 reply_id: 26144[/import]

Atheros, I also recall wondering if there might be an issue with fonts with a space in their name. I suggest you report this as a bug. There you can attach a zip file of your project (including the font) so the Ansca staff can try and duplicate the problem.

Click on “Report a Bug” in the upper right corner of this page, or go here:

http://developer.anscamobile.com/content/bug-submission
[import]uid: 9905 topic_id: 2289 reply_id: 26146[/import]

An alternative (with both advantages and disadvantages) to compiling a TTS font into your project may be to use a pre-rendered bitmap font.

You can read about and download my implementation in this thread:
https://developer.anscamobile.com/forum/2011/02/05/bitmap-font

The advantages of a bitmap font are:

  • You can have fonts which include baked-in effects like drop-shadow and gradient fill.
  • You can use custom fonts without worrying about the tricky TTF embedding.
  • You can save space by including only those letters that you will need.

The disadvantages of a bitmap font are:

  • You cannot display text at arbitrary sizes
  • You cannot display text in arbitrary colors
    You can work around these two issues by creating multiple font files in different colors and sizes or by creating a large font file and scaling the text down.
    [import]uid: 32962 topic_id: 2289 reply_id: 26370[/import]

I am a windows user and am building for Android, it is my understanding then that for android, you do not need to add the font in your build settings correct? I still cant seem to get it to work in my game. here is my code:

local mytime = display.newText("0", 0, 0, "Harrowprint", 35)  

and i have the font installed and also a copy in my root folder
[import]uid: 19620 topic_id: 2289 reply_id: 28316[/import]

Any news or official docs on how to embed fonts and sample code?
Am using Windows and trying to build for Android.
[import]uid: 40581 topic_id: 2289 reply_id: 30132[/import]

I finally got mine to work, but like others have said, it seems that only fonts that are single word named will work. All you need to do is install the font in your windows/fonts folder. then also make a copy to put in the root of your project folder, and then in your code you would replace Harrowpoint with whatever your font is named. (use the name that is shown in microsoft word, not the fonts file name)

should do the trick [import]uid: 19620 topic_id: 2289 reply_id: 30166[/import]

I am getting nowhere trying to get font embedded using Windows build for Android.
My font is ravie.ttf (single name) and is in the root directory.
It works fine in the simulator but not when built. I am using the trail version (377) of corona might that be an issue.
Any help greatly appreciated

Ansca?

[import]uid: 40581 topic_id: 2289 reply_id: 31064[/import]

Any updates on helping this out? I’m stuck like g.harrison. Tried everything… or so it seems. I even re-encoded it with fontLab. Still no luck. [import]uid: 10361 topic_id: 2289 reply_id: 32791[/import]

3cord, as I mentioned above, if you are desperate for a custom font and can’t get the TTF fonts to embed, you can try using my BMF library (free) or TextCandy to display a bitmap font.

You can generate bitmap fonts from TTF fonts using BMFont (free, Windows) or GlyphDesigner (better program, paid, Mac). [import]uid: 32962 topic_id: 2289 reply_id: 32792[/import]

Thanks for the idea p120.

I actually just now got it working. It was an error in my build settings. I had a comma and a curly brace in the wrong spot. So it works on my device now.

If anyone wants to use my build settings here they are:

settings = {  
 orientation = {  
 default = "landscapeRight",  
 supported = { "landscapeLeft", "landscapeRight"}  
 },  
 iphone = {  
 plist = {  
 CFBundleIconFile = "Icon.png",  
 CFBundleIconFiles = {  
 "Icon.png" ,   
 "Icon@2x.png" ,   
 "Icon-72.png" ,   
 "Icon-Small-50.png" ,   
 "Icon-Small.png" ,   
 "Icon-Small@2x.png"  
 },  
 UIStatusBarHidden = true,  
 UIPrerenderedIcon = true,  
 UIApplicationExitsOnSuspend = true,  
 UIAppFonts = {"YourFontHere.ttf"}  
 },  
 }  
}  
  

Like I said, once I got this under control it worked perfectly. Even fixed an error I had with one of my icons. [import]uid: 10361 topic_id: 2289 reply_id: 32795[/import]

Another quick tip (This is probably a no-brainer to those with a little more experience):
I needed a custom font on an Android app, so I downloaded the font, installed it on Windows, and copied the .ttf file to the app root directory. It still wasn’t working, even after I had read and reread the above thread to make sure I was doing it right.
Turns out I just had to completely close and reopen the simulator. Once I did that it worked perfectly. [import]uid: 29171 topic_id: 2289 reply_id: 37967[/import]

brainsofsteel answer is the one that got it working for me … All the others are good, but no one else mentioned shutting the SIM and restarting… [import]uid: 41214 topic_id: 2289 reply_id: 40294[/import]

Hi,

who wants to embed the whole Unicode font file? In practice I need in my app only some symbols out of this font! How can I limit the character set that is embeded without having to create a complete new ttf file?

Regards,
Devarai [import]uid: 75667 topic_id: 2289 reply_id: 45403[/import]