IntroductionThis is the second section of the FreeType 2 tutorial. It describes how to
1. Glyph metricsGlyph metrics are, as their name suggests, certain distances associated with each glyph in order to describe how to use it to layout text. There are usually two sets of metrics for a single glyph: Those used to layout the glyph in horizontal text layouts (Latin, Cyrillic, Arabic, Hebrew, etc.), and those used to layout the glyph in vertical text layouts (Chinese, Japanese, Korean, etc.). Note that only a few font formats provide vertical metrics. You can test whether a given face object contains them by using the macro FT_HAS_VERTICAL, which is true when appropriate. Individual glyph metrics can be accessed by first loading the glyph in a face's glyph slot, then accessing them through the face->glyph->metrics structure, whose type is FT_Glyph_Metrics. We will discuss this in more detail below; for now, we only note that it contains the following fields:
NOTE: As not all fonts do contain vertical metrics, the values of vertBearingX, vertBearingY and vertAdvance should not be considered reliable when FT_HAS_VERTICAL is false. The following graphics illustrate the metrics more clearly. First, for horizontal metrics, where the baseline is the horizontal axis: ![]() For vertical text layouts, the baseline is vertical, identical to the vertical axis: ![]() The metrics found in face->glyph->metrics are normally expressed in 26.6 pixel format (i.e., 1/64th of pixels), unless you use the FT_LOAD_NO_SCALE flag when calling FT_Load_Glyph or FT_Load_Char. In this case, the metrics will be expressed in original font units. The glyph slot object has also a few other interesting fields that will ease a developer's work. You can access them through face->glyph->xxx, where xxx is one of the following fields:
2. Managing glyph imagesThe glyph image that is loaded in a glyph slot can be converted into a bitmap, either by using FT_LOAD_RENDER when loading it, or by calling FT_Render_Glyph. Each time you load a new glyph image, the previous one is erased from the glyph slot. There are situations, however, where you may need to extract this image from the glyph slot in order to cache it within your application, and even perform additional transformations and measures on it before converting it to a bitmap. The FreeType 2 API has a specific extension which is capable of dealing with glyph images in a flexible and generic way. To use it, you first need to include the FT_GLYPH_H header file, as in:
#include FT_GLYPH_H
We will now explain how to use the functions defined in this file: a. Extracting the glyph image:You can extract a single glyph image very easily. Here some code that shows how to do it:
FT_Glyph glyph; /* a handle to the glyph image */
...
error = FT_Load_Glyph( face, glyph_index, FT_LOAD_NORMAL );
if ( error ) { ... }
error = FT_Get_Glyph( face->glyph, &glyph );
if ( error ) { ... }
As you see, we have: |