Xft(3)
π NAME π
Xft β the X FreeType interface library, bestie. (X Version 11, if you were wondering.)
β¨ DESCRIPTION β¨
Okay so Xft is a simple library that draws text and graphics. It does this by:
- using info provided by the Fontconfig library,
- converting font glyphs using the FreeType rasterizer, and
- displaying the converted font data using the X Rendering Extension.
This manual page barely scratches the surface of this library. π
π HEADER FILE π
#include <X11/Xft/Xft.h>
π CONSTANTS π
XFT_MAJORβ the major version number of Xft.XFT_MINORβ the minor version number of Xft.XFT_REVISIONβ the revision number of Xft.XFT_VERSIONβXFT_MAJORtimes 10000 (ten thousand), plusXFT_MINORtimes 100, plusXFT_REVISION.XftVersionβ an alias forXFT_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.\n", XFT_MAJOR,
XFT_MINOR,
XFT_REVISION);
#endif
π DATA TYPES π
Xft datatypes follow a naming convention, prefixing all names with βXftβ. (Cute, right? π)
π¦ From Xlib... π¦
Xlib datatypes do not follow a naming convention. They are documented in Xlib - C Language Interface.
Xft uses these names: Bool, Colormap, Display, Drawable, Pixmap, Region, Visual, and XRectangle.
Some datatypes are especially relevant to Xft:
Drawableβ declared in<X11/X.h>, this is an X resource ID, e.g., a window associated with a display. Both windows and pixmaps can be used as sources and destinations in graphics operations. These windows and pixmaps are collectively known as drawables. However, anInputOnlywindow cannot be used as a source or destination in a graphics operation.Regionβ declared in<X11/Xutil.h>and<X11/Xregion.h>, aRegionis an arbitrary set of pixel locations which Xlib can manipulate. Internally, aRegionis represented by the union of an arbitrary number of rectangles. Xlib maintains a rectangle which tells it the extent of this union.Visualβ declared in<X11/Xutil.h>, this structure contains information about the possible color mapping.
β¨ From XRender... β¨
The X Render Extension library datatypes are inspired by Xlib, but lack the corresponding documentation. Refer to the header file for details:
<X11/extensions/Xrender.h>
or read the source code (which provides an outline of libXrender).
Xft uses these names: Picture, XGlyphInfo, XRenderColor.
πΈ From Fontconfig... πΈ
Fontconfig datatypes follow a naming convention, prefixing all names with βFcβ which are documented in Fontconfig Developers Reference.
Xft uses these Fontconfig names: FcBool, FcChar8, FcChar16, FcChar32, FcCharSet, FcEndian, FcFontSet, FcPattern, and FcResult.
π§ From FreeType 2... π§
FreeType 2 datatypes follow a naming convention, prefixing all names with βFT_β which are documented in FreeType API Reference.
Xft uses these names: FT_Face, FT_Library, and FT_UInt.
FreeType 2 uses FT_UInt (an unsigned integer) to represent glyphs.
π XftFont π
typedef struct _XftFont {
int ascent;
int descent;
int height;
int max_advance_width;
FcCharSet *charset;
FcPattern *pattern;
} XftFont;
An XftFont is the primary data structure of interest to programmers using Xft; it contains general font metrics and pointers to the Fontconfig character set and pattern associated with the font.
XftFonts are populated with any of XftFontOpen(), XftFontOpenName(), XftFontOpenXlfd(), XftFontOpenInfo(), or XftFontOpenPattern(). XftFontCopy() is used to duplicate XftFonts, and XftFontClose() is used to mark an XftFont as unused. XftFonts are internally allocated, reference-counted, and freed by Xft; the programmer does not ordinarily need to allocate or free storage for them.
XftDrawGlyphs(), the XftDrawString*() family, XftDrawCharSpec(), and XftDrawGlyphSpec() use XftFonts to render text to an XftDraw object, which may correspond to either a core X drawable or an X Rendering Extension drawable.
XftGlyphExtents() and the XftTextExtents*() family are used to determine the extents (maximum dimensions) of an XftFont.
An XftFont's glyph or character coverage can be determined with XftFontCheckGlyph() or XftCharExists(). XftCharIndex() returns the XftFont-specific character index corresponding to a given Unicode codepoint.
XftGlyphRender(), XftGlyphSpecRender(), XftCharSpecRender(), and the XftTextRender*() family use XftFonts to draw into X Rendering Extension Picture structures.
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. XftFontInfo structures are created with XftFontInfoCreate(), freed with XftFontInfoDestroy(), and compared with XftFontInfoEqual(). XftFontInfo objects are internally allocated and freed by Xft; the programmer does not ordinarily need to allocate or free storage for them.
Each XftFontInfo structure in use is associated with a unique identifier, which can be retrieved with XftFontInfoHash(). An XftFont can be opened based on XftFontInfo data with XftFontOpenInfo().
π XftColor π
typedef struct _XftColor {
unsigned long pixel;
XRenderColor color;
} XftColor;
An XftColor object permits text and other items to be rendered in a particular color (or the closest approximation offered by the X visual in use).
XftColorAllocName() and XftColorAllocValue() request a color allocation from the X server (if necessary) and initialize the members of XftColor. XftColorFree() instructs the X server to free the color currently allocated for an XftColor.
Once an XftColor has been initialized, XftDrawSrcPicture(), XftDrawGlyphs(), the XftDrawString*() family, XftDrawCharSpec(), XftDrawCharFontSpec(), XftDrawGlyphSpec(), XftDrawGlyphFontSpec(), and XftDrawRect() 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.
XftDraw objects are created with any of XftDrawCreate() (which associates an XftDraw with an existing X drawable), XftDrawCreateBitmap(), or XftDrawCreateAlpha(), and destroyed with XftDrawDestroy(). The X drawable associated with an XftDraw can be changed with XftDrawChange(). XftDraw objects are internally allocated and freed by Xft; the programmer does not ordinarily need to allocate or free storage for them.
The X Display, Drawable, Colormap, and Visual properties of an XftDraw can be queried with XftDrawDisplay(), XftDrawDrawable(), XftDrawColormap(), and XftDrawVisual(), respectively.
Several functions use XftDraw objects: XftDrawCharFontSpec(), XftDrawCharSpec(), XftDrawGlyphFontSpec(), XftDrawGlyphSpec(), XftDrawGlyphs(), XftDrawRect(), XftDrawSetClip(), XftDrawSetClipRectangles(), XftDrawSetSubwindowMode(), and the XftDrawString*() family.
The X Rendering Extension Picture associated with an XftDraw is returned by XftDrawPicture(), and XftDrawSrcPicture(). It is used by XftCharFontSpecRender(), XftCharSpecRender(), XftGlyphFontSpecRender(), XftGlyphRender(), XftGlyphSpecRender(), and the XftTextRender*() family.
π¦ XftCharSpec π¦
typedef struct _XftCharSpec {
FcChar32 ucs4;
short x;
short y;
} XftCharSpec;
XftCharSpec is used by XftDrawCharSpec(), and XftCharSpecRender().
π XftCharFontSpec π
typedef struct _XftCharFontSpec {
XftFont *font;
FcChar32 ucs4;
short x;
short y;
} XftCharFontSpec;
XftCharFontSpec is used by XftCharFontSpecRender().
π XftGlyphSpec π
typedef struct _XftGlyphSpec {
FT_UInt glyph;
short x;
short y;
} XftGlyphSpec;
XftGlyphSpec is used by XftDrawGlyphSpec().
π« XftGlyphFontSpec π«
typedef struct _XftGlyphFontSpec {
XftFont *font;
FT_UInt glyph;
short x;
short y;
} XftGlyphFontSpec;
XftGlyphFontSpec is used by XftDrawGlyphFontSpec(), and XftGlyphFontSpecRender().
π₯ FUNCTIONS π₯
β¨ Initialization β¨
A typical application using Xft does not explicitly initialize the library. That is usually done as a side-effect of opening a font.
When Xft initializes, it collects information about the display, and stores some of that information in a Fontconfig pattern (essentially a collection of properties with typed values). The calling application can modify that pattern to change the library's behavior.
Not all of the collected information is stored in a pattern. The remainder is stored in internal data structures. Xft makes some of that available to the application via functions.
Bool XftDefaultHasRender (
Display *dpy);
Obtain information about the display dpy if not done already, and return true if Xft found that the display supports the X Render extension, and if it is able to find a suitable XRenderPictFormat (X Render's datatype which is analogous to Xlib's Visual) on the display.
Bool XftDefaultSet (
Display *dpy,
FcPattern *defaults);
Obtain information about the display dpy if not done already, and set the Fontconfig pattern holding default properties which Xft will use for this display.
Xft uses those properties initially to obtain these limits:
XFT_MAX_GLYPH_MEMORY(maxglyphmemory) β the max amount of glyph memory for all the fonts Xft is using (default:4*1024*1024).XFT_MAX_UNREF_FONTS(maxunreffonts) β the max number of unreferenced fonts (default:16).XFT_TRACK_MEM_USAGE(trackmemusage) β when true, Xft keeps tabs on how much glyph memory is actually in use, so it can make better decisions about what to unload when it hits the max glyph memory (default:false).
Xft also uses these default properties in XftDefaultSubstitute().
void XftDefaultSubstitute (
Display *dpy,
int screen,
FcPattern *pattern);
Xft fills in the missing properties in the pattern you hand it, using the default properties for the display dpy you named β like, the ones that were set in XftDefaultSet().
Your typical Xft app calls this to help Fontconfig pick a suitable font. π
And these properties get substituted before FcDefaultSubstitute() is called:
FC_ANTIALIASβ true if FreeType should use antialiasing (default:False). (default:True). yes bestie, both defaults are literally in there, we don't make the rules πFC_AUTOHINTβ true if FreeType should use autohinting (default:False).FC_DPIβ dots/inch used for resolution (default: computed from the display height).FC_EMBOLDENβ true ifFT_GlyphSlot_Embolden()should be used to embolden a font (default:False).FC_HINTINGβ true if hinting should be used when filling in properties to open a font (default:True).FC_HINT_STYLEβ the hinting style used when filling in properties to open a font (default:FC_HINT_FULL).FC_LCD_FILTERβ the parameter passed toFT_Library_SetLcdFilter()when loading glyphs (default:FC_LCD_DEFAULT).FC_MINSPACEβ the minimum space value used when filling in properties to open a font (default:False).FC_RGBAβ the RGBA value used when filling in properties to open a font (default: computed by callingXRenderQuerySubpixelOrder()).FC_SCALEβ the scale used in Fontconfig (default:1.0).XFT_MAX_GLYPH_MEMORYβ maximum memory for one font (default:1024*1024).XFT_RENDERβ true if the display supports the X Render extension (default: the result fromXftDefaultHasRender()).
FcBool XftInit (
_Xconst char *config);
Initializes the Fontconfig library (it calls FcInit()).
The config parameter is unused.
Xft does not deinitialize the Fontconfig library when it's done. no take-backs, no cleanup, it just leaves it there π«Ά
FcBool XftInitFtLibrary (void);
Initializes the FreeType library (it calls FT_Init_FreeType() to create a library object) β but only if it hasn't already been initialized. You need this done before you use the FreeType library to read font data out of a file.
Xft calls XftInitFtLibrary() internally, via XftFontInfoCreate() and XftFontOpenPattern().
Xft does not discard the library object when it's done (like, it never calls FT_Done_FreeType()). β¨
int XftGetVersion (void);
Returns XftVersion, which lets an app figure out the actual version of Xft that's in use. iconic for feature checks.
β¨ Opening and Matching Fonts β¨
XftFont *XftFontOpen (
Display *dpy,
int screen,
...);
XftFontOpen takes a list of pattern element triples β field, type, value, terminated with a NULL β matches that pattern against the fonts you actually have, and opens the matching font, sizing it correctly for screen number screen on display dpy. It returns the matched font, or NULL if nothing matches. π
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 gets converted to the correct pixel size automatically, based on the resolution of the monitor. math, but make it fashion.
XftFont *XftFontOpenName (
Display *dpy,
int screen,
_Xconst char *name);
XftFontOpenName behaves exactly like XftFontOpen does, except it takes a Fontconfig pattern string instead (and that string gets passed to the Fontconfig library's FcNameParse() function).
XftFont *XftFontOpenXlfd (
Display *dpy,
int screen,
_Xconst char *xlfd)
XftFontOpenXlfd behaves exactly like XftFontOpen does, except it takes a string containing an X Logical Font Description (XLFD), and it uses the XftXlfdParse() function.
FcPattern *XftFontMatch (
Display *dpy,
int screen,
_Xconst FcPattern *pattern,
FcResult *result);
Also used internally by the XftFontOpen* functions, XftFontMatch can be called directly too, to find out the Fontconfig font pattern that results from an Xft font open request. π
FcPattern *XftXlfdParse (
_Xconst char *xlfd_orig,
Bool ignore_scalable,
Bool complete);
XftXlfdParse parses the xlfd_orig parameter according to the X Logical Font Description Conventions document, but it ignores some of the fields: setwidth_name, add_style_name, spacing, and average_width.
XftXlfdParse creates a Fontconfig pattern, sets the property XFT_XLFD to the xlfd_orig value, and maps all the info it collected over to Fontconfig properties. Empty fields or "*" fields get ignored:
FC_FOUNDRYβ fromfoundry.FC_FAMILYβ fromfamily.FC_WEIGHTβweight_name, defaulting toFC_WEIGHT_MEDIUM.FC_SLANTβ fromslant, defaulting toFC_SLANT_ROMAN.FC_SIZEβ frompoint_size.FC_PIXEL_SIZEβ frompixel_size. Ifpoint_sizewas set, as well asresolution_xandresolution_y, then the value is scaled convert the font's height to points.
π Families of Functions π
Xft gives you groups of drawing functions that differ based on how the data is encoded β like, 8-bit (ISO-8859-1) versus UTF-8. Here's the whole lineup of these related functions:
- 8 β
XftDrawString8,XftTextExtents8,XftTextRender8 - 16 β
XftDrawString16,XftTextExtents16,XftTextRender16 - 16BE β
XftDrawString16,XftTextExtents16,XftTextRender16BE - 16LE β
XftDrawString16,XftTextExtents16,XftTextRender16LE - 32 β
XftDrawString32,XftTextExtents32,XftTextRender32 - 32BE β
XftDrawString32,XftTextExtents32,XftTextRender32BE - 32LE β
XftDrawString32,XftTextExtents32,XftTextRender32LE - UTF-8 β
XftDrawStringUtf8,XftTextExtentsUtf8,XftTextRenderUtf8 - UTF-16 β
XftDrawStringUtf16,XftTextExtentsUtf16,XftTextRenderUtf16
π Determining Text Extents π
Xft has several functions for figuring out how tall and how wide a text string needs to be to display. Once you account for the offset β for the cases where the string is going to be shifted up, down, left or right β those numbers are what we call text extents.
void XftTextExtents8 (
Display *dpy,
XftFont *font,
_Xconst FcChar8 *string,
int len,
XGlyphInfo *extents);
XftTextExtents8 computes the pixel extents on display dpy of no more than len glyphs of a string made of eight-bit characters, when drawn with font, and stores them in extents.
void XftTextExtents16 (
Display *dpy,
XftFont *font,
_Xconst FcChar16 *string,
int len,
XGlyphInfo *extents);
XftTextExtents16 computes the pixel extents on display dpy of no more than len glyphs of a string made of sixteen-bit characters, when drawn with font, and stores them in extents.
void XftTextExtents32 (
Display *dpy,
XftFont *font,
_Xconst FcChar32 *string,
int len,
XGlyphInfo *extents);
XftTextExtents32 computes the pixel extents on display dpy of no more than len glyphs of a string made of thirty-two-bit characters, when drawn with font, and stores them in extents.
void XftTextExtentsUtf8 (
Display *dpy,
XftFont *font,
_Xconst FcChar8 *string,
int len,
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, and stores them in extents. (bytes, not glyphs, bestie β that distinction is doing a lot of heavy lifting here π«Ά)
void XftTextExtentsUtf16 (
Display *dpy,
XftFont *font,
_Xconst FcChar8 *string,
FcEndian endian,
int len,
XGlyphInfo *extents);
okay so XftTextExtentsUtf16 is out here computing 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, and it stores them in extents. The endianness of string must be specified in endian. π
void XftGlyphExtents (
Display *dpy,
XftFont *font,
_Xconst FT_UInt *glyphs,
int nglyphs,
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. β¨
If any of the glyphs are missing (determined by a check with XftFontCheckGlyph()), the corresponding entry in extents is filled with zeroes. π
β¨ Managing XftColor β¨
Bool XftColorAllocName (
Display *dpy,
_Xconst Visual *visual,
Colormap cmap,
_Xconst char *name,
XftColor *result);
Use XAllocNamedColor() to look up the named color name for the screen associated with the colormap cmap. π¨
- If
XAllocNamedColor()returns nonzero,XftColorAllocName()fills in the resultingXftColorpixel field with the closest color supported by the screen, as well as the exact red, green and blue fields from the database, and returnsTrue. β - If
XAllocNamedColor()returns zero,XftColorAllocName()returnsFalse, and does not update theXftColorreferenced byresult. β
The visual parameter is unused. π
Bool XftColorAllocValue (
Display *dpy,
Visual *visual,
Colormap cmap,
_Xconst XRenderColor *color,
XftColor *result);
Allocate a color value: π
- If the visual class is
TrueColor,XftColorAllocValue()sets the pixel field in theXftColorreferenced byresultusing the red, green and blue fields from thecolorparameter. π - If the visual class is not
TrueColor,XftColorAllocValue()callsXAllocColor()to allocate an entry in the colormapcmap, which returns the pixel value of the color closest to the specified RGB elements supported by the hardware.
If XAllocColor() succeeds XftColorAllocValue() stores that pixel value in the XRenderColor referenced by result and returns True.
If XAllocColor() fails, XftColorAllocValue() returns False and does not modify the result. π
void XftColorFree (
Display *dpy,
Visual *visual,
Colormap cmap,
XftColor *color);
If the visual class is not TrueColor, Xft calls XFreeColors() to free the entry from the colormap cmap whose pixel value in the color parameter was allocated by XftColorAllocName(). π§Ή
β¨ Managing XftDraw β¨
XftDraw *XftDrawCreate (
Display *dpy,
Drawable drawable,
Visual *visual,
Colormap colormap);
XftDrawCreate creates a structure that can be used to render text and rectangles using the specified drawable, visual, and colormap on display. π¨
XftDraw *XftDrawCreateBitmap (
Display *dpy,
Pixmap bitmap);
XftDrawCreateBitmap behaves as XftDrawCreate(), except that it uses an X pixmap of color depth 1 instead of an X drawable. πΌοΈ
XftDraw * XftDrawCreateAlpha (
Display *dpy,
Pixmap pixmap,
int depth);
XftDrawCreateAlpha behaves as XftDrawCreate(), except that it uses an X pixmap of color depth depth instead of an X drawable. β¨
void XftDrawChange (
XftDraw *draw,
Drawable drawable);
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. π₯οΈ
Drawable XftDrawDrawable (
XftDraw *draw);
XftDrawDrawable returns the X drawable associated with the Xft draw object draw. ποΈ
Colormap XftDrawColormap (
XftDraw *draw);
XftDrawColormap() returns the colormap associated with the Xft draw object draw. π¨
Visual *XftDrawVisual (
XftDraw *draw);
XftDrawVisual returns a pointer to the visual associated with the Xft draw object draw. π
Picture XftDrawPicture (
XftDraw *draw);
XftDrawPicture returns the picture associated with the Xft draw object draw. πΌοΈ
If the X server does not support the X Rendering Extension, 0 is returned. π
Picture XftDrawSrcPicture (
XftDraw *draw,
_Xconst XftColor *color);
Return an X Render Picture object, which is used for rendering glyphs, e.g., with XftGlyphRender(), XftGlyphSpecRender(), or XftGlyphFontSpecRender(), by XftDrawGlyphs(), XftDrawGlyphSpec(), XftDrawGlyphFontSpec(), respectively. π¨
If the X server does not support the X Render extension, those functions use XftGlyphCore(), XftGlyphSpecCore(), or XftGlyphFontSpecCore(). π
void XftDrawDestroy (
XftDraw *draw);
XftDrawDestroy destroys draw (created by one of the XftDrawCreate*() functions) and frees the memory that was allocated for it. ποΈ
Bool XftDrawSetClip (
XftDraw *draw,
Region r);
Set up clipping for the given XftDraw parameter draw starting with a Region: βοΈ
- If the
Regionparameterris not null, Xft creates a newRegion(to copy the parameter), - Xft destroys any existing clipping region.
- Xft sets the
clip_typefor thedrawparameter toXftClipTypeRegionif therparameter was not null. Otherwise it sets theclip_typetoXftClipTypeNone. - Finally, Xft updates clipping for existing objects, updates the
clip_maskfor its X Render Picture object and sets the clipping-mask in the graphic context (GC) associated with theXftDrawparameter.
XftDrawSetClip() returns True if no change was necessary, or if the operation succeeded. It returns False if it was unable to create the new Region(). π
Bool XftDrawSetClipRectangles (
XftDraw *draw,
int xOrigin,
int yOrigin,
_Xconst XRectangle *rects,
int n);
Like XftDrawSetClip(), XftDrawSetClipRectangles() sets up clipping for the given XftDraw parameter draw but uses a set of n rectangles (the rects parameter) which could be used to construct a Region . π
Xft sets the clip_type for draw to XftClipTypeRectangles and uses XSetClipRectangles() for core (X11) clipping and XRenderSetPictureClipRectangles() for X Render clipping. π¨
void XftDrawSetSubwindowMode (
XftDraw *draw,
int mode);
Sets the subwindow-mode for the given XftDraw parameter draw. The mode can be either ClipByChildren (the default), or IncludeInferiors: πͺ
- For
ClipByChildren, both source and destination windows are additionally clipped by all viewableInputOutputchildren. - For
IncludeInferiors, neither source nor destination window is clipped by inferiors. This will result in including subwindow contents in the source and drawing through subwindow boundaries of the destination.
In addition to the subwindow-mode maintained by Xft, it updates the subwindow mode for any associated graphics context GC using XSetSubwindowMode() as well as for an X Render Picture using XRenderChangePicture(). π§
β¨ Drawing Strings β¨
void XftDrawString8 (
XftDraw *d,
_Xconst XftColor *color,
XftFont *font,
int x,
int y,
_Xconst FcChar8 *string,
int len);
XftDrawString8 draws no more than len glyphs of string to Xft drawable d using font in color at position x, y. βοΈ
β¨ Drawing Other Things β¨
void XftDrawRect (
XftDraw *d,
_Xconst XftColor *color,
int x,
int y,
unsigned int width,
unsigned int height);
XftDrawRect draws a solid rectangle of the specified color, width, and height at position x, y to Xft drawable d. π₯
void XftCharFontSpecRender (
Display *dpy,
int op,
Picture src,
Picture dst,
int srcx,
int srcy,
_Xconst XftCharFontSpec*chars,
int len);
XftCharFontSpecRender() converts the chars parameter from XftCharFontSpec to XftGlyphFontSpec, passing the converted array along with the other parameters unchanged to XftGlyphFontSpecRender() to render the data. π
void XftDrawGlyphFontSpec (
XftDraw *draw,
_Xconst XftColor *color,
_Xconst XftGlyphFontSpec*glyphs,
int len);
Okay so this one draws a whole list of glyphs π β glyphs that come pre-tied to their fonts at specific coordinates, handed over as an array of len XftGlyphFontSpec structs through the glyphs parameter. And every single one of them gets drawn in the color you passed as color. One color, whole squad. π
For each entry in the glyphs array, here's the tea:
- If the associated font uses the X Render extension, then Xft calls
XftGlyphFontSpecRender()to draw the glyph, using aPictureit got from callingXftDrawSrcPicture ()with thedrawandcolorparameters. β¨ - Otherwise, Xft provides an analogous feature using Xlib. π«
void XftGlyphFontSpecRender (
Display *dpy,
int op,
Picture src,
Picture dst,
int srcx,
int srcy,
_Xconst XftGlyphFontSpec*glyphs,
int nglyphs);
This one's a whole journey, bestie β it involves several steps: π¦
- First, Xft ensures that the
glyphsarray is complete usingXftFontCheckGlyph()and loading any missing glyphs withXftFontLoadGlyphs(). no glyph left behind fr - Then Xft examines the glyphs to find the maximum Unicode value. That determines the encoding size, i.e., the width. π
- Then, for each glyph, Xft checks if its Unicode value is handled by the corresponding font. If not, the value is set to zero (
0), to ignore it. While doing this, Xft also remembers which was the first font used, and computes the position at which each glyph will be drawn. π― - Xft then constructs an equivalent array of glyphs in the format expected by the X Render library. π
- Finally,
XftGlyphFontSpecRender()uses the X Render extension to draw the glyphs, with the appropriateXRenderCompositeText*()function according to the width, and discards temporary data. ποΈβ¨
The op, dst, src, srcx, and srcy parameters are used as described in the documentation for the X Render library. iykyk, go read that one too π
π Manipulating patterns π
FcFontSet *XftListFonts (
Display *dpy,
int screen,
...);
Xft uses FcPatternVapBuild() and FcObjectSetVapBuild() to process the variable-length parameter list, and FcFontList() to obtain a list of matching Fontconfig patterns, which it returns to the caller. π
The caller can dispose of the return value using FcPatternDestroy(). please do that, she's your responsibility now π
FcPattern *XftNameParse (
_Xconst char *name);
Xft uses Fontconfig to parse the name, passing the name to FcNameParse(), returning the result. πΈ
FcBool XftNameUnparse (
FcPattern *pat,
char *dest,
int len);
Like XfgNameParse(), Xft uses Fontconfig. (and yes, that is literally how it's spelled up in here, I'm not being chaotic on purpose for once π) In this case, it uses FcNameUnparse(), which converts the pattern pat back into a string that can be parsed. XftNameUnparse() stores the result via the caller's pointer dest, but checks first if it will fit, using the len parameter. If it fits, Xft copies the string and returns FcTrue, otherwise it returns FcFalse. β
β
π Manipulating Font data π
void XftFontLoadGlyphs (
Display *dpy,
XftFont *pub,
FcBool need_bitmaps,
_Xconst FT_UInt *glyphs,
int nglyph);
Using FT_Load_Glyph(), load nglyphs for the glyph indices (Unicode values) listed in the array glyphs from the given font pub. π€
Loading a glyph entails more than just reading data into memory. Xft uses the Fontconfig pattern associated with the display dpy (e.g., via XftDefaultSet()) to determine whether to use a bounding box, clip the glyphs into those bounds, scale the glyphs, compute font metrics, and add it to the X Render extension using XRenderAddGlyphs(). it's giving whole-ass production pipeline, not a vibe πβ¨
void XftFontUnloadGlyphs (
Display *dpy,
XftFont *pub,
_Xconst FT_UInt *glyphs,
int nglyph);
Discards data for up to nglyph glyphs whose glyph indices (Unicode values) are listed in the array glyphs for the given font pub. If the glyphs were added to the X Render extension, Xft removes those using XRenderFreeGlyphs(). Xft keeps track of the amount of memory used for glyphs, and updates the usage associated with the display dpy. π§Ήπ
FT_Face XftLockFace (
XftFont *pub);
If no FreeType 2 βfaceβ (in-memory representation of a given typeface in a given style) has been created for the pub font, create one using FT_New_Face(). Face-locks are a reference count used by Xft to ensure that only one face is created, and that it is retained until the font is no longer used. ππ
Face-locking is used directly in XftCharIndex() and XftFontLoadGlyphs(), which in turn are used in many functions of Xft. π
Face-locking was introduced in version 1 (October 2002). A few applications, such as Gdk/Gimp relied upon these functions. In version 2.1.9 (June 2006), face-locking was retained as part of the public API when improved shared-library configurations provided for hiding private symbols. π history lesson unlocked
void XftUnlockFace (
XftFont *pub);
Decrements the reference count for the FreeType 2 βfaceβ associated with the font. π
FT_Face objects are deallocated using FT_Done_Face(). Xft does this in XftFontInfoDestroy() and when cleaning up on failure in XftFontInfoCreate() and XftFontOpenPattern(). π§Ό
π DEBUGGING π
Xft reads the environment variable XFT_DEBUG and converts that to an integer. Each bit in the resulting value tells Xft to print debugging information to the standard output: π¨οΈπ
1β font-opening2β additional font-matching and opening (verbose) so much yapping, love that for us4β shows details about theXRenderPictFormatwhich will be used.8β shows the string whichXftDrawString8()will draw.16β shows which font-ids are matched.32β shows useful information about the glyphs which will be drawn64β shows an ASCII-art representation of the glyphs. ASCII ART?? iconic behavior fr π¨128β shows details about the memory-cache management256β shows details about managing glyph cached-memory512β shows a report on memory-usage1024β shows details on extended management of glyph cached-memory
π«Ά COMPATIBILITY π«Ά
As of version 2 (May 2002), Xft became relatively stable. It is expected to retain source and binary compatibility in future releases. slay, stable queen π
Xft provides a compatibility interface to its previous major version, Xft 1.x, described below. β¬οΈ
π§ Xft 1.x Header File π§
#include <X11/Xft/XftCompat.h>
πΈ Xft 1.x Data Types πΈ
XftPatternβ holds a set of names with associated value lists; each name refers to a property of a font.XftPatternsare used as inputs to the matching code as well as holding information about specific fonts. πXftFontSetβ contains a list ofXftPatterns. Internally, Xft uses this data structure to hold sets of fonts. Externally, Xft returns 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. (double "the the" and all, we keep it real in here π)
β¨ AUTHOR β¨
- Keith Packard π
- Thomas E. Dickey (performance improvements) π
π¦ SEE ALSO π¦
- Fontconfig Developers Reference
- FreeType API Reference
- Xlib - C Language Interface
- X Logical Font Description Conventions
and that's a wrap on the whole page, bestie!! π This lil masterpiece lives in X Version 11, it's libXft 2.3.8, and its whole identity in the wild is Xft(3). Go forth and render some glyphs, you absolute main character. πβ¨ππ
π¦ where this page comes from
- alpine 3.22: libxft-doc 2.3.8-r3 Β· MIT
- centos-stream 10: libXft-devel 2.3.8-8.el10 Β· HPND-sell-variant
- fedora 43: libXft-devel 2.3.8-9.fc43 Β· HPND-sell-variant
- fedora 43: libXft-devel 2.3.8-9.fc43 Β· HPND-sell-variant
- fedora 44: libXft-devel 2.3.8-10.fc44 Β· HPND-sell-variant
- fedora 44: libXft-devel 2.3.8-10.fc44 Β· HPND-sell-variant
- opensuse-leap 16.0: libXft-devel 2.3.8-160000.2.2 Β· MIT
- opensuse-leap 16.0: libXft-devel 2.3.8-160000.2.2 Β· MIT
- opensuse-leap 16.0: libXft-devel 2.3.8-160000.2.2 Β· MIT
- opensuse-leap 16.0: libXft-devel 2.3.8-160000.2.2 Β· MIT
- Copyright Β© 2022 Thomas E. Dickey
- Copyright Β© 2000 Keith Packard
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms