How to Use Custom Font?

I ran and built your test app on my iPad 4 with no changes. Here are the results:

Simulator (2906): worked (see 1st screen shot)

iPad 4 (iOS 9.3.2): worked (see 2nd screen shot)

So at this point since no fonts seem to work it has to be something local blocking it and I really have no clue what that might be… I’ll try to have a conversation with the engineers in a bit to see they have any ideas.

Does this font/method of loading work in other apps where you do have custom fonts work?

Can you do another test this time loading the font old school (include the UIAppFonts block in build.settings, load by Font Family name instead of file name) and see if that works?

Finally I noticed this in my log file:

Jul 26 10:56:33.548 Activated fonts in ‘Robotron.ttf’ (Robotron)
Jul 26 10:56:33.593 Copyright © 2009-2016  C o r o n a   L a b s   I n c .
                        Version: 3.0.0
                        Build: 2016.2906
Jul 26 10:56:33.621 Loading project from:   /Volumes/Macintosh HD/Media/Downloads/What the Shell
Jul 26 10:56:33.622 Project sandbox folder: ~/Library/Application Support/Corona Simulator/What the Shell-BEA285BAA549719F01AEB0DF37AF1A03
Jul 26 10:56:33.657 Platform: iPhone / x86_64 / 10.11.5 / Intel HD Graphics 4000 OpenGL Engine / 2.1 INTEL-10.14.66 / 2016.2906 / en | US | en_US | en

Are you seeing that line?

Forgot to attach the files:

I just build the app for Mac OS and IPhone 6s works.

I just did a macOS build too and it worked as expected.

Okay, I’m using:

OS X 10.11.5

Xcode 7.3.1

iPad mini 2 9.3.2

iPhone 6 9.3.3

I got the “Activated” line when the app *didn’t* get copied to the device, but right now it’s copying every time and that line is not appearing.

I’ll try switching back to the “old fashioned” way and see what happens.

 Jay

This is the first project I’ve done since the new way was available. But I just switched to the new way in an older project and it freaking works. Argh!

I went back through that sample project and there’s almost nothing there – nothing that should cause problems at all. But even that little sample project will not show a custom font on a device. I’ve tried both the old and new ways with no luck on iOS…

…although it does work when installed on my Android device. Double argh!!!

 Jay

I discovered the problem, and it looks like Corona Labs’ fault rather than mine!!! Woohoo! :wink:

When I did a build I chose “What the Shell?!” as the application name, but this evening I used that as the name of the build folder, I found Corona Simulator barfed on it. So then I changed the name of the folder and changed the build Application Name (took off the ?!) and now the custom fonts are showing in the game!

The folder problem happens with the question mark – don’t know if that’s the same for the custom font issue (or if it’s the exclamation point, or both) because it’s about 4AM and now that I found the problem I’ll leave it to a CL engineer to look further. :wink:

 Jay

Can you file a bug report on this please? You will need a complete project (main.lua, config.lua, build.settings and any assets such as the fonts) that demonstrates the problem. Put that in a .zip file and use the Report a bug link at the top of the page.

Thanks

Rob

It’s bug #46860 – and I bugged the other one separately because I figured they might actually be two different areas of the code, two different types of fixes, whatever. Just in case. :slight_smile:

 Jay

The font *does* work fine the way I have it coded when I build for OSX, though. (I deleted it from my system fonts.)

OSX is not case sensitive , so that be it. Also it might just be the font, some fonts don’t work on certain devices. 

Okay, I tried the .otf version of the font and it didn’t work. so then I tried a completely different font – and it didn’t work, either.

The _ strange thing about that _ is I used the same font in my last game, which was done in Unity, and it works fine on the device, so I’m thinking it’s *not* the font that’s the problem. 

I’m using it like this: 

local mainFont = "BoogalooOne-Regular.ttf" -- and then later on... local dTxt = display.newText(txt, 0, 0, mainFont, 24)

The .ttf font file is in the root directory of the project and I can see from the console that it’s actually in the project:

Copying /Users/jay/Desktop/What the Shell/BoogalooOne-Regular.ttf to /Users/jay/Desktop/What the Shell?!.app/BoogalooOne-Regular.ttf

I’m using Corona v2016.2906 that I just downloaded today.

 Jay

Ok i used corona 2912 and it worked fine. Attached a demo below along with an image it work on device and simulator.

Hmmm…this is weird. Your test worked on my device. So I tried some things:

  1. I updated to the daily build to make sure that wasn’t the problem.
  2. Saw you were using Boogaloo-Regular instead of BoogalooOne-Regular, so I downloaded that. (Var in code changed to the new name.)
  3. When that didn’t help I used the actual .otf file from your example. 

None of those fixed the problem, I’m still getting squares with question marks. The device is an iPad mini 2 (Retina) and I’ve also tried my iPhone 6S with the same results. I completely delete the old app from the device before trying a new build. No errors in the build console.

At this point I assume it’s something dumb that I’m doing and just not seeing. I think I’ll go for a walk and come back with a bigger hammer.

Thanks for your help, Scott.

 Jay 

Can you post the font you are using? You don’t have to if it is private or paid product.

I can, but there’s something else weird going on. I rebooted my machine (you know, because if that’s good enough for Windows, it’s good enough for Mac?) and started again, double-checking things first.

It looks like the Corona Simulator is “caching” stuff and not taking the new files for the build. Or something. After the build it’s telling me it can’t find the font, but that was from before I rebooted when I was just testing stuff – according to the source code the font name is correct (I misspelled the font name on purpose just to make sure it would default to system font – it did).

Plus, the build console is showing me a runtime error, but I never launched the app yet. In fact, the app doesn’t even show up on the device. That runtime error happened the last time I ran the app on the device.

So something strange is going on and I’m thinking it may not have anything to do with the font at all. (Although it only started happening when I put in the custom font.)

Let me poke some more…

 Jay

ok

Okay, here’s the font I’m using:

http://masteringcoronasdk.com/files/Boogaloo-Regular.otf.zip

I finally got a build with no (false) errors but still no custom font. Grrr!

 Jay

I just tried your font works fine on my iOS device and my mac

Just to clarify things…

  1. We added the ability across all platforms to use just the filename after the previous public build. But it’s in the current public build (2906).

  2. Have you tried a different font just to make sure it’s not a problem with that particular font.

  3. Fonts no longer have to be installed on the device to work in the simulator.

  4. That it works in a macOS build but not a simulator run seems odd indeed. Again you probably should try a different font just to rule out problems with that font file. Even though we let you load by file name, we still have to get the font family name from the font itself (and you can still use font family names as well!) to render the font, so if there is something wonky internally…

Rob