Xft (3) Linux Manual Page
Xft – X FreeType interface library
Description
Xft is a simple library designed to interface the FreeType rasterizer with the X Rendering Extension. This manual page barely scratches the surface of this library.
Header File
#include <X11/Xft/Xft.h>
Constants
XFT_MAJOR- is the major version number of
Xft. XFT_MINOR- is the minor version number of
Xft. XFT_REVISION- is the revision number of
Xft. XFT_VERSION- is
XFT_MAJORtimes 10000 (ten thousand), plusXFT_MINORtimes 100, plusXFT_REVISION. XftVersion- is an alias for
XFT_VERSION.
The following example illustrates how Xft‘s version constants might be used:
#if (XFT_VERSION >= 20107)
(void) puts("Version 2.1.7 or later of the Xft library is in"
" use.");
#else
(void) printf("Insufficient version of Xft (%d.%d.%d) installed;
" need at least version 2.1.7.
", XFT_MAJOR,
XFT_MINOR,
XFT_REVISION);
#endif
Data Types
XftFont-
typedef struct _XftFont { int ascent; int descent; int height; int max_advance_width; FcCharSet *charset; FcPattern *pattern; } XftFont;An
XftFontis the primary data structure of interest to programmers usingXft; it contains general font metrics and pointers to the Fontconfig character set and pattern associated with the font. TheFcCharSetandFcPatterndata types are defined by the Fontconfig library.XftFonts are populated with any ofXftFontOpen(),XftFontOpenName(),XftFontOpenXlfd(),XftFontOpenInfo(), orXftFontOpenPattern().XftFontCopy() is used to duplicateXftFonts, andXftFontClose() is used to mark anXftFontas unused.XftFonts are internally allocated, reference-counted, and freed byXft; the programmer does not ordinarily need to allocate or free storage for them.XftDrawGlyphs(), theXftDrawString*() family,XftDrawCharSpec(), andXftDrawGlyphSpec() useXftFonts to render text to anXftDrawobject, which may correspond to either a core X drawable or an X Rendering Extension drawable.XftGlyphExtents() and theXftTextExtents*() family are used to determine the extents (maximum dimensions) of anXftFont.- An
XftFont‘s glyph or character coverage can be determined withXftFontCheckGlyph() orXftCharExists().XftCharIndex() returns theXftFont-specific character index corresponding to a given Unicode codepoint.XftGlyphRender(),XftGlyphSpecRender(),XftCharSpecRender(), and theXftTextRender*() family useXftFonts to draw into X Rendering ExtensionPicturestructures.Note:XftDrawGlyphs(), theXftDrawString*() family,XftDrawCharSpec(), andXftDrawGlyphSpec() provide a means of rendering fonts that is independent of the availability of the X Rendering Extension on the X server. XftFontInfo- is an opaque object that stores information about a font.
XftFontInfostructures are created withXftFontInfoCreate(), freed withXftFontInfoDestroy(), and compared withXftFontInfoEqual().XftFontInfoobjects are internally allocated and freed byXft; the programmer does not ordinarily need to allocate or free storage for them.- Each
XftFontInfostructure in use is associated with a unique identifier, which can be retrieved withXftFontInfoHash(). AnXftFontcan be opened based onXftFontInfodata withXftFontOpenInfo(). - Each
XftColor-
typedef struct _XftColor { unsigned long pixel; XRenderColor color; } XftColor;An
XftColorobject permits text and other items to be rendered in a particular color (or the closest approximation offered by the X visual in use). TheXRenderColordata type is defined by the X Render Extension library.XftColorAllocName() andXftColorAllocValue() request a color allocation from the X server (if necessary) and initialize the members ofXftColor.XftColorFree() instructs the X server to free the color currently allocated for anXftColor.- One an
XftColorhas been initialized,XftDrawSrcPicture(),XftDrawGlyphs(), theXftDrawString*() family,XftDrawCharSpec(),XftDrawCharFontSpec(),XftDrawGlyphSpec(),XftDrawGlyphFontSpec(), andXftDrawRect() may be used to draw various objects using it. XftDraw- is an opaque object which holds information used to render to an X drawable using either the core protocol or the X Rendering extension.
XftDrawobjects are created with any ofXftDrawCreate() (which associates anXftDrawwith an existing X drawable),XftDrawCreateBitmap(), orXftDrawCreateAlpha(), and destroyed withXftDrawDestroy(). The X drawable associated with anXftDrawcan be changed withXftDrawChange().XftDraws are internally allocated and freed byXft; the programmer does not ordinarily need to allocate or free storage for them.- The X
Display,Drawable,Colormap, andVisualof anXftDrawcan be queried withXftDrawDisplay(),XftDrawDrawable(),XftDrawColormap(), andXftDrawVisual(), respectively. The X Rendering ExtensionPictureassociated with anXftDrawis returned byXftDrawPicture(). XftCharSpec-
typedef struct _XftCharSpec { FcChar32 ucs4; short x; short y; } XftCharSpec;- The
FcChar32data type is defined by the Fontconfig library. - The
XftCharFontSpec-
typedef struct _XftCharFontSpec { XftFont *font; FcChar32 ucs4; short x; short y; } XftCharFontSpec;- The
FcChar32data type is defined by the Fontconfig library. - The
XftGlyphSpec-
typedef struct _XftGlyphSpec { FT_UInt glyph; short x; short y; } XftGlyphSpec;- The
FT_UIntdata type is defined by the FreeType library. - The
XftGlyphFontSpec-
typedef struct _XftGlyphFontSpec { XftFont *font; FT_UInt glyph; short x; short y; } XftGlyphFontSpec;- The
FT_UIntdata type is defined by the FreeType library. - The
Functions
Opening and Matching Fonts
XftFont *XftFontOpen (Display *dpy,intscreen,...);
XftFontOpen takes a list of pattern element triples of the form field, type, value (terminated with a NULL), matches that pattern against the available fonts, and opens the matching font, sizing it correctly for screen number screen on display dpy. The Display data type is defined by the X11 library. Returns NULL if no match is found.
Example:
font = XftFontOpen (dpy, screen, XFT_FAMILY, XftTypeString, "charter", XFT_SIZE, XftTypeDouble, 12.0, NULL);
This opens the “charter” font at 12 points. The point size is automatically converted to the correct pixel size based on the resolution of the monitor.
XftFont *XftFontOpenName (Display *dpy,intscreen,unsigned char *name);
XftFontOpenName behaves as XftFontOpen does, except that it takes a Fontconfig pattern string (which is passed to the Fontconfig library’s FcNameParse() function).
XftFont *XftFontOpenXlfd (Display *dpy,intscreen,unsigned char *xlfd)
XftFontOpenXlfd behaves as XftFontOpen does, except that it takes a string containing an X Logical Font Description (XLFD).
FcPattern *XftFontMatch (Display *dpy,intscreen,FcPattern *pattern,FcResult *result);
Also used internally by the XftFontOpen* functions, XftFontMatch can also be used directly to determine the Fontconfig font pattern resulting from an Xft font open request. The FcPattern and FcResult data types are defined by the Fontconfig library.
Determining the Pixel Extents of a Text String
voidXftTextExtents8 (Display *dpy,XftFont *font,FcChar8 *string,intlen,XGlyphInfo *extents);
XftTextExtents8 computes the pixel extents on display dpy of no more than len glyphs of a string consisting of eight-bit characters when drawn with font, storing them in extents. The FcChar8 data type is defined by the Fontconfig library, and the XGlyphInfo data type is defined by the X Rendering Extension library.
voidXftTextExtents16 (Display *dpy,XftFont *font,FcChar16 *string,intlen,XGlyphInfo *extents);
XftTextExtents16 computes the pixel extents on display dpy of no more than len glyphs of a string consisting of sixteen-bit characters when drawn with font, storing them in extents. The FcChar16 data type is defined by the Fontconfig library, and the XGlyphInfo data type is defined by the X Rendering Extension library.
voidXftTextExtents32 (Display *dpy,XftFont *font,FcChar32 *string,intlen,XGlyphInfo *extents);
XftTextExtents32 computes the pixel extents on display dpy of no more than len glyphs of a string consisting of thirty-two-bit characters when drawn with font, storing them in extents. The FcChar32 data type is defined by the Fontconfig library, and the XGlyphInfo data type is defined by the X Rendering Extension library.
voidXftTextExtentsUtf8 (Display *dpy,XftFont *font,FcChar8 *string,intlen,XGlyphInfo *extents);
XftTextExtentsUtf8 computes the pixel extents on display dpy of no more than len bytes of a UTF-8 encoded string when drawn with font, storing them in extents. The XGlyphInfo data type is defined by the X Rendering Extension library.
voidXftTextExtentsUtf16 (Display *dpy,XftFont *font,FcChar8 *string,FcEndianendian,intlen,XGlyphInfo *extents);
XftTextExtentsUtf16 computes the pixel extents on display dpy of no more than len bytes of a UTF-16LE- or UTF-16BE-encoded string when drawn with font, storing them in extents. The endianness of string must be specified in endian. The FcEndian data type is defined by the Fontconfig library, and the XGlyphInfo data type is defined by the X Rendering Extension library.
voidXftGlyphExtents (Display *dpy,XftFont *font,FT_UInt *glyphs,intnglyphs,XGlyphInfo *extents);
Also used internally by the XftTextExtents* functions, XftGlyphExtents computes the pixel extents on display dpy of no more than nglyphs in the array glyphs drawn with font, storing them in extents. The FT_UInt data type is defined by the FreeType library, and the XGlyphInfo data type is defined by the X Rendering Extension library.
Drawing Strings (and Other Things)
XftDraw *XftDrawCreate (Display *dpy,Drawabledrawable,Visual *visual,Colormapcolormap);
XftDrawCreate creates a structure that can be used to render text and rectangles using the specified drawable, visual, and colormap on display. The Drawable, Visual, and Colormap data types are defined by the X11 library.
XftDraw *XftDrawCreateBitmap (Display *dpy,Pixmapbitmap);
XftDrawCreateBitmap behaves as XftDrawCreate, except it uses an X pixmap of color depth 1 instead of an X drawable. The Pixmap data type is defined by the X11 library.
XftDraw *XftDrawCreateAlpha (Display *dpy,Pixmappixmap,intdepth);
XftDrawCreateAlpha behaves as XftDrawCreate, except it uses an X pixmap of color depth depth instead of an X drawable. The Pixmap data type is defined by the X11 library.
voidXftDrawChange (XftDraw *draw,Drawabledrawable);
XftDrawChange changes the X drawable association of the existing Xft draw object draw from its current value to drawable.
Display *XftDrawDisplay (XftDraw *draw);
XftDrawDisplay returns a pointer to the display associated with the Xft draw object draw.
DrawableXftDrawDrawable (XftDraw *draw);
XftDrawDrawable returns the X drawable associated with the Xft draw object draw.
ColormapXftDrawColormap (XftDraw *draw);
XftDrawColormap returns the colormap associatied with the Xft draw object draw.
Visual *XftDrawVisual (XftDraw *draw);
XftDrawVisual returns a pointer to the visual associated with the Xft draw object draw.
PictureXftDrawPicture (XftDraw *draw);
XftDrawPicture returns the picture associated with the Xft draw object draw. If the the X server does not support the X Rendering Extension, 0 is returned.
PictureXftDrawSrcPicture (XftDraw *draw,XftColor *color);
This function is never called if the X server doesn’t support the X Rendering Extension; instead, XftGlyphCore is used.
voidXftDrawDestroy (XftDraw *draw);
XftDrawDestroy destroys draw (created by one of the XftCreate functions) and frees the memory that was allocated for it.
voidXftDrawString8 (XftDraw *d,XftColor *color,XftFont *font,intx,inty,unsigned char *string,intlen);
XftDrawString8 draws no more than len glyphs of string to Xft drawable d using font in color at position x, y.
voidXftDrawRect (XftDraw *d,XftColor *color,intx,inty,unsigned intwidth,unsigned intheight);
XftDrawRect draws a solid rectangle of the specified color, width, and height at position x, y to Xft drawable d.
Compatibility
As of version 2, Xft has become relatively stable and is expected to retain source and binary compatibility in future releases.
Xft does provide a compatibility interface to its previous major version, Xft 1.x, described below.
Xft 1.x Compatibility Header File
#include <X11/Xft/XftCompat.h>
Xft 1.x Compatibility Data Types
XftPattern- holds a set of names with associated value lists; each name refers to a property of a font.
XftPatterns are used as inputs to the matching code as well as holding information about specific fonts. XftFontSet- contains a list of
XftPatterns. Internally,Xftuses this data structure to hold sets of fonts. Externally,Xftreturns the results of listing fonts in this format. XftObjectSet- holds a set of names and is used to specify which fields from fonts are placed in the the list of returned patterns when listing fonts.
Author
Keith Packard
See Also
Fontconfig Developers Reference
FreeType API Reference
Xlib – C Language Interface
