ref: 0d17a04bbcbb6ee26415d356f40e75d891c5f016
dir: /unix/test.c/
#include <assert.h> #include <err.h> #include <math.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include "otf.h" #define nil NULL static char *argv0; #define ARGBEGIN for((argv0? 0: (argv0=*argv)),argv++,argc--;\ argv[0] && argv[0][0]=='-' && argv[0][1];\ argc--, argv++) {\ char *_args, *_argt;\ int _argc;\ _args = &argv[0][1];\ if(_args[0]=='-' && _args[1]==0){\ argc--; argv++; break;\ }\ _argc = 0;\ while((_argc = *_args++) != 0)\ switch(_argc) #define ARGEND (void)_argt; (void)_argc; (void)_args;}(void)argv; (void)argc; #define ARGF() (_argt=_args, _args="",\ (*_argt? _argt: argv[1]? (argc--, *++argv): 0)) #define ARGC() _argc #define EARGF(x) (_argt=_args, _args="",\ (*_argt? _argt: argv[1]? (argc--, *++argv): (x, (char*)0))) #include "test.h" static int otfseek(void *aux, int off, int whence) { if(fseek(aux, off, whence) < 0) return -1; return ftell(aux); } static int otfread(void *aux, void *dst, int sz) { return fread(dst, 1, sz, aux); } static int otfwrite(void *aux, const void *src, int sz) { return fwrite(src, 1, sz, aux); } static void usage(Otfile *out) { printusage(out); exit(1); } int main(int argc, char **argv) { Otfile in, out; int i; Otf *o; out.print = (void*)fprintf; out.write = otfwrite; out.aux = fdopen(1, "wb"); in.seek = otfseek; in.read = otfread; parseoptions(); for(i = 0; i < argc; i++){ if((in.aux = fopen(argv[i], "rb")) == NULL) err(1, "%s", argv[i]); if((o = otfopen(&in)) == NULL) errx(1, "%s: %s", argv[i], otferrstr()); if(ppem <= 0) out.print(out.aux, "%s\n", argv[i]); if(map && gind < 0){ int i, n = otfglyfnum(o); GlyfImage *im = ppem > 0 ? calloc(n, sizeof(*im)) : NULL; for(i = 0; i < n; i++){ Glyf *g = otfglyf(o, i); if(g == NULL) errx(1, "glyph %d: %s", i, otferrstr()); if(ppem > 0 && g->numberOfContours != 0){ if(otfdrawglyf(o, g, ppem, gap, im+i) != 0) errx(1, "glyph %d: %s", i, otferrstr()); }else if(ppem <= 0){ out.print(out.aux, "%d (%s):\n", i, g->simple ? "simple" : (g->component ? "component" : "empty")); print_Glyf(&out, indentΔ, o, g); } free(g); } if(ppem > 0){ if(dumpmap(&out, im, n) != 0) err(1, nil); for(i = 0; i < n; i++) free(im[i].b); free(im); } }else if(gind < 0){ otfprint(o, &out, indentΔ); }else{ int n = otfglyfnum(o); if(gind >= n) errx(1, "glyph %d out of range, max %d", gind, n-1); Glyf *g = otfglyf(o, gind); if(g == NULL){ errx(1, "glyph %d: %s", gind, otferrstr()); }else if(ppem > 0){ GlyfImage im; if(otfdrawglyf(o, g, ppem, gap, &im) != 0) errx(1, "glyph %d: %s", gind, otferrstr()); out.print(out.aux, "%11s %11d %11d %11d %11d ", "k8", 0, 0, im.w, im.h); out.write(out.aux, im.b, im.w*im.h); free(im.b); }else{ out.print(out.aux, "\n%d:\n", gind); print_Glyf(&out, indentΔ, o, g); } } otfclose(o); fclose(in.aux); } fclose(out.aux); return 0; }