XTextExtents()XTextExtents()Name
XTextExtents – get string and font metrics locally.
Synopsis
XTextExtents(font_struct, string, nchars, direction_return,
font_ascent_return, font_descent_return, overall_return)
XFontStruct *font_struct;
char *string;
int nchars;
int *direction_return;
int *font_ascent_return, *font_descent_return;
XCharStruct *overall_return;
Arguments
font_struct
Specifies a connection to an XFontStruct structure.
string Specifies the character string for which metrics are to be
returned.
nchars Specifies the number of characters in the character string.
direction_return
Returns the value of the direction element of the
XFontStruct. Either FontRightToLeft or FontLeftToRight.
font_ascent_return
Returns the font ascent element of the XFontStruct. This is
the overall maximum ascent for the font.
font_descent_return
Returns the font descent element of the XFontStruct. This is
the overall maximum descent for the font.
overall_return
Returns the overall characteristics of the string. These are
the sum of the width measurements for each character, the
maximum font_ascent_return and font_descent_return, the mini‐
mum lbearing added to the width of all characters up to the
character with the smallest lbearing, and the maximum rbear‐
ing added to the width of all characters up to the character
with the largest rbearing.
DescriptionXTextExtents() returns the dimensions in pixels that specify the bound‐
ing box of the specified string of characters in the named font, and
the maximum ascent and descent for the entire font. This function per‐
forms the size computation locally and, thereby, avoids the roundtrip
overhead of XQueryTextExtents(), but it requires a filled XFontStruct.
font_ascent_return and font_descent_return return information about the
font, while overall_return returns information about the given string.
The returned font_ascent_return and font_descent_return should usually
be used to calculate the line spacing, while the width, rbearing, and
lbearing members of overall_return should be used for horizontal mea‐
sures. The total height of the bounding rectangle, good for any string
in this font, is font_ascent_return+font_descent_return.
overall_return.ascent is the maximum of the ascent metrics of all char‐
acters in the string. The overall_return.descent is the maximum of the
descent metrics. The overall_return.width is the sum of the character-
width metrics of all characters in the string. The over‐
all_return.lbearing is the lbearing of the character in the string with
the smallest lbearing plus the width of all the characters up to but
not including that character. The overall_return.rbearing is the
rbearing of the character in the string with the largest rbearing plus
the width of all the characters up to but not including that character.
If the font has no defined default character, undefined characters in
the string are taken to have all zero metrics.
For more information on drawing text, see Volume One, Chapter 6, Draw‐
ing Graphics and Text.
Structures
typedef struct {
XExtData *ext_data; /* hook for extension to hang data */
Font fid; /* font ID for this font */
unsigned direction; /* hint about direction the font is painted */
unsigned min_char_or_byte2; /* first character */
unsigned max_char_or_byte2; /* last character */
unsigned min_byte1; /* first row that exists */
unsigned max_byte1; /* last row that exists */
Bool all_chars_exist; /* flag if all characters have non-zero size */
unsigned default_char; /* char to print for undefined character */
int n_properties; /* how many properties there are */
XFontProp *properties; /* pointer to array of additional properties */
XCharStruct min_bounds; /* minimum bounds over all existing char */
XCharStruct max_bounds; /* maximum bounds over all existing char */
XCharStruct *per_char; /* first_char to last_char information */
int ascent; /* logical extent above baseline for spacing */
int descent; /* logical descent below baseline for spacing */
} XFontStruct;
typedef struct {
short lbearing; /* origin to left edge of character */
short rbearing; /* origin to right edge of character */
short width; /* advance to next char's origin */
short ascent; /* baseline to top edge of character */
short descent; /* baseline to bottom edge of character */
unsigned short attributes; /* per char flags (not predefined) */
} XCharStruct;
See AlsoXDrawImageString(), XDrawImageString16(), XDrawString(), XDraw‐
String16(), XDrawText(), XDrawText16(), XQueryTextExtents(), XQueryTex‐
tExtents16(), XTextExtents16(), XTextWidth(), XTextWidth16().
Xlib - Text XTextExtents()