Using Custom Fonts

This guide outlines how to include and use custom embedded fonts in Corona, allowing you to stylize your app more consistently across platforms.

Font File Support

While both TrueType (.ttf) and OpenType (.otf) fonts are theoretically supported, there is no guarantee that any font will work across all platforms. Essentially, fonts are loaded by the operating system, and whether or not a particular font is supported depends on the platform and OS version. For example, on Windows and some versions of Android, there may be compatibility issues with certain OpenType font files (.otf), and if the platform/OS refuses to load a font, Corona will fall back to a default system font and the error will get logged. Essentially, if you use custom fonts, you should test on as many potential target devices as possible.

Including and Using Fonts

  1. Copy the font file to the main project directory, alongside main.lua or copy it to a subdirectory. If you do include the subdirectory name in the path.

  2. To use the font, pass the font file name as a [string][api.type.string] to the appropriate API, including the file extension:

-- Standard text object -- font in the same folder with main.lua
local displayText = display.newText( "Hello World", 150, 80, "CoolCustomFont.ttf", 24 )

-- Standard text object -- font in a folder named "fonts"
local displayText = display.newText( "Hello World", 150, 80, "fonts/CoolCustomFont.ttf", 24 )

-- Font for native text input field
local inputText = native.newFont( "CoolCustomFont.ttf", 16 )
local textField = native.newTextField( 150, 150, 180, 30 )
textField.font = inputText