ref: 0d17a04bbcbb6ee26415d356f40e75d891c5f016
dir: /plan9/test.c/
#include <u.h> #include <libc.h> #include <bio.h> #include "otf.h" #include "test.h" static int otfseek(void *aux, int off, int whence) { return Bseek(aux, off, whence); } static int otfread(void *aux, void *dst, int sz) { return Bread(aux, dst, sz); } static int otfwrite(void *aux, void *dst, int sz) { return Bwrite(aux, dst, sz); } static void usage(Otfile *f) { printusage(f); exits("usage"); } void main(int argc, char **argv) { int i; Otfile in, out; Otf *o; in.seek = otfseek; in.read = otfread; out.print = (void*)Bprint; out.write = otfwrite; out.aux = Bfdopen(1, OWRITE); parseoptions(); for(i = 0; i < argc; i++){ if((in.aux = Bopen(argv[i], OREAD)) == nil || (o = otfopen(&in)) == nil){ fprint(2, "%r\n"); continue; } if(ppem <= 0) Bprint(out.aux, "%s\n", argv[i]); if(map > 0 && gind < 0){ int i, n = otfglyfnum(o); GlyfImage *im = ppem > 0 ? calloc(n, sizeof(*im)) : nil; for(i = 0; i < n; i++){ Glyf *g = otfglyf(o, i); if(g == nil) sysfatal("glyf %d: %r", i); if(ppem > 0 && g->numberOfContours != 0){ if(otfdrawglyf(o, g, ppem, gap, &im[i]) != 0) sysfatal("glyf %d: %r", i); }else if(ppem <= 0){ Bprint(out.aux, "%d (%s):\n", i, g->simple ? "simple" : (g->component ? "component" : "empty")); print_Glyf(&out, indentΔ, o, g); } free(g); } if(ppem > 0){ dumpmap(&out, im, n); for(i = 0; i < n; i++) free(im[i].b); free(im); }else{ fprint(2, "\n"); } }else if(gind < 0){ otfprint(o, &out, indentΔ); }else{ int n = otfglyfnum(o); if(gind >= n) sysfatal("glyph %d out of range, max %d", gind, n-1); Glyf *g = otfglyf(o, gind); if(g == nil){ fprint(2, "%d: %r\n", gind); }else if(ppem > 0){ GlyfImage im; if(otfdrawglyf(o, g, ppem, gap, &im) != 0) sysfatal("%r"); fprint(1, "%11s %11d %11d %11d %11d ", "k8", 0, 0, im.w, im.h); write(1, im.b, im.w*im.h); free(im.b); }else{ Bprint(out.aux, "\n%d:\n", gind); print_Glyf(&out, indentΔ, o, g); } } otfclose(o); Bterm(in.aux); } Bterm(out.aux); exits(nil); }