共用方式為


glyf — Glyph Data (OpenType 1.8.1)

This table contains information that describes the glyphs in the font in the TrueType outline format. Information regarding the rasterizer (scaler) refers to the TrueType rasterizer.

Each glyph begins with the following header:

Type Name Description
int16 numberOfContours If the number of contours is greater than or equal to zero, this is a single glyph; if negative, this is a composite glyph.
int16 xMin Minimum x for coordinate data.
int16 yMin Minimum y for coordinate data.
int16 xMax Maximum x for coordinate data.
int16 yMax Maximum y for coordinate data.

Note that the bounding rectangle from each character is defined as the rectangle with a lower left corner of (xMin, yMin) and an upper right corner of (xMax, yMax).

Note: The scaler will perform better if the glyph coordinates have been created such that the xMin is equal to the lsb. For example, if the lsb is 123, then xMin for the glyph should be 123. If the lsb is -12 then the xMin should be -12. If the lsb is 0 then xMin is 0. If all glyphs are done like this, set bit 1 of flags field in the 'head' table.

Simple Glyph Description

This is the table information needed if numberOfContours is greater than zero, that is, a glyph is not a composite.

Type Name Description
uint16 endPtsOfContours[n] Array of last points of each contour; n is the number of contours.
uint16 instructionLength Total number of bytes for instructions.
uint8 instructions[n] Array of instructions for each glyph; n is the number of instructions.
uint8 flags[n] Array of flags for each coordinate in outline; n is the number of flags.
uint8 or int16 xCoordinates[ ] First coordinates relative to (0,0); others are relative to previous point.
uint8 or int16 yCoordinates[ ] First coordinates relative to (0,0); others are relative to previous point.

Note: In the glyf table, the position of a point is not stored in absolute terms but as a vector relative to the previous point. The delta-x and delta-y vectors represent these (often small) changes in position.

Each flag is a single bit. Their meanings are shown below.

Flags Bit Description
On Curve 0 If set, the point is on the curve; otherwise, it is off the curve.
x-Short Vector 1 If set, the corresponding x-coordinate is 1 unsigned byte (uint8). If not set, it is a 16-bit signed value (int16).
y-Short Vector 2 If set, the corresponding y-coordinate is 1 unsigned byte (uint8). If not set, it is 16-bit signed value (int16).
Repeat 3 If set, the next byte (read as unsigned) specifies the number of additional times this set of flags is to be repeated. In this way, the number of flags listed can be smaller than the number of points in a character.
This x is same
(Positive x-Short Vector)
4 This flag has two meanings, depending on how the x-Short Vector flag is set. If x-Short Vector is set, this bit describes the sign of the value, with 1 equalling positive and 0 negative. If the x-Short Vector bit is not set and this bit is set, then the current x-coordinate is the same as the previous x-coordinate. If the x-Short Vector bit is not set and this bit is also not set, the current x-coordinate is a signed 16-bit delta vector.
This y is same
(Positive y-Short Vector)
5 This flag has two meanings, depending on how the y-Short Vector flag is set. If y-Short Vector is set, this bit describes the sign of the value, with 1 equalling positive and 0 negative. If the y-Short Vector bit is not set and this bit is set, then the current y-coordinate is the same as the previous y-coordinate. If the y-Short Vector bit is not set and this bit is also not set, the current y-coordinate is a signed 16-bit delta vector.
Reserved 6 This bit is reserved. Set it to zero.
Reserved 7 This bit is reserved. Set it to zero.

Composite Glyph Description

This is the table information needed for composite glyphs (numberOfContours is -1). A composite glyph starts with two uint16 values (“flags” and “glyphIndex,” i.e. the index of the first contour in this composite glyph); the data then varies according to “flags”).

Type Name Description
uint16 flags component flag
uint16 glyphIndex glyph index of component
uint8, int8, uint16 or int16 argument1 x-offset for component or point number; type depends on bits 0 and 1 in component flags
uint8, int8, uint16 or int16 argument2 y-offset for component or point number; type depends on bits 0 and 1 in component flags
Transformation Option

The C pseudo-code fragment below shows how the composite glyph information is stored and parsed; definitions for “flags” bits follow this fragment:

