STRINGSIZE(3)

πŸ“¦ version 0_git20260208, in alpine 3.24, arch rolling, nixos 26.05, nixpkgs unstable

πŸ’– STRINGSIZE(3) β€” Library Functions Manual edition 🫢

okay so bestie, this is the glow-up of the page for all the little string-measuring icons in the Library Functions Manual, and it's genuinely so useful β€” no cap πŸ’…


πŸŽ€ NAME πŸŽ€

The squad is stringsize, stringwidth, stringnwidth, runestringsize, runestringwidth, and runestringnwidth β€” and their whole thing is the graphical size of strings ✨

🌸 SYNOPSIS 🌸

#include <u.h>
#include <libc.h>
#include <draw.h>

Point stringsize(Font *f, char *s)

int   stringwidth(Font *f, char *s)

int   stringnwidth(Font *f, char *s, int n)

Point runestringsize(Font *f, Rune *s)

int   runestringwidth(Font *f, Rune *s)

int   runestringnwidth(Font *f, Rune *s, int n)

πŸ¦‹ DESCRIPTION πŸ¦‹

Okay so these routines compute the geometrical extent of character strings when they're drawn on the display. The most straightforward one, stringsize, returns a Point representing the vector from upper left to lower right of the NUL-terminated string s drawn in font f. stringwidth returns just the x component. stringnwidth returns the width of the first n characters of s πŸ’–

The routines beginning with rune are analogous, but they accept an array of runes rather than UTF-encoded bytes. Cute, right? 🧚

🌷 FILES 🌷

  • /lib/font/bit β€” directory of fonts πŸŽ€

πŸ”₯ SOURCE πŸ”₯

The source lives at /src/libdraw β€” that's the spot, bestie πŸ’…

πŸ‘‘ SEE ALSO πŸ‘‘

πŸ’€ DIAGNOSTICS πŸ’€

⚠️ heads up bestie: because strings are loaded dynamically, these routines may generate I/O to the server and produce calls to the graphics error function. That's the diagnostics tea β˜•βœ¨

okay bye bestie β€” footer sign-off: STRINGSIZE(3) from the Library Functions Manual, and no separate source/version or date was printed in the footer, so I'm not inventing one πŸ’–βœ¨