Lua logo

Preface

This is the reference manual of MoonFonts, which is a Lua binding library for Sean Barrett’s Bitmap fonts for C/C++ 3D programmers. [1]

It is assumed that the reader is familiar with the Lua programming language.

For convenience of reference, this document contains external (deep) links to the Lua Reference Manual.

Getting and installing

For installation intructions, refer to the README file in the MoonFonts official repository on GitHub.

Module organization

The MoonFonts module is loaded using Lua’s require() and returns a table containing the functions it provides (as usual with Lua modules). This manual assumes that such table is named fonts, i.e. that it is loaded with:

 fonts = require("moonfonts")

but nothing forbids the use of a different name.

Examples

Complete examples can be found in the examples/ directory of the release package.

License

MoonFonts is released under the MIT/X11 license (same as Lua, and with the same only requirement to give proper credits to the original author). The copyright notice is in the LICENSE file in the base directory of the official repository on GitHub.

See also

MoonFonts is part of MoonLibs, a collection of Lua libraries for graphics and audio programming.

Bindings

  • font = load(fontname, [pow2])
    Loads the font named fontname (a string), or nil if the font is not available, and returns a table with the properties of the font face, the texture atlas, and the metrics for rendering individual characters.
    Pass pow2=true if you want the image dimensions to be powers of 2.

  • {fontname} = list( )
    Returns a list with the names (strings) of the available fonts.

  • boolean = is_available(fontname)
    Returns true if the font named fontname is available, false otherwise.

Note
For fontname for the font implemented in the stb_font_xxx.inl file is 'xxx' (e.g. the name for the font implemented in stb_font_consolas_24_latin1.inl is 'consolas_24_latin1').

font = {
name: string,
num_chars: integer,
width: integer,
height: integer,
pixels: binary string (texture atlas, width x height bytes),
line_spacing: integer,
fontchar: {fontchar} (indexed by codepoint),
}

fontchar = {
codepoint: integer,
s0, t0, s1, t1: number,
x0, y0, x1, y1: number,
advance: number,
s0f, t0f, s1f, t1f: number,
x0f, y0f, x1f, y1f: number,
advancef: number,
} (Rfr: stb_fontchar)


1. This manual is written in AsciiDoc, rendered with AsciiDoctor and a CSS from the AsciiDoctor Stylesheet Factory.