Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Embedding custom fonts
Started by Eric Sep 30 2010 07:19 AM

- - - - -
49 replies to this topic
[TOPIC CONTROLS]
Page 2 of 2 1 2
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#26

DavidBFox

[GLOBAL: userInfoPane.html]
DavidBFox
  • Contributor

  • 179 posts
  • Corona SDK

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.

uid: 9905 topic_id: 2289 reply_id: 26138


[TOPIC: post.html]
#27

nhakimsat20101

[GLOBAL: userInfoPane.html]
nhakimsat20101
  • Observer

  • 9 posts
  • Guests

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
uid: 35284 topic_id: 2289 reply_id: 26135


[TOPIC: post.html]
#28

nhakimsat20101

[GLOBAL: userInfoPane.html]
nhakimsat20101
  • Observer

  • 9 posts
  • Guests

Hey David,
local text = display.newText( "Hello Harrowprint font!", 0, 0, "Harrowprint", 50 )


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
uid: 35284 topic_id: 2289 reply_id: 26144


[TOPIC: post.html]
#29

DavidBFox

[GLOBAL: userInfoPane.html]
DavidBFox
  • Contributor

  • 179 posts
  • Corona SDK

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
uid: 9905 topic_id: 2289 reply_id: 26146


[TOPIC: post.html]
#30

p120ph37

[GLOBAL: userInfoPane.html]
p120ph37
  • Enthusiast

  • 46 posts
  • Corona SDK

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.
uid: 32962 topic_id: 2289 reply_id: 26370


[TOPIC: post.html]
#31

rxmarccall

[GLOBAL: userInfoPane.html]
rxmarccall
  • Contributor

  • 751 posts
  • Corona SDK

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
uid: 19620 topic_id: 2289 reply_id: 28316


[TOPIC: post.html]
#32

g.harrison

[GLOBAL: userInfoPane.html]
g.harrison
  • Observer

  • 17 posts
  • Corona SDK

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


[TOPIC: post.html]
#33

rxmarccall

[GLOBAL: userInfoPane.html]
rxmarccall
  • Contributor

  • 751 posts
  • Corona SDK

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
uid: 19620 topic_id: 2289 reply_id: 30166


[TOPIC: post.html]
#34

g.harrison

[GLOBAL: userInfoPane.html]
g.harrison
  • Observer

  • 17 posts
  • Corona SDK

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?

uid: 40581 topic_id: 2289 reply_id: 31064


[TOPIC: post.html]
#35

3CordGuy

[GLOBAL: userInfoPane.html]
3CordGuy
  • Contributor

  • 128 posts
  • Corona SDK

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.
uid: 10361 topic_id: 2289 reply_id: 32791


[TOPIC: post.html]
#36

p120ph37

[GLOBAL: userInfoPane.html]
p120ph37
  • Enthusiast

  • 46 posts
  • Corona SDK

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).
uid: 32962 topic_id: 2289 reply_id: 32792


[TOPIC: post.html]
#37

3CordGuy

[GLOBAL: userInfoPane.html]
3CordGuy
  • Contributor

  • 128 posts
  • Corona SDK

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.
uid: 10361 topic_id: 2289 reply_id: 32795


[TOPIC: post.html]
#38

brainofsteel

[GLOBAL: userInfoPane.html]
brainofsteel
  • Enthusiast

  • 44 posts
  • Corona SDK

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.
uid: 29171 topic_id: 2289 reply_id: 37967


[TOPIC: post.html]
#39

phulesgame

[GLOBAL: userInfoPane.html]
phulesgame
  • Observer

  • 1 posts
  • Guests

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.....
uid: 41214 topic_id: 2289 reply_id: 40294


[TOPIC: post.html]
#40

henning

[GLOBAL: userInfoPane.html]
henning
  • Observer

  • 2 posts
  • Corona SDK

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
uid: 75667 topic_id: 2289 reply_id: 45403


[TOPIC: post.html]
#41

qmnjb007

[GLOBAL: userInfoPane.html]
qmnjb007
  • Observer

  • 1 posts
  • Guests

i have this same problem as well... did you ever find a solution??
uid: 39086 topic_id: 2289 reply_id: 50520


[TOPIC: post.html]
#42

lhvio89

[GLOBAL: userInfoPane.html]
lhvio89
  • Enthusiast

  • 64 posts
  • Corona SDK

Hello,

I'm running into issues embedding custom fonts here as well. I followed the sample that is in the documentation (with Harrowprint, which I downloaded from the link provided in the sample code), and the custom font just won't display. I've copied the code to the letter, and made sure every file is in its proper place before running.

Are custom fonts just not working right now?

Thanks!
Logan
uid: 44896 topic_id: 2289 reply_id: 66594


[TOPIC: post.html]
#43

