# The libfreetype module

## Introduction

The libfreetype module is a font engine. As such, it can rasterize characters into bitmaps. The freetype library is wrapped by mdefont, which provides a higher-level interface and useful utilities such as caching. Freetype is a third-party module, not implemented by Opera.

### Output formats

Freetype supports three pixel formats: 1-bit bitmaps, 8-bit gray-level pixmaps and three-component pixmaps (either horizontally or vertically) used for sub-pixel rendering.

### Supported font formats

Freetype can support at least the following font formats:

- TrueType
- OpenType
- Type1
- CID
- CFF
- Windows FON/FNT
- X11 PCF
- SFNT-based bitmap fonts
- BDF
- PFR
- Type 42 (limited support)

## documentation

FreeType-2.4.8 API Reference

FreeType Glyph Conventions

The design of FreeType 2

### Important functions

FT_Init_FreeType
  initiates a freetype library object
FT_Done_FreeType
  uninitiates a freetype library object
FT_New_Face
  loads a font face into a freetype library object
FT_Done_Face
  unloads a font face from a freetype library object
FT_Load_Char
  loads a character

## Memory usage

mdefont has both face and glyph cashes. The glyph cache resides in its entire inside mdefont. The font cache however lets freetype store the actual face data. The size of the face is dependent on the font. Freetype allocates its own memory, by using a memory allocation object storing function pointers to alloc, free and realloc. Freetype is not memory safe.

## Implementation details

The core of freetype is the FT_Library instance, which is created using FT_Init_Freetype. This instance is then used as a handle to virtually all freetype functions. It embeds a memory manager and a scan-line converter object.

As mentioned, freetype uses its own memory manager. It holds function pointers to user-specified allocation and deallocation methods. Since freetype does not use constructors, and thus cannot initialize allocated objects freetype has a version of its allocator that zero:s the memory after allocation.

Freetype supports many different formats. In order to get a unified interface, function pointers are relied on heavily. There is a struct called FT_Driver that holds all the function pointers needed to manipulate a font face. This makes debugging hard. When a face is loaded, all information about the face is stored in the resulting FT_Face struct. No glyphs are loaded, but freetpye will automatically create a glyph slot. A call to FT_Load_Char will load the requested char to this slot.