4

I am trying to integrate custom fonts (Imperator.ttf and goodfish.ttf) from the following website into my corona app:
http://www.1001freefonts.com/top-fonts.php

I am following carefully the tutorial found here on Corona's official website:
http://www.coronalabs.com/blog/2013/01/16/faq-wednesday-custom-fonts/

I follow the whole procedure for macosx integration (installing the font by double clicking etc) and do not get any error. I also added the font file name to my build.settings file:

 UIAppFonts =
 {
       "Imperator.ttf"
 },

Whenever i launch the simulator and debug the currently loaded fonts, the new one doesn't appear.

Is there an easy way to debug the issue on corona simulator, on osx, to troubleshoot why the font doesn't load ?

Thanks

Teddy Engel
  • 996
  • 6
  • 17
  • Here you have an efficent way to change the font for the entire application: http://stackoverflow.com/questions/18847531/access-a-typeface-once-from-asset-and-use-it-as-a-reference/18847778#18847778 – Diego Palomar Oct 31 '13 at 09:28

2 Answers2

7

While installing custom fonts to your corona application, you have to follow the following steps:

  • Install the font in your system.
  • Copy and paste the font file(such as: Imperator.ttf) to the application folder where your main.lua exists.
  • Then for iPhone(only for iPhone, Android doesn't need this), add the following lines to your build.settings:

iphone =
    {
        plist =
        {
            UIAppFonts =
            {
                "Imperator.ttf"  -- Font file name
            },
            UIApplicationExitsOnSuspend = true
        },
    }

  • Debug and get the supported Font Names by the system using the following:

local fonts = native.getFontNames()
for i,fontname in ipairs(fonts) do
    print(fonts[i])
end

From the above debugging, you can get the exact Font Name (here: Imperator) that you have to use while creating the text/label. Sometimes this may differ from the name of the font file. You can also get it from applications like photoshop(it's text tool font name), etc.

local myText = display.newText("Label with custom font",150,100,"Imperator",20)

Then finally, you will get the output as:

enter image description here

Keep coding................

Krishna Raj Salim
  • 7,331
  • 5
  • 34
  • 66
  • 1
    Thanks ! I noticed what i had wrong, it was actually the method used to display installed fonts, taken from: http://www.coronalabs.com/blog/2013/01/16/faq-wednesday-custom-fonts/ Oh well :) Thanks for that ! – Teddy Engel Oct 30 '13 at 16:54
-2

Put Imperator.ttf font file in Assets folder

In class use following code:

Typeface imperator_typeface =Typeface.createFromAsset(getContext().getAssets(),"Imperator.ttf");

your_textview.setTypeface(imperator_typeface);

techroid
  • 477
  • 4
  • 11