ref: f1a004c3925df32274aa9947e6e899ff5ca79c35
dir: /textimg.c/
#include <u.h> #include <libc.h> #include <draw.h> #include <memdraw.h> void usage(void) { sysfatal("usage: %s [ -f subfont ] text", argv0); } void main(int argc, char **argv) { char *s; Memsubfont *f; Point p; Memimage *img; s = "/lib/font/bit/lucida/latin1B.32.1"; f = nil; ARGBEGIN{ case 'f': s = EARGF(usage()); break; }ARGEND; if (argc < 1) sysfatal("no text argument"); if (memimageinit()) sysfatal("memimageinit failed: %r"); if (s) f = openmemsubfont(s); if (!f){ fprint(2, "cannot load subfont. Falling back to default.\n"); f = getmemdefont(); } p = memsubfontwidth(f, argv[0]); if (p.x == 0) sysfatal("no length"); img = allocmemimage(Rect(0, 0, p.x, f->height), RGB24); if (!img) sysfatal("cannot allocate memimage: %r"); memfillcolor(img, DWhite); memimagestring(img, Pt(0, 0), memblack, ZP, f, argv[0]); writememimage(1, img); }