Skip to content

Fonts

The data structure which actually contains the font information has changed significantly since previous releases; it now attempts to hide the actual storage format for the data from the application, providing accessor functions to get at the data. This allows a range of internal details for different font sources. The structure is split into two pieces, so that ListFontsWithInfo can share information from the font when it has been loaded. The FontInfo structure, then, contains only information germane to LFWI.

typedef struct _FontInfo {
    unsigned short firstCol;            /* range of glyphs for this font */
    unsigned short lastCol;
    unsigned short firstRow;
    unsigned short lastRow;
    unsigned short defaultCh;           /* default character index */
    unsigned int noOverlap:1;           /* no combination of glyphs overlap */
    unsigned int terminalFont:1;        /* Character cell font */
    unsigned int constantMetrics:1;     /* all metrics are the same */
    unsigned int constantWidth:1;       /* all character widths are the same*/
    unsigned int inkInside:1;           /* all ink inside character cell */
    unsigned int inkMetrics:1;          /* font has ink metrics */
    unsigned int allExist:1;            /* no missing chars in range */
    unsigned int drawDirection:2;       /* left-to-right/right-to-left*/
    unsigned int cachable:1;            /* font needn't be opened each time*/
    unsigned int anamorphic:1;          /* font is strangely scaled */
    short       maxOverlap;             /* maximum overlap amount */
    short       pad;                    /* unused */
    xCharInfo   maxbounds;              /* glyph metrics maximums */
    xCharInfo   minbounds;              /* glyph metrics minimums */
    xCharInfo   ink_maxbounds;          /* ink metrics maximums */
    xCharInfo   ink_minbounds;          /* ink metrics minimums */
    short       fontAscent;             /* font ascent amount */
    short       fontDescent;            /* font descent amount */
    int         nprops;                 /* number of font properties */
    FontPropPtr props;                  /* font properties */
    char       *isStringProp;           /* boolean array */
}           FontInfoRec, *FontInfoPtr;
typedef struct _FontInfo {
    unsigned short firstCol;            /* range of glyphs for this font */
    unsigned short lastCol;
    unsigned short firstRow;
    unsigned short lastRow;
    unsigned short defaultCh;           /* default character index */
    unsigned int noOverlap:1;           /* no combination of glyphs overlap */
    unsigned int terminalFont:1;        /* Character cell font */
    unsigned int constantMetrics:1;     /* all metrics are the same */
    unsigned int constantWidth:1;       /* all character widths are the same*/
    unsigned int inkInside:1;           /* all ink inside character cell */
    unsigned int inkMetrics:1;          /* font has ink metrics */
    unsigned int allExist:1;            /* no missing chars in range */
    unsigned int drawDirection:2;       /* left-to-right/right-to-left*/
    unsigned int cachable:1;            /* font needn't be opened each time*/
    unsigned int anamorphic:1;          /* font is strangely scaled */
    short       maxOverlap;             /* maximum overlap amount */
    short       pad;                    /* unused */
    xCharInfo   maxbounds;              /* glyph metrics maximums */
    xCharInfo   minbounds;              /* glyph metrics minimums */
    xCharInfo   ink_maxbounds;          /* ink metrics maximums */
    xCharInfo   ink_minbounds;          /* ink metrics minimums */
    short       fontAscent;             /* font ascent amount */
    short       fontDescent;            /* font descent amount */
    int         nprops;                 /* number of font properties */
    FontPropPtr props;                  /* font properties */
    char       *isStringProp;           /* boolean array */
}           FontInfoRec, *FontInfoPtr;

The font structure, then, contains a font info record, the format of the bits in each bitmap and the functions which access the font records (which are stored in an opaque format hung off of fontPrivate).