me7

[GLOBAL: userInfoPane.html]
me7
  • Enthusiast

  • 65 posts
  • Corona SDK

^I wonder the same as above. Anything changed on r704?

My font is being found (checked that names match), but is not loaded by the simulator. In Android it's not loaded (nor is it in the list of fonts).

I tried a bunch of "tricks":
1. Putting font in root dir (obvious)
2. Installing font in Windows (for simulator to see it, it still fails to load it though it is in fonts list)
3. Change font extension from OTF to TTF (including removing it)
4. Testing both font name and font names match, and also tried with filename(both with and without extension on both Android and simulator
5. Simplifying font name with FontForge (actually, it was simple already but I changed to an 8 letter lower case name)

Probably irrelevant, but in a pure Android version of the app, the font is loadable, but I guess Corona uses different font loading code.

Any more ideas? Or shall I submit as bug report? I would normally just select a working font but I'm on a short deadline and client specifically wants this font.
uid: 58849 topic_id: 2289 reply_id: 85931


[TOPIC: post.html]
#44

matias.kiviniemi

[GLOBAL: userInfoPane.html]
matias.kiviniemi
  • Enthusiast

  • 40 posts
  • Corona SDK

Any new insights, tricks or tips on this topic? I've hit a wall to get my custom font to load on Android. It works on simulator (windows) and I've tried all mentioned variations, i.e. simplifying names, referencing file name vs. font name, ttf vs. otf, rebooting but no luck.
uid: 46570 topic_id: 2289 reply_id: 103837


[TOPIC: post.html]
#45

me7

[GLOBAL: userInfoPane.html]
me7
  • Enthusiast

  • 65 posts
  • Corona SDK

I just gave up and embedded custom fonts for static strings into images and used system defaults for most dynamic strings, and had the font exported to BMF (bitmap font) for some dynamic strings where the difference in style was too distinct to be ignored.

I think, it's just something in the font file that causes loading in Corona to silently fail for that font. If it's possible, one can simply try replacing the font. However, my client had decided that that particular font should be used and I couldn't explain why it wouldn't work in Corona as opposed to Java Android. Tough luck. :-)
uid: 58849 topic_id: 2289 reply_id: 103856


[TOPIC: post.html]
#46

matias.kiviniemi

[GLOBAL: userInfoPane.html]
matias.kiviniemi
  • Enthusiast

  • 40 posts
  • Corona SDK

Result! \o/

I did an experiment that maybe it wants the actual path and tried using the pathToFile-version form resoure-dir. This helped nothing, but using aLogCat I could see Corona gave an error about not finding the font. So I concluded Corona tries to load the font but fails silently (like people suggested).

Next attempt convert/resave the font file if that would help. FontForge that was recommended seemed like a major PITA in Windows so I tried Type Light and a couple of web tools. What gave results was
http://onlinefontconverter.com/

When I converted from .otf to .ttf, the tool changed the filename from the original, presumably to match the font metadata. Using this new file and name (without extension!) worked! Either that tool changes file format, or it's the fact of file name matching internal metadata.

So to be clear
1) Upload "OldName.otf" to site
2) Save "NewName.ttf" to project root
3) Use "NewName" as the font name in Corona

And all this is ANDROID!
uid: 46570 topic_id: 2289 reply_id: 104154


[TOPIC: post.html]
#47

calebr2048

[GLOBAL: userInfoPane.html]
calebr2048
  • Contributor

  • 182 posts
  • Corona SDK

@matias.kiviniemi

Thank you so much for this! It worked for me too! This is the first time I've ever been able to get a custom font to work on an Android device.
uid: 27965 topic_id: 2289 reply_id: 109147


[TOPIC: post.html]
#48

matias.kiviniemi

[GLOBAL: userInfoPane.html]
matias.kiviniemi
  • Enthusiast

  • 40 posts
  • Corona SDK

That's good to hear. This process worked for me on two fonts on both iPhone and Android. But that is to say "I got fonts to load". The other font still did not render properly (had strange small T-letters). So the custom fonts is a bit touchy.
uid: 46570 topic_id: 2289 reply_id: 109415


[TOPIC: post.html]
#49

joemauke

[GLOBAL: userInfoPane.html]
joemauke
  • Observer

  • 24 posts
  • Corona SDK

I never got a good answer to my question a few years back about embedded text vertical alignment. Its fine in the simulator, but on the app its off by about 3-5px.  Could this be the font ascender?  And if it is, how can I fix this?



[TOPIC: post.html]
#50

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 26,408 posts
  • Enterprise

The best way is to probably put in an if statement to see if your on the simulator or device and provide some padding adjustment to the x, y of your text string.




[topic_controls]
Page 2 of 2 1 2
 
[/topic_controls]