ref: 29c96c7ead583a633d3e05b9df1eca529b7d996f
dir: /test_plan9.c/
#include <u.h>
#include <libc.h>
#include <bio.h>
#include "otf.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 void
usage(void)
{
fprint(2, "usage: %s [-g GLYPH_ID] [-G] [-i N] [-s PX] font.otf ...\n", argv0);
fprint(2, " -g: specifies a single glyph id\n");
fprint(2, " -G: print out glyph ids, only ones that can be drawn atm (no compound yet)\n");
fprint(2, " -s: draw (of size PX) and write the image to stdout\n");
exits("usage");
}
void
main(int argc, char **argv)
{
int i, gi, G, h;
Otfile in, out;
Otf *o;
gi = -1;
G = 0;
h = 0;
ARGBEGIN{
case 'g':
gi = strtol(EARGF(usage()), nil, 0);
break;
case 'G':
G++;
break;
case 's':
h = strtol(EARGF(usage()), nil, 0);
break;
default:
usage();
}ARGEND
in.seek = otfseek;
in.read = otfread;
out.print = (void*)Bprint;
out.aux = Bfdopen(1, OWRITE);
for(i = 0; i < argc; i++){
if(h <= 0)
Bprint(out.aux, "%s\n", argv[i]);
if((in.aux = Bopen(argv[i], OREAD)) == nil || (o = otfopen(&in)) == nil){
fprint(2, "%r\n");
continue;
}
if(G){
int i, n = otfglyfnum(o);
for(i = 0; i < n; i++){
Glyf *g = otfglyf(o, i);
if(g != nil && g->simple != nil && g->numberOfContours > 0){
if(h > 0){
int w;
u8int *b = otfdrawglyf(g, h, &w);
if(b == nil)
sysfatal("%r");
free(b);
}else{
fprint(2, "%d ", i);
}
}
free(g);
}
if(h <= 0)
fprint(2, "\n");
}else if(gi < 0){
otfprint(o, &out, indentΔ);
}else{
int n = otfglyfnum(o);
if(gi >= n)
sysfatal("glyph %d out of range, max %d\n", gi, n-1);
Glyf *g = otfglyf(o, gi);
if(g == nil){
fprint(2, "%d: %r\n", gi);
}else if(h > 0){
if(g->component != nil)
fprint(2, "%d: component\n", gi);
else{
int w;
u8int *b = otfdrawglyf(g, h, &w);
if(b == nil)
sysfatal("%r");
fprint(1, "%11s %11d %11d %11d %11d ", "k8", 0, 0, w, h);
write(1, b, w*h);
free(b);
}
}else{
Bprint(out.aux, "\n%d:\n", gi);
print_Glyf(&out, indentΔ, o, g);
}
}
otfclose(o);
Bterm(in.aux);
}
Bterm(out.aux);
exits(nil);
}