# Font Loader

# Overview

Spyric Font Loader is a simple to use utility plugin that will preload all of your fonts.

Whenever Solar2D uses a font file for the very first time, Solar2D will cache it. Depending on what platform your app is running on, this may be a couple of milliseconds or hundreds of milliseconds per font. Once a font has been cached, using it again during runtime will be near instant.

By using Spyric Font Loader to preload your all of app's fonts, you can avoid any lag spikes that might occur while your app first uses a font, resulting in a superior user experience.

# Setting up

Spyric Font Loader is a fully open-sourced plugin. In order to set it up, all you need to do is download it from GitHub, then place it in your project's root folder and require it.

local fontLoader = require( "fontLoader" )

# Functions & syntax

preload: loads & caches fonts.

fontLoader.preload( [folder] [, options] )
folder (optional)
string. The folder where your fonts are located.
options (optional)
table. A table that may containing optional parameters.

# preload options

The options table can contain various options pertaining to where and how the fonts are preloaded:

directory (optional)
constant. The base directory where the folder is located. Default is system.ResourceDirectory.
deepScan(optional)
Boolean. If true, the font loader will look for fonts in the given folder and all of its subfolders. If no folder is defined, then deepScan would scan all folders in the base directory, e.g. the app's entire resource directory. Default is false.
consoleOutput(optional)
Boolean. If true, the font loader will print what it is doing to the Solar2D console. Default is false.

# Examples

Preload all fonts from a specific folder.

local fontLoader = require( "fontLoader" )
fontLoader.preload( "fonts" )

Preload all fonts in the entire app and show print event messages to Solar2D console.

local fontLoader = require( "fontLoader" )
fontLoader.preload( { deepScan=true, consoleOutput=true } )