WSFONT(9)

πŸ“¦ version 11.0, in nixpkgs unstable

🌸 WSFONT(9) β€” the wsfont manual page, bestie edition 🌸

okay so this is from the Kernel Developer's Manual (the Wsfont one, section 9, iykyk) and it's literally all about how the kernel handles fonts. let's get into it πŸ’…


✨ NAME ✨

wsfont, wsfont_init, wsfont_matches, wsfont_find, wsfont_add, wsfont_remove, wsfont_enum, wsfont_lock, wsfont_unlock, wsfont_map_unichar β€” the whole wscons font support squad 🫢


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <dev/wscons/wsconsio.h>
#include <dev/wsfont/wsfont.h>

void
wsfont_init(void);

int
wsfont_matches(struct wsdisplay_font *font, const char *name, int width,
    int height, int stride, int flags);

int
wsfont_find(const char *name, int width, int height, int stride,
    int bitorder, int byteorder, int flags);

int
wsfont_add(struct wsdisplay_font *font, int copy);

int
wsfont_remove(int cookie);

void
wsfont_enum(void (*callback)(const char *, int, int, int));

int
wsfont_lock(int cookie, struct wsdisplay_font **ptr);

int
wsfont_unlock(int cookie);

int
wsfont_map_unichar(struct wsdisplay_font *font, int c);

πŸ’– DESCRIPTION πŸ’–

so the wsfont module is a whole component of the wscons(9) framework, and its entire job is giving you access to display fonts. that's it, that's the vibe ✨

fonts can be loaded dynamically into the kernel OR included statically in the kernel at compile time β€” both are valid, no cap. and display drivers that emulate a glass-tty console on a bit-mapped display can add, remove, and find fonts for use by device-dependent blitter operations. iconic behavior honestly πŸ”₯

the main character of this whole page is the wsdisplay_font structure over in dev/wscons/wsconsio.h:

struct wsdisplay_font {
        const char *name;       /* font name */
        int firstchar;
        int numchars;           /* size of font table */
        int encoding;           /* font encoding */
        u_int fontwidth;        /* character width */
        u_int fontheight;       /* character height */
        u_int stride;
        int bitorder;
        int byteorder;
        void *data;             /* pointer to font table */
};

the maximum font table size is WSDISPLAY_MAXFONTSZ β€” remember that, it matters πŸŽ€

🌈 the encodings the framework supports

  • WSDISPLAY_FONTENC_ISO β€” ISO-encoded fonts, classic.
  • WSDISPLAY_FONTENC_IBM β€” IBM-encoded fonts, the ones you'll commonly find for IBM CGA, EGA and VGA display adapters. retro slay πŸ’€
  • WSDISPLAY_FONTENC_PCVT β€” PCVT-encoding fonts, distributed as part of the old PCVT terminal emulation driver. vintage.
  • WSDISPLAY_FONTENC_ISO7 β€” ISO-encoded Greek fonts πŸ‡¬πŸ‡·
  • WSDISPLAY_FONTENC_ISO2 β€” ISO-encoded East European fonts.

πŸŽ€ FUNCTIONS πŸŽ€

wsfont_init(void)

Initialises the font list with the built-in fonts. starting fresh, periodt ✨

wsfont_matches(font, name, width, height, stride)

Matches the font font against the specs name, width, height, stride and flags. returns zero if not matched and non-zero if matched πŸ’– and just so you know, the flags parameter means the exact same thing as it does in wsfont_find().

wsfont_find(name, width, height, stride, bitorder, byteorder, flags)

Finds the font called name from the fonts loaded into the kernel. the font's whole aspect is specified by width, height, and stride. and here's the bestie hack: if wsfont_find() is called with any of those parameters as 0, that literally means "we don't care about that aspect of the font" πŸ™ˆ. if the font is found, a (nonnegative-valued) cookie gets returned, and you can use that cookie with all the other functions. cookie πŸͺ honestly cute.

the bitorder and byteorder arguments are the bit order and byte order you require. valid values are:

  • WSDISPLAY_FONTORDER_KNOWN β€” the font is in known ordered format and doesn't need converting. already perfect, no notes πŸ‘‘
  • WSDISPLAY_FONTORDER_L2R β€” the font is ordered left to right.
  • WSDISPLAY_FONTORDER_R2L β€” the font is ordered right to left.

the flags parameter decides what type of font can be returned, and any combination of these values is allowed:

  • WSFONT_FIND_BITMAP β€” to search bitmap fonts,
  • WSFONT_FIND_ALPHA β€” to search anti-aliased fonts.

when you need more flexibility than that, you should use wsfont_enum() instead. that's the move πŸ’…

wsfont_add(font, copy)

Adds a font font to the font list. and the copy argument? if it's non-zero, then the font is physically copied. otherwise a reference to the original font is made. your call bestie 🫢

Removes the font specified by cookie from the font list. and the value of cookie was returned by wsfont_add(), so don't just make one up 😭

wsfont_enum(callback)

Enumerates the list of fonts. for every single font in the font list, the callback function argument gets called with arguments specifying the font name, width, height and stride. it's giving roll call πŸ“‹

Locks access to the font specified by cookie so it cannot be unloaded from the kernel while it's being used β€” very important, don't skip this one πŸ”’

now here's the spicy part: if the bit or byte order of the font to be locked differs from what was requested with wsfont_find(), then the glyph data will be modified to match. at that point it may be necessary for wsfont_lock() to make a copy of the font data β€” and that action is transparent to the caller, so don't worry about it. a later call to wsfont_unlock() will free resources used by temporary copies. very demure, very mindful of resources 🧚

the address of the wsdisplay_font pointer for the specified font gets returned in the ptr argument.

wsfont_lock() returns zero on success, or an error code on failure.

Unlocks the font specified by cookie. returns zero on success, or an error code on failure. that's it, she's simple πŸŽ€

wsfont_map_unichar(font, c)

Remaps the unicode character c to a glyph for font font. returns the glyph on success or -1 on error. the remappingβ„’ ✨


πŸ¦‹ CODE REFERENCES πŸ¦‹

the wscons subsystem lives inside the directory sys/dev/wscons. and the wsfont subsystem itself? implemented within the file sys/dev/wsfont/wsfont.c β€” now you know exactly where to look πŸ”


🌸 SEE ALSO 🌸

wsfont(4), wsfontload(8), autoconf(9), driver(9), intro(9), wscons(9), wsdisplay(9)

go read those too, they're all in their own little ecosystem πŸ’œ


and that's the whole page bestie, mwah πŸ’‹ β€” this one came from Debian, dated January 13, 2012, so yeah it's got some vintage energy but she still ate. periodt. 🌈✨

πŸ“¦ where this page comes from