XListFonts(3)

🌸 XListFonts(3) β€” the font-listing glow-up you didn't know you needed πŸ’…

okay bestie, gather round, because we're talking about XListFonts, XFreeFontNames, XListFontsWithInfo, and XFreeFontInfo β€” the iconic little quartet from the Xlib C Language X Interface (X Version 11, libX11 1.8.14) that lets you obtain or free font names and font info. it's giving "backend bestie energy," and honestly? we're obsessed. 🫢✨


✨ SYNTAX ✨

bestie, here's the exact shape of each function β€” copy these character for character, no cap:

char **XListFonts(Display *display, _Xconst char *pattern, int maxnames,
       int *actual_count_return);

int XFreeFontNames(char *list[]);

char **XListFontsWithInfo(Display *display, _Xconst char *pattern, int
       maxnames, int *count_return, XFontStruct **info_return);

int XFreeFontInfo(char **names, XFontStruct *free_info, int
       actual_count);

πŸŽ€ ARGUMENTS πŸŽ€

every single parameter, served fresh, no skips:

  • actual_count β€” Specifies the actual number of font names.
  • actual_count_return β€” Returns the actual number of font names.
  • count_return β€” Returns the actual number of matched font names.
  • display β€” Specifies the connection to the X server.
  • info_return β€” Returns the font information.
  • free_info β€” Specifies the font information.
  • list β€” Specifies the array of strings you want to free.
  • maxnames β€” Specifies the maximum number of names to be returned.
  • names β€” Specifies the list of font names.
  • pattern β€” Specifies the null-terminated pattern string that can contain wildcard characters.

πŸ’– DESCRIPTION πŸ’–

okay so here's the tea on each one, and yes we're doing all of them πŸ“

🌈 XListFonts

The XListFonts function returns an array of available font names (as controlled by the font search path; see XSetFontPath) that match the string you passed to the pattern argument. The pattern string can contain any characters, but each asterisk (*) is a wildcard for any number of characters, and each question mark (?) is a wildcard for a single character. If the pattern string is not in the Host Portable Character Encoding, the result is implementation-dependent. Use of uppercase or lowercase does not matter. Each returned string is null-terminated. If the data returned by the server is in the Latin Portable Character Encoding, then the returned strings are in the Host Portable Character Encoding. Otherwise, the result is implementation-dependent. If there are no matching font names, XListFonts returns NULL. The client should call XFreeFontNames when finished with the result to free the memory.

lowkey the wildcard thing is so cute β€” * = "any number of characters, idc" and ? = "exactly one character bestie". also: uppercase/lowercase? doesn't matter. slay. πŸ’…

🌸 XFreeFontNames

The XFreeFontNames function frees the array and strings returned by XListFonts or XListFontsWithInfo. literally the cleanup bestie β€” don't leave your memory hanging, periodt.

πŸ¦‹ XListFontsWithInfo

The XListFontsWithInfo function returns a list of font names that match the specified pattern and their associated font information. The list of names is limited to size specified by maxnames. The information returned for each font is identical to what XLoadQueryFont would return except that the per-character metrics are not returned. The pattern string can contain any characters, but each asterisk (*) is a wildcard for any number of characters, and each question mark (?) is a wildcard for a single character. If the pattern string is not in the Host Portable Character Encoding, the result is implementation-dependent. Use of uppercase or lowercase does not matter. Each returned string is null-terminated. If the data returned by the server is in the Latin Portable Character Encoding, then the returned strings are in the Host Portable Character Encoding. Otherwise, the result is implementation-dependent. If there are no matching font names, XListFontsWithInfo returns NULL.

"except that the per-character metrics are not returned" β€” ok so it's the XLoadQueryFont experience but without the per-character metrics. we love a stripped-down icon. πŸ‘‘

freeing strategy, because yes there's a whole decision tree:

  • To free only the allocated name array, the client should call XFreeFontNames.
  • To free both the name array and the font information array or to free just the font information array, the client should call XFreeFontInfo.

🧚 XFreeFontInfo

The XFreeFontInfo function frees a font structure or an array of font structures and optionally an array of font names.

  • If NULL is passed for names, no font names are freed.
  • If a font structure for an open font (returned by XLoadQueryFont) is passed, the structure is freed, but the font is not closed; use XUnloadFont to close the font.
heads up bestie β€” freeing the structure does NOT close the font. you need XUnloadFont for that. don't let anyone tell you otherwise. πŸ’€

⚠️ IMPORTANT VIBE CHECK ⚠️ Note that XListFontsWithInfo is not thread-safe. If other threads make X requests on the same Display, then this function's behavior is undefined. fr fr, do not play with this. 😭

πŸ‘‘ SEE ALSO πŸ‘‘

the whole friend group:


and that's the whole page, bestie! πŸŽ€ this glamorous little manual brought to you by X Version 11, libX11 1.8.14, dated however long ago, with all the copyright and license energy baked right in β€” now go list those fonts and free that memory responsibly. mwah! πŸ’–βœ¨πŸ¦‹πŸŒˆπŸŒ·

πŸ“¦ where this page comes from