do {
    uint16 flags;
    uint16 glyphIndex;
    if ( flags & ARG_1_AND_2_ARE_WORDS) {
    (int16 or FWord) argument1;
    (int16 or FWord) argument2;
    } else {
        uint16 arg1and2; /* (arg1 << 8) | arg2 */
    }
    if ( flags & WE_HAVE_A_SCALE ) {
        F2Dot14  scale;    /* Format 2.14 */
    } else if ( flags & WE_HAVE_AN_X_AND_Y_SCALE ) {
        F2Dot14  xscale;    /* Format 2.14 */
        F2Dot14  yscale;    /* Format 2.14 */
    } else if ( flags & WE_HAVE_A_TWO_BY_TWO ) {
        F2Dot14  xscale;    /* Format 2.14 */
        F2Dot14  scale01;   /* Format 2.14 */
        F2Dot14  scale10;   /* Format 2.14 */
        F2Dot14  yscale;    /* Format 2.14 */
    }
} while ( flags & MORE_COMPONENTS ) 
if (flags & WE_HAVE_INSTR){
    uint16 numInstr
    uint8 instr[numInstr]

Argument1 and argument2 can be either x and y offsets to be added to the glyph or two point numbers. In the latter case, the first point number indicates the point that is to be matched to the new glyph. The second number indicates the new glyph’s “matched” point. Once a glyph is added, its point numbers begin directly after the last glyphs (endpoint of first glyph + 1).

When arguments 1 and 2 are an x and a y offset instead of points and the bit ROUND_XY_TO_GRID is set to 1, the values are rounded to those of the closest grid lines before they are added to the glyph. X and Y offsets are described in FUnits.

If the bit WE_HAVE_A_SCALE is set, the scale value is read in 2.14 format-the value can be between -2 to almost +2. The glyph will be scaled by this value before grid-fitting.

The bit WE_HAVE_A_TWO_BY_TWO allows for linear transformation of the X and Y coordinates by specifying a 2 × 2 matrix. This could be used for scaling and 90-degree rotations of the glyph components, for example.

These are the constants for the flags field:

Flags Bit Description
ARG_1_AND_2_ARE_WORDS 0 If this is set, the arguments are 16-bit (uint16 or int16); otherwise, they are bytes (uint8 or int8).
ARGS_ARE_XY_VALUES 1 If this is set, the arguments are signed xy values; otherwise, they are unsigned point numbers.
ROUND_XY_TO_GRID 2 For the xy values if the preceding is true.
WE_HAVE_A_SCALE 3 This indicates that there is a simple scale for the component. Otherwise, scale = 1.0.
RESERVED 4 This bit is reserved. Set it to 0.
MORE_COMPONENTS 5 Indicates at least one more glyph after this one.
WE_HAVE_AN_X_AND_Y_SCALE 6 The x direction will use a different scale from the y direction.
WE_HAVE_A_TWO_BY_TWO 7 There is a 2 by 2 transformation that will be used to scale the component.
WE_HAVE_INSTRUCTIONS 8 Following the last component are instructions for the composite character.
USE_MY_METRICS 9 If set, this forces the aw and lsb (and rsb) for the composite to be equal to those from this original glyph. This works for hinted and unhinted characters.
OVERLAP_COMPOUND 10 If set, the components of the compound glyph overlap. Use of this flag is not required in OpenType — that is, it is valid to have components overlap without having this flag set. It may affect behaviors in some platforms, however. (See Apple’s specification for details regarding behavior in Apple platforms.)
SCALED_COMPONENT_OFFSET 11 The composite is designed to have the component offset scaled.
UNSCALED_COMPONENT_OFFSET 12 The composite is designed not to have the component offset scaled.

The purpose of USE_MY_METRICS is to force the lsb and rsb to take on a desired value. For example, an i-circumflex (U+00EF) is often composed of the circumflex and a dotless-i. In order to force the composite to have the same metrics as the dotless-i, set USE_MY_METRICS for the dotless-i component of the composite. Without this bit, the rsb and lsb would be calculated from the hmtx entry for the composite (or would need to be explicitly set with TrueType instructions).

Note that the behavior of the USE_MY_METRICS operation is undefined for rotated composite components.