ref: f703cd3cbfe6ca6cb78b9cabf2bf09ec4457c2f6
author: sirjofri <sirjofri@sirjofri.de>
date: Sat Jan 16 12:38:31 EST 2021
adds files
--- /dev/null
+++ b/README.md
@@ -1,0 +1,6 @@
+textimg
+=======
+
+`textimg [ -f /path/to/subfont ] 'hello world'`
+
+Works with plumber to tweak, or redirect it in file.
--- /dev/null
+++ b/mkfile
@@ -1,0 +1,6 @@
+</$objtype/mkfile
+
+TARG=textimg
+OFILES=textimg.$O
+
+</sys/src/cmd/mkone
--- /dev/null
+++ b/textimg.c
@@ -1,0 +1,53 @@
+#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);
+}