SUBFONT(3)
π SUBFONT(3) β subfont manipulation π
okay so bestie, this is the SUBFONT(3) page from the Library Functions Manual, and it is literally your group-chat cheat sheet for subfont manipulation. no cap, weβre keeping every function, every argument, every cache behavior, and every tiny caveat. letβs get into it π
π NAME π
allocsubfont, freesubfont, installsubfont, lookupsubfont, uninstallsubfont, subfontname, readsubfont, readsubfonti, writesubfont, stringsubfont, strsubfontwidth, mkfont β the whole squad, and their collective job is subfont manipulation. periodt β¨
π SYNOPSIS π
k so hereβs the exact spellbook, bestie β includes first, then all the signatures:
#include <u.h>
#include <libc.h>
#include <draw.h>
Subfont* allocsubfont(char *name, int n, int height, int ascent,
Fontchar *info, Image *i)
void freesubfont(Subfont *f)
void installsubfont(char *name, Subfont *f)
Subfont* lookupsubfont(Subfont *f)
void uninstallsubfont(Subfont *f)
Subfont* readsubfont(Display *d, char *name, int fd, int dolock)
Subfont* readsubfonti(Display *d, char *name, int fd, Image *im,
int dolock)
int writesubfont(int fd, Subfont *f)
Point stringsubfont(Image *dst, Point p, Image *src,
Subfont *f, char *str)
Point strsubfontwidth(Subfont *f, char *s)
Font* mkfont(Subfont *f, Rune min)
π¦ DESCRIPTION π¦
Subfonts are the components of fonts that hold the character images. A font comprises an array of subfonts; see cachechars(3). A new Subfont is allocated and initialized with allocsubfont. See cachechars(3) for the meaning of n, height, ascent, and info, and the arrangement of characters in image i. The name is used to identify the subfont in the subfont cache; see the descriptions lookupsubfont and installsubfont (q.v.). The appropriate fields of the returned Subfont structure are set to the passed arguments, and the image is registered as a subfont with the graphics device draw(3). And yeah, allocsubfont returns 0 on failure.
freesubfont frees a subfont and all its associated structure including the associated image. a lilβ caveat from the page: since freesbufont calls free on f->info, if f->info was not allocated by malloc(3) it should be zeroed before calling subffree.
A number of subfonts are kept in external files. The convention for naming subfont files is:
/font/name/class.size.depth
where size is approximately the height in pixels of the lower case letters (without ascenders or descenders). If there is only one version of the subfont, the .depth extension is elided. Class describes the range of runes encoded in the subfont: ascii, latin1, greek, etc.
Subfonts are cached within the program, so a subfont shared between fonts will be loaded only once. installsubfont stores subfont f under the given name, typically the file name from which it was read. uninstallsubfont removes the subfont from the cache. Finally, lookupsubfont searches for a subfont with the given name in the cache and returns it, or nil if no such subfont exists.
subfontname is used to locate subfonts given their names within the fonts. The default version constructs a name given the cfname, its name within the font, fname, the name of the font, and the maximum depth suitable for this subfont. This interface allows a partially specified name within a font to be resolved at run-time to the name of a file holding a suitable subfont. Although it is principally a routine internal to the library, subfontname may be substituted by the application to provide a less file-oriented subfont naming scheme.
The format of a subfont file is described in font(7). Briefly, it contains a image with all the characters in it, followed by a subfont header, followed by character information. readsubfont reads a subfont from the file descriptor fd. The name is used to identify the font in the cache. The dolock argument specifies whether the routine should synchronize use of the Display with other processes; for single-threaded applications it may always be zero. readsubfonti does the same for a subfont whose associated image is already in memory; it is passed as the argument im. In other words, readsubfonti reads only the header and character information from the file descriptor.
writesubfont writes on fd the part of a subfont file that comes after the image. It should be preceded by a call to writeimage (see allocimage(3)).
stringsubfont is analogous to string (see draw(3)) for subfonts. Rather than use the underlying font caching primitives, it calls draw for each character. It is intended for stand-alone environments such as operating system kernels. strsubfontwidth returns the width of the string s in as it would appear if drawn with stringsubfont in Subfont f.
mkfont takes as argument a Subfont s and returns a pointer to a Font that maps the character images in s into the Runes min to min+s->n-1.
π FILES π
/fontβ bitmap font file tree
π§ SOURCE π§
/src/libdraw
πΈ SEE ALSO πΈ
go peek at graphics(3), allocimage(3), draw(3), cachechars(3), image(7), and font(7).
π DIAGNOSTICS π
All of the functions use the graphics error function (see graphics(3)).
xoxo, bestie π β footer sign-off: SUBFONT(3) from the Library Functions Manual. no separate version/date is printed on this page, so weβre not inventing one. mwah π
π¦ where this page comes from
- alpine 3.24: plan9port-doc 0_git20260208-r0 Β· LPL-1.02
- arch rolling: plan9port 20261021-2 Β· custom
- nixos 26.05: plan9port 0-unstable-2025-11-10
- nixos 26.05: plan9port-wayland 0-unstable-2025-11-26
- nixpkgs unstable: plan9port 0-unstable-2025-11-10
- nixpkgs unstable: plan9port-wayland 0-unstable-2025-11-26
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms