XTextExtents(3)
π XTextExtents(3) β compute or query text extents, bestie
Okay so this is an XLIB FUNCTIONS page, and todayβs main character is text extents. No cap, weβre measuring text like itβs our job. π
πΈ NAME πΈ
XTextExtents, XTextExtents16, XQueryTextExtents, XQueryTextExtents16 β compute or query text extents. Thatβs the whole vibe. β¨
π¦ SYNTAX π¦
int XTextExtents(XFontStruct *font_struct, _Xconst char *string, int nchars, int *direction_return, int *font_ascent_return, int *font_descent_return, XCharStruct *overall_return);
int XTextExtents16(XFontStruct *font_struct, _Xconst XChar2b *string, int nchars, int *direction_return, int *font_ascent_return, int *font_descent_return, XCharStruct *overall_return);
int XQueryTextExtents(Display *display, XID font_ID, _Xconst char *string, int nchars, int *direction_return, int *font_ascent_return, int *font_descent_return, XCharStruct *overall_return);
int XQueryTextExtents16(Display *display, XID font_ID, _Xconst XChar2b *string, int nchars, int *direction_return, int *font_ascent_return, int *font_descent_return, XCharStruct *overall_return);
π ARGUMENTS π
direction_returnβ returns the value of the direction hint, which is eitherFontLeftToRightorFontRightToLeft. Slay.displayβ specifies the connection to the X server. Your server link, your main character energy. π₯font_IDβ specifies either the font ID or the GContext ID that contains the font. Both are valid, iykyk.font_ascent_returnβ returns the font ascent.font_descent_returnβ returns the font descent.font_structβ specifies theXFontStructstructure.ncharsβ specifies the number of characters in the character string.stringβ specifies the character string. The text itself, bestie.overall_returnβ returns the overall size in the specifiedXCharStructstructure.
β¨ DESCRIPTION β¨
The XTextExtents and XTextExtents16 functions perform the size computation locally and, thereby, avoid the round-trip overhead of XQueryTextExtents and XQueryTextExtents16. Both functions return an XCharStruct structure, whose members are set to the values as follows.
- The
ascentmember is set to the maximum of the ascent metrics of all characters in the string. - The
descentmember is set to the maximum of the descent metrics. - The
widthmember is set to the sum of the character-width metrics of all characters in the string. - For each character in the string, let
Wbe the sum of the character-width metrics of all characters preceding it in the string. LetLbe the left-side-bearing metric of the character plusW. LetRbe the right-side-bearing metric of the character plusW. Thelbearingmember is set to the minimumLof all characters in the string. Therbearingmember is set to the maximumR.
For fonts defined with linear indexing rather than 2-byte matrix indexing, each XChar2b structure is interpreted as a 16-bit number with byte1 as the most significant byte. If the font has no defined default character, undefined characters in the string are taken to have all zero metrics. π«Ά
The XQueryTextExtents and XQueryTextExtents16 functions return the bounding box of the specified 8-bit and 16-bit character string in the specified font or the font contained in the specified GC. These functions query the X server and, therefore, suffer the round-trip overhead that is avoided by XTextExtents and XTextExtents16. Both functions return a XCharStruct structure, whose members are set to the values as follows.
- The
ascentmember is set to the maximum of the ascent metrics of all characters in the string. - The
descentmember is set to the maximum of the descent metrics. - The
widthmember is set to the sum of the character-width metrics of all characters in the string. - For each character in the string, let
Wbe the sum of the character-width metrics of all characters preceding it in the string. LetLbe the left-side-bearing metric of the character plusW. LetRbe the right-side-bearing metric of the character plusW. Thelbearingmember is set to the minimumLof all characters in the string. Therbearingmember is set to the maximumR.
For fonts defined with linear indexing rather than 2-byte matrix indexing, each XChar2b structure is interpreted as a 16-bit number with byte1 as the most significant byte. If the font has no defined default character, undefined characters in the string are taken to have all zero metrics.
Characters with all zero metrics are ignored. If the font has no defined default_char, the undefined characters in the string are also ignored.
XQueryTextExtents and XQueryTextExtents16 can generate BadFont and BadGC errors. π
π DIAGNOSTICS π
BadFontβ A value for a Font or GContext argument does not name a defined Font.BadGCβ A value for a GContext argument does not name a defined GContext.
π SEE ALSO π
Xlib - C Language X Interface
Bye bestie π«Ά β this page comes from X Version 11, libX11 1.8.14, and the footer doesnβt list a date, so thatβs the source/version tea. Periodt. π
π¦ where this page comes from
- alpine 3.24: libx11-doc 1.8.14-r0 Β· X11
- arch rolling: libx11 1.8.14-1 Β· MIT AND X11
- nixos 26.05: libx11 1.8.14
- nixpkgs unstable: libx11 1.8.14
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms