XDrawString(3)

πŸ’… XDrawString β€” drawing text characters, the iconic way

Okay bestie, so this is the XDrawString(3) page from the XLIB FUNCTIONS manual, and it's literally about putting text on a drawable. Two functions, one vibe. Let's get into it ✨


🌸 NAME 🌸

XDrawString, XDrawString16 β€” draw text characters. That's it, that's the whole thing. Text. On your drawable. Slay. πŸŽ€


✨ SYNTAX ✨

int XDrawString(Display *display, Drawable d, GC gc, int x, int y,
       _Xconst char *string, int length);

int XDrawString16(Display *display, Drawable d, GC gc, int x, int y,
       _Xconst XChar2b *string, int length);

Two signatures, same energy. One takes a char *, the other takes an XChar2b *. Both return int. Both are your new besties 🫢


🌈 ARGUMENTS 🌈

  • d β€” Specifies the drawable. Like, the thing you're drawing on. The canvas. The main character.
  • display β€” Specifies the connection to the X server. Your little link to the mothership πŸ’–
  • gc β€” Specifies the GC. The Graphics Context. It's giving "settings bag" and honestly it kinda is.
  • length β€” Specifies the number of characters in the string argument. Count 'em. Fr fr, count them.
  • string β€” Specifies the character string. The actual text. The star of the show ⭐
  • x, y β€” Specify the x and y coordinates, which are relative to the origin of the specified drawable and define the origin of the first character. So like, that's where your first letter starts. The spawn point, if you will.

πŸ¦‹ DESCRIPTION πŸ¦‹

Okay so here's the tea β˜• β€” each character image, as defined by the font in the GC, is treated as an additional mask for a fill operation on the drawable. Think of it as: the letter is a stencil, and you're filling through it.

The drawable is modified only where the font character has a bit set to 1. Nowhere else. No sneaky stray pixels. Respect the mask, periodt πŸ’…

For fonts defined with 2-byte matrix indexing and used with XDrawString16, each byte is used as a byte2 with a byte1 of zero. Like, that's just how it goes for those fonts, ngl.

Both functions use these GC components:

  • function
  • plane-mask
  • fill-style
  • font
  • subwindow-mode
  • clip-x-origin
  • clip-y-origin
  • clip-mask

They also use these GC mode-dependent components:

  • foreground
  • background
  • tile
  • stipple
  • tile-stipple-x-origin
  • tile-stipple-y-origin
Heads up bestie β€” XDrawString and XDrawString16 can generate BadDrawable, BadGC, and BadMatch errors. So like, vibe check your args, okay? 😭

πŸ’€ DIAGNOSTICS πŸ’€

  • BadDrawable β€” A value for a Drawable argument does not name a defined Window or Pixmap. So whatever you passed in? It's not a real thing. Ghosted. πŸ‘»
  • BadGC β€” A value for a GContext argument does not name a defined GContext. Same situation, different argument. The GC said "not me" πŸ™ˆ
  • BadMatch β€” An InputOnly window is used as a Drawable. Bestie no, InputOnly windows are for input, not for drawing. That's literally their whole thing.
  • BadMatch β€” Some argument or pair of arguments has the correct type and range but fails to match in some other way required by the request. Like, everything looks right but the request still said no. Type and range: valid. Vibes: misaligned. πŸ’€

🧚 SEE ALSO 🧚


πŸ’œ Okay that's the whole page! Go forth and draw your little strings, bestie. If you need me I'll be over here stanning plane-masks.

Later, icon πŸ‘‘ β€” this was the XDrawString(3) page, X Version 11, libX11 1.8.14. Bookmark it, iykyk πŸŽ€πŸ’–βœ¨

πŸ“¦ where this page comes from