freetype depends on Frisket
freetype contains no utilities.
The freetype package is marked as Compatible, which means any game can use it. However, if your game is not GPL and uses FreetypeFont, you must add the following notice (or a similar one) somewhere in the game (such as the title screen) in order to comply with the FreeType license:
Portions of this software are copyright (C) 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007 The FreeType Project (www.freetype.org). All rights reserved.
When the freetype package is loaded, it prints this notice to stdout at startup. Most users won't see this, so it doesn't count. Your game should present this notice (or an equivalent) somehow, such as on the splash screeen. This is only printed to remind you, the developer, that you need to present a notice to the user. You can suppress the printing of this notice by setting the global freetype_copyright_ok to a non-nil value before initializing SubCritical.
FreetypeFont encapsulates an instance of a Font in the FreeType library. It can be used to render TrueType (TTF) and other fonts for display.
FreetypeFont performs subpixel pen positioning and kerning, but does not hint.
Because of the high quality of FreetypeFont's output, very little caching can be done. As such, rendering text is expensive. Try to cache rendered text if possible, and try to render as little text as possible.
- font = SubCritical.Construct("FreetypeFont", path)
font = assert(SubCritical.Construct("FreetypeFont", path))
- Tries to load the font located at path (see SCPath) in a format FreeType knows. If this font is important, you may want to assert it (as above).
- offset = font:GetNextChar(string[, start[, stop]])
- Returns the byte offset to add to start to skip one UTF-8 character. This can be used in a text editing situation to construct a table of character boundaries with which to move the insertion point back and forth. start and stop behave like the parameters of string.sub.
- Prepares font to be rendered at size (possibly non-integer) points. By providing two sizes, you can achieve different aspect ratios.
- All of the below functions are affected by this size.
- stop,next_start = font:BreakLine(text[, width[, start]])
- Returns a suitable stop value to pass to GetTextWidth or RenderText to render the largest single-line span of text that is less than width wide, and a suitable start value to pass to the next BreakLine. If next_start is nil, this is the last line. If stop is nil, there was no printable text left.
- width = font:GetTextWidth(text[, start[, stop]])
- Returns the approximate width, in pixels, of text as rendered by font. start and stop behave like the parameters of string.sub.
- frisket[,outpen] = font:RenderText(text[, start[, stop[, width[, x[, y]]]]])
- Returns a Frisket containing text as rendered by font. start and stop behave like the parameters of string.sub. If width is not provided, an appropriate value is calculated.
- If x and/or y are provided, their fractional portion is interpreted as a subpixel offset for the rendered text in the positive X and Y direction, respectively. In combination with outpen, which is the amount that the pen advanced (including the fractional portion of x if provided) from the origin, this can be used to render multi-style text with subpixel precision.
- height = font:GetLineHeight()
- Returns the (possibly non-integer) offset between lines of text in font.
- height = font:GetAscender()
- Returns the (possibly non-integer) offset between the top of a rendered Frisket and the baseline of text in font.
Back to index