How to Use Custom Font?

The docs say to use a custom font by putting the font filename in the actual code:

https://docs.coronalabs.com/guide/system/customFont/index.html

I saw that was supposed to be for a daily build, not the latest public build. but that doc page is for the public build, yes?

The problem I’m having is that on the device all I’m seeing are squares with question marks in them – so I guess that means the custom font is being used, but it just doesn’t work for the device???

 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

Yes, I just tried 3rd font with the same result.

What’s also weird is that often (maybe 50%?) of the time the build doesn’t show up on the device, although Corona tells me it’s been copied over and no errors are generated. Not sure if this is a different problem, or part of the same thing.

This is what the console log looks like when it doesn’t actually copy:

Jul 25 06:49:58.658 Installing ‘Robotronish.app’ on Jay’s_iPad_mini …

Jul 25 06:49:58.658 ----------  Device Log Starts  ----------

Jul 25 06:50:04.076 Exiting…

Jul 25 06:50:04.076 Exiting…

Jul 25 06:50:04.076 ---------- Device Log Finished ----------

Should there be more stuff in there?

 Jay

I don’t remember if fonts are loaded but maybe not.
Just had a thought can you post your build.settings

settings = { orientation = { default ="portrait", content = "portrait", supported = { "portrait","portraitUpsideDown" }, }, iphone = { plist = { UIApplicationExitsOnSuspend = false, UIPrerenderedIcon = true, UIStatusBarHidden = true }, }, }

Ok never mind, i always delete the app on my device before I build. I have never experienced any like this when buld for iOS.

Just rebuilt another game using a custom font and it worked fine on the device – copied that font to the new project and set it as mainFont in my main.lua and did a build – and it doesn’t work on the device.

So something(?) in my new project is blocking custom fonts from working?

I’m going to start ripping things out and see what happens…

Below is a link to the project that consists of a main and menu (composer scene file). Main goes straight to menu and there’s a button that should say “Play” using the included custom font. But on my devices and the Xcode simulator all I see are squares with question marks. Works fine in Corona Simulator.

Any ideas?

 Jay

http://gamedevnation.com/files/WhattheShell.zip

The failing to copy the app on build does happen to me from time to time. It seems to happen more on my iPad than my iPhone. I think you’re the first one to report it in the forums, so it’s a bit more wide spread that something in my setup. I’ll see if I can repo it and catch the full log to send to an engineer.

I’ll look at the zip file too and see what’s up.

Rob

Also what device/OS version are you testing on?

What version of Xcode is installed?

What version of macOS are you running?

Thanks

Rob