typedef struct _Font {
    int         refcnt;
    FontInfoRec info;
    char        bit;                    /* bit order: LSBFirst/MSBFirst */
    char        byte;                   /* byte order: LSBFirst/MSBFirst */
    char        glyph;                  /* glyph pad: 1, 2, 4 or 8 */
    char        scan;                   /* glyph scan unit: 1, 2 or 4 */
    fsBitmapFormat format;              /* FS-style format (packed) */
    int         (*get_glyphs)  ( /* font, count, chars, encoding, count, glyphs */ );
    int         (*get_metrics) ( /* font, count, chars, encoding, count, glyphs */ );
    int         (*get_bitmaps) ( /* client, font, flags, format,
                                    flags, nranges, ranges, data_sizep,
                                    num_glyphsp, offsetsp, glyph_datap,
                                    free_datap */ );
    int         (*get_extents) ( /* client, font, flags, nranges,
                                    ranges, nextentsp, extentsp */);
    void        (*unload_font) ( /* font */ );
    FontPathElementPtr fpe;             /* FPE associated with this font */
    pointer     svrPrivate;             /* X/FS private data */
    pointer     fontPrivate;            /* private to font */
    pointer     fpePrivate;             /* private to FPE */
    int         maxPrivate;             /* devPrivates (see below) */
    pointer     *devPrivates;           /*  ... */
}           FontRec, *FontPtr;
typedef struct _Font {
    int         refcnt;
    FontInfoRec info;
    char        bit;                    /* bit order: LSBFirst/MSBFirst */
    char        byte;                   /* byte order: LSBFirst/MSBFirst */
    char        glyph;                  /* glyph pad: 1, 2, 4 or 8 */
    char        scan;                   /* glyph scan unit: 1, 2 or 4 */
    fsBitmapFormat format;              /* FS-style format (packed) */
    int         (*get_glyphs)  ( /* font, count, chars, encoding, count, glyphs */ );
    int         (*get_metrics) ( /* font, count, chars, encoding, count, glyphs */ );
    int         (*get_bitmaps) ( /* client, font, flags, format,
                                    flags, nranges, ranges, data_sizep,
                                    num_glyphsp, offsetsp, glyph_datap,
                                    free_datap */ );
    int         (*get_extents) ( /* client, font, flags, nranges,
                                    ranges, nextentsp, extentsp */);
    void        (*unload_font) ( /* font */ );
    FontPathElementPtr fpe;             /* FPE associated with this font */
    pointer     svrPrivate;             /* X/FS private data */
    pointer     fontPrivate;            /* private to font */
    pointer     fpePrivate;             /* private to FPE */
    int         maxPrivate;             /* devPrivates (see below) */
    pointer     *devPrivates;           /*  ... */
}           FontRec, *FontPtr;

Yes, there are several different private pointers in the Font structure; they were added haphazardly until the devPrivate pointers were added. Future releases may remove some (or all) of the specific pointers, leaving only the devPrivatesmechanism.

There are two similar interfaces implemented - get_glyphs/get_metrics and get_bitmaps/get_extents. Too little time caused the font-server specific interfaces to be placed in the font library (and portions duplicated in each renderer) instead of having them integrated into the font server itself. This may change. The X server uses only get_glyphs/get_metrics, and those will not change dramatically. Each of the routines is described below.

(*get_glyphs)

This routine returns CharInfoPtrs for each of the requested characters in the font. If the character does not exist in the font, the default character will be returned, unless no default character exists in which case that character is skipped. Thus, the number of glyphs returned will not always be the same as the number of characters passed in.

(*get_metrics)

This is similar to (*get_glyphs) except that pointers to xCharInfo structures are returned, and, if the font has ink metrics, those are returned instead of the bitmap metrics.

(*get_bitmaps)

This packs the glyph image data in the requested format and returns it. The ranges/nranges argument specify the set of glyphs from the font to pack together.

(*get_extents)

This returns the metrics for the specified font from the specified ranges.

(*unload_font)

This is called from the FPE routine (*close_font), and so should not ever be called from the application.

maxPrivate

When initializing a new font structure, maxPrivate should be set to -1 so that the FontSetPrivate() macro works properly with an index of 0. Initializing maxPrivate to 0 can cause problems if the server tries to set something at index 0.