ref: 1b381f9ec368578a78dc0f094ff200224d0a14bc
dir: /test.h/
static void
printusage(Otfile *f)
{
f->print(f->aux, "usage: %s [-i GLYPH_ID] [-m] [-p PX] font.otf ...\n", argv0);
f->print(f->aux, " -i: specifies a single glyph id\n");
f->print(f->aux, " -g: gap (in pixels) to add to every glyph border\n");
f->print(f->aux, " -m: print out glyph ids or render them all (with -p)\n");
f->print(f->aux, " -p: draw (of size in pixels per em) and write the image to stdout\n");
f->print(f->aux, "Specifying -m more than once adds guide lines\n");
f->print(f->aux, "Specifying -m more than twice adds filling of empty pixels\n");
}
static int gap, gind = -1, map, ppem;
static int
dumpmap(Otfile *f, GlyfImage *im, int n)
{
int x, y, i, j, t, maxh, prebase, postbase, d;
int gap, total, mid, npix, bw, bh, lines, fill;
u8int *b;
total = 0;
maxh = 0;
gap = 1;
lines = map > 1;
fill = map > 2;
for(i = 0; i < n; i++){
if(im[i].b == nil)
continue;
if(maxh < im[i].h)
maxh = im[i].h;
total += im[i].w;
}
mid = total / n;
npix = (mid+gap)*(maxh+gap)*n;
bh = sqrt(npix);
bw = npix/bh;
npix += bw*gap;
if((b = malloc(npix*3)) == nil)
return -1;
memset(b, 0xff, npix*3);
y = gap;
for(i = 0; i < n;){
for(prebase = postbase = x = 0, j = i; j < n; j++){
if(im[j].b == nil)
continue;
x += im[j].w + gap;
if(x > bw)
break;
if(prebase < im[j].h+im[j].baseline)
prebase = im[j].h+im[j].baseline;
if(postbase < im[j].baseline)
postbase = im[j].baseline;
}
maxh = prebase + postbase;
if(j == i || y+maxh > bh)
break;
for(x = 0; i < j; i++){
if(im[i].b == nil)
continue;
u8int *lt = b + ((y + prebase - (im[i].h+im[i].baseline))*bw + x)*3;
for(d = 0; d < im[i].h; d++, lt += bw*3){
for(t = 0; t < im[i].w; t++){
u8int r, g, b;
r = g = b = im[i].b[d*im[i].w + t];
if(lines && g == 0xff && (d == im[i].h+im[i].baseline)){
g = 0;
b = 0;
}else if(lines && g == 0xff && (fill || t == 0 || t == im[i].w-1 || d == 0 || d == im[i].h-1)){
r = 0;
b = 0;
}
if(r != 0xff || g != 0xff || b != 0xff){
lt[t*3+0] = b;
lt[t*3+1] = g;
lt[t*3+2] = r;
}
}
}
x += im[i].w + gap;
}
y += maxh + gap;
}
f->print(f->aux, "%11s %11d %11d %11d %11d ", "r8g8b8", 0, 0, bw, y);
f->write(f->aux, b, bw*y*3);
free(b);
return 0;
}
#define parseoptions() \
ARGBEGIN{ \
case 'g': \
gap = strtol(EARGF(usage(&out)), nil, 0); \
break; \
case 'i': \
gind = strtol(EARGF(usage(&out)), nil, 0); \
break; \
case 'm': \
map++; \
break; \
case 'p': \
ppem = strtol(EARGF(usage(&out)), nil, 0); \
break; \
default: \
usage(&out); \
}ARGEND