Next: , Previous: FONTLIB overview, Up: FONTLIB



9.2 FONTLIB programmers usage

All symbols defined by FONTLIB have the font_ prefix. Before the first use of FONTLIB, the font_init function must be called. On the other hand, the cleanup is done by the font_finish function.

FONTLIB provides a powerful font server which caches the loaded fonts. Every font loaded into the fontserver gets a unique integer identification number, called the font ID or also the font descriptor. A zero or negative font ID is considered invalid. A font file can be loaded via the font_load_file function. The font server keeps track of loaded fonts and does not load twice the same file into the memory. Caching is managed by the FreeType library. That means that if the memory is low or there are many fonts loaded, only the recently used fonts are present in memory. The others are “swapped” and opened on demand.

Most of the communication with rendering routines, bounding box computing and other functions is done via the struct font_ctl structure, which is passed as an argument. Here you specify the font ID, font size (measured in millimeters), transformation, etc. Do not forget that this structure has to be properly initialized and also cleaned up by the font_ctl_init and font_ctl_cleanup functions.

The actual rendering of one glyph and a whole string is done by the functions font_render_glyph and font_render_string, respectively. These functions perform some computation, then call FreeType to do the low-level glyph rendering and return the resulting bitmap.

To compute the bounding box (in millimeters) of a given glyph or string, there are the font_get_glyph_bbox and font_get_string_bbox functions. Again, they are controlled via the struct font_ctl structure.

The rest of the functions does not need any special comments, just look in the reference manual or font/font.h source. We just briefly sketch the functionality. There are routines returning various font information (font_info, font_t1_info, ...). Some font formats can be converted into some other (font_pfa_to_pfb, font_tt_to_type42, font_pfb_to_pfa), see Font conversions for details.

There is also the not yet fully implemented support for expanding fonts into the GEOMLIB curve representation (font_char_decompose). FONTLIB also includes a logic for finding the most similar font if the original one is not available (font_search). The FontConfig library is utilized here.