Home

Awesome

MoonFreeType: Lua bindings for FreeType

MoonFreeType is a Lua binding library for the FreeType library.

It runs on GNU/Linux and on Windows (MSYS2/MinGW) and requires Lua (>=5.3) and FreeType (>=2.6.1).

Authored by: Stefano Trettel

Lua logo

License

MIT/X11 license (same as Lua). See LICENSE.

Documentation

See the Reference Manual.

Getting and installing

Setup the build environment as described here, then:

$ git clone https://github.com/stetre/moonfreetype
$ cd moonfreetype
moonfreetype$ make
moonfreetype$ make install # or 'sudo make install' (Ubuntu)

Example

The script below loads a font face from a file and lists the contained glyphs:

-- MoonFreeType example: listglyphs.lua

ft = require("moonfreetype")

fontfile = arg[1]
if not fontfile then print("Usage: " .. arg[0] .. " <fontfile>") return end

-- Create a library:
lib = ft.init_freetype()

-- Create a face, loading from fontfile:
face = ft.new_face(lib, fontfile)

-- List all the glyphs (character code - glyph index - glyph name):
charcode, index = face:get_first_char()
while index do
   print(charcode, index, face:get_glyph_name(index))
   charcode, index = face:get_next_char(charcode)
end

lib:done()

The script can be executed at the shell prompt with the standard Lua interpreter, passing it a font file name, e.g.:

$ lua listglyphs.lua myfavouritefont.ttf

Other examples can be found in the examples/ directory.

See also