ref: f703cd3cbfe6ca6cb78b9cabf2bf09ec4457c2f6
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);
}