Unified · Split
| @@ -539,6 +539,10 @@ otfglyf(Otf *o, int index) · 538 unmodified lines | ||
| 539 | 539 | werrstr("no memory"); |
| 540 | 540 | goto err; |
| 541 | 541 | } |
| 542 | + if(o->td.head == nil){ | |
| 543 | + werrstr("no head table"); | |
| 544 | + goto err; | |
| 545 | + } | |
| 542 | 546 | if(o->td.loca == nil){ |
| 543 | 547 | werrstr("no loca table"); |
| 544 | 548 | goto err; |
| @@ -577,6 +581,8 @@ otfglyf(Otf *o, int index) · 32 unmodified lines | ||
| 577 | 581 | if(read_Glyf(o, g) < 0){ |
| 578 | 582 | free(g); |
| 579 | 583 | g = nil; |
| 584 | + }else{ | |
| 585 | + g->unitsPerEm = o->td.head->unitsPerEm; | |
| 580 | 586 | } |
| 581 | 587 | otfpoprange(o); |
| 582 | 588 | otfpoprange(o); |
| @@ -80,4 +80,4 @@ void otfclose(Otf *o); · 79 unmodified lines | ||
| 80 | 80 | typedef struct Glyf Glyf; |
| 81 | 81 | Glyf *otfglyf(Otf *o, int index); |
| 82 | 82 | int otfglyfnum(Otf *o); |
| 83 | −u8int *otfdrawglyf(Glyf *g, int h, int *wo); | |
| 83 | +u8int *otfdrawglyf(Glyf *g, int ppem, int *wo, int *ho); | |
| @@ -209,7 +209,7 @@ · 208 unmodified lines | ||
| 209 | 209 | {int16 xMax} |
| 210 | 210 | {int16 yMax} |
| 211 | 211 | #:extra |
| 212 | − (list (cons 'field (list (~a "ComponentGlyph *component;") (~a "SimpleGlyph *simple;"))) | |
| 212 | + (list (cons 'field (list (~a "ComponentGlyph *component;") (~a "SimpleGlyph *simple;") (~a "u16int unitsPerEm;"))) | |
| 213 | 213 | (cons 'read |
| 214 | 214 | (list (~a "if(v->numberOfContours < 0 && read_ComponentGlyph(o, &v->component, 0) < 0)") |
| 215 | 215 | (~a " goto err;") |
| @@ -553,6 +553,10 @@ otfglyf(Otf *o, int index) · 552 unmodified lines | ||
| 553 | 553 | werrstr("no memory"); |
| 554 | 554 | goto err; |
| 555 | 555 | } |
| 556 | + if(o->td.head == nil){ | |
| 557 | + werrstr("no head table"); | |
| 558 | + goto err; | |
| 559 | + } | |
| 556 | 560 | if(o->td.loca == nil){ |
| 557 | 561 | werrstr("no loca table"); |
| 558 | 562 | goto err; |
| @@ -591,6 +595,8 @@ otfglyf(Otf *o, int index) · 32 unmodified lines | ||
| 591 | 595 | if(read_Glyf(o, g) < 0){ |
| 592 | 596 | free(g); |
| 593 | 597 | g = nil; |
| 598 | + }else{ | |
| 599 | + g->unitsPerEm = o->td.head->unitsPerEm; | |
| 594 | 600 | } |
| 595 | 601 | otfpoprange(o); |
| 596 | 602 | otfpoprange(o); |
| @@ -80,7 +80,7 @@ void otfclose(Otf *o); · 79 unmodified lines | ||
| 80 | 80 | typedef struct Glyf Glyf; |
| 81 | 81 | Glyf *otfglyf(Otf *o, int index); |
| 82 | 82 | int otfglyfnum(Otf *o); |
| 83 | −u8int *otfdrawglyf(Glyf *g, int h, int *wo); | |
| 83 | +u8int *otfdrawglyf(Glyf *g, int ppem, int *wo, int *ho); | |
| 84 | 84 | |
| 85 | 85 | typedef struct SubHeader SubHeader; |
| 86 | 86 | typedef struct MapGroup MapGroup; |
| @@ -451,6 +451,7 @@ struct Glyf { · 364 unmodified lines | ||
| 451 | 451 | s16int yMax; |
| 452 | 452 | ComponentGlyph *component; |
| 453 | 453 | SimpleGlyph *simple; |
| 454 | + u16int unitsPerEm; | |
| 454 | 455 | }; |
| 455 | 456 | |
| 456 | 457 | int read_Glyf(Otf *o, Glyf *v); |
| @@ -6,38 +6,43 @@ · 5 unmodified lines | ||
| 6 | 6 | typedef struct Image Image; |
| 7 | 7 | |
| 8 | 8 | struct Image { |
| 9 | + int h; | |
| 9 | 10 | int w; |
| 10 | 11 | u8int *b; |
| 11 | 12 | }; |
| 12 | 13 | |
| 13 | 14 | static void |
| 14 | −fit(u8int *b, int bw, int bh, Image *im, int h, int *x, int *y, int gap) | |
| 15 | +fit(u8int *b, int bw, int bh, Image *im, int maxh, int *x, int *y, int gap) | |
| 15 | 16 | { |
| 16 | 17 | int d; |
| 17 | 18 | |
| 18 | 19 | if((bw-*x) < im->w+gap){ |
| 19 | − *y += h + gap; | |
| 20 | + *y += maxh + gap; | |
| 20 | 21 | *x = gap; |
| 21 | 22 | } |
| 22 | − if((bh-*y) < h+gap) | |
| 23 | + if((bh-*y) < maxh+gap) | |
| 23 | 24 | return; |
| 24 | − for(d = 0; d < h; d++) | |
| 25 | + for(d = 0; d < im->h; d++) | |
| 25 | 26 | memcpy(b + (*y + d)*bw + *x, im->b + d*im->w, im->w); |
| 26 | 27 | *x += im->w + gap; |
| 27 | 28 | } |
| 28 | 29 | |
| 29 | 30 | static void |
| 30 | −dumpmap(Biobuf *out, Image *im, int n, int h) | |
| 31 | +dumpmap(Biobuf *out, Image *im, int n) | |
| 31 | 32 | { |
| 32 | −#define gap 2 | |
| 33 | − int total, mid, npix, bw, bh, x, y, i; | |
| 33 | +#define gap 1 | |
| 34 | + int total, mid, npix, bw, bh, x, y, i, maxh; | |
| 34 | 35 | u8int *b; |
| 35 | 36 | |
| 36 | 37 | total = 0; |
| 37 | − for(i = 0; i < n; i++) | |
| 38 | + maxh = 0; | |
| 39 | + for(i = 0; i < n; i++){ | |
| 40 | + if(maxh < im[i].h) | |
| 41 | + maxh = im[i].h; | |
| 38 | 42 | total += im[i].w; |
| 43 | + } | |
| 39 | 44 | mid = total / n; |
| 40 | − npix = (mid+gap)*(h+gap)*n; | |
| 45 | + npix = (mid+gap)*(maxh+gap)*n; | |
| 41 | 46 | bh = sqrt(npix); |
| 42 | 47 | bw = npix/bh; |
| 43 | 48 | bh *= 1.5; |
| @@ -48,9 +53,9 @@ dumpmap(Biobuf *out, Image *im, int n, int h) · 4 unmodified lines | ||
| 48 | 53 | memset(b, 0xff, npix); |
| 49 | 54 | x = y = gap; |
| 50 | 55 | for(i = 0; i < n; i++) |
| 51 | − fit(b, bw, bh, im+i, h, &x, &y, gap); | |
| 52 | − Bprint(out, "%11s %11d %11d %11d %11d ", "k8", 0, 0, bw, y+h+gap); | |
| 53 | − Bwrite(out, b, bw*(y+h+gap)); | |
| 56 | + fit(b, bw, bh, im+i, maxh, &x, &y, gap); | |
| 57 | + Bprint(out, "%11s %11d %11d %11d %11d ", "k8", 0, 0, bw, y+maxh+gap); | |
| 58 | + Bwrite(out, b, bw*(y+maxh+gap)); | |
| 54 | 59 | free(b); |
| 55 | 60 | } |
| 56 | 61 | |
| @@ -69,23 +74,23 @@ otfread(void *aux, void *dst, int sz) · 12 unmodified lines | ||
| 69 | 74 | static void |
| 70 | 75 | usage(void) |
| 71 | 76 | { |
| 72 | − fprint(2, "usage: %s [-g GLYPH_ID] [-G] [-i N] [-s PX] font.otf ...\n", argv0); | |
| 77 | + fprint(2, "usage: %s [-g GLYPH_ID] [-G] [-i N] [-p PPM] font.otf ...\n", argv0); | |
| 73 | 78 | fprint(2, " -g: specifies a single glyph id\n"); |
| 74 | 79 | fprint(2, " -G: print out glyph ids, only ones that can be drawn atm (no compound yet)\n"); |
| 75 | − fprint(2, " -s: draw (of size PX) and write the image to stdout\n"); | |
| 80 | + fprint(2, " -p: draw (of size in pixels per em) and write the image to stdout\n"); | |
| 76 | 81 | exits("usage"); |
| 77 | 82 | } |
| 78 | 83 | |
| 79 | 84 | void |
| 80 | 85 | main(int argc, char **argv) |
| 81 | 86 | { |
| 82 | − int i, gi, G, h; | |
| 87 | + int i, gi, G, ppem; | |
| 83 | 88 | Otfile in, out; |
| 84 | 89 | Otf *o; |
| 85 | 90 | |
| 86 | 91 | gi = -1; |
| 87 | 92 | G = 0; |
| 88 | − h = 0; | |
| 93 | + ppem = 0; | |
| 89 | 94 | ARGBEGIN{ |
| 90 | 95 | case 'g': |
| 91 | 96 | gi = strtol(EARGF(usage()), nil, 0); |
| @@ -93,8 +98,8 @@ main(int argc, char **argv) · 1 unmodified line | ||
| 93 | 98 | case 'G': |
| 94 | 99 | G++; |
| 95 | 100 | break; |
| 96 | − case 's': | |
| 97 | − h = strtol(EARGF(usage()), nil, 0); | |
| 101 | + case 'p': | |
| 102 | + ppem = strtol(EARGF(usage()), nil, 0); | |
| 98 | 103 | break; |
| 99 | 104 | default: |
| 100 | 105 | usage(); |
| @@ -110,30 +115,27 @@ main(int argc, char **argv) · 9 unmodified lines | ||
| 110 | 115 | fprint(2, "%r\n"); |
| 111 | 116 | continue; |
| 112 | 117 | } |
| 113 | − if(h <= 0) | |
| 118 | + if(ppem <= 0) | |
| 114 | 119 | Bprint(out.aux, "%s\n", argv[i]); |
| 115 | 120 | if(G && gi < 0){ |
| 116 | 121 | int i, n = otfglyfnum(o); |
| 117 | − Image *im = h > 0 ? calloc(n, sizeof(*im)) : nil; | |
| 122 | + Image *im = ppem > 0 ? calloc(n, sizeof(*im)) : nil; | |
| 118 | 123 | for(i = 0; i < n; i++){ |
| 119 | 124 | Glyf *g = otfglyf(o, i); |
| 120 | 125 | if(g == nil) |
| 121 | 126 | sysfatal("%r"); |
| 122 | − if(h > 0 && g->simple != nil && g->numberOfContours > 0){ | |
| 123 | − int w; | |
| 124 | − u8int *b = otfdrawglyf(g, h, &w); | |
| 125 | − if(b == nil) | |
| 127 | + if(ppem > 0 && g->simple != nil && g->numberOfContours > 0){ | |
| 128 | + im[i].b = otfdrawglyf(g, ppem, &im[i].w, &im[i].h); | |
| 129 | + if(im[i].b == nil) | |
| 126 | 130 | sysfatal("%r"); |
| 127 | − im[i].w = w; | |
| 128 | − im[i].b = b; | |
| 129 | − }else if(h <= 0){ | |
| 131 | + }else if(ppem <= 0){ | |
| 130 | 132 | Bprint(out.aux, "%d (%s):\n", i, g->simple ? "simple" : "component"); |
| 131 | 133 | print_Glyf(&out, indentΔ, o, g); |
| 132 | 134 | } |
| 133 | 135 | free(g); |
| 134 | 136 | } |
| 135 | − if(h > 0){ | |
| 136 | − dumpmap(out.aux, im, n, h); | |
| 137 | + if(ppem > 0){ | |
| 138 | + dumpmap(out.aux, im, n); | |
| 137 | 139 | for(i = 0; i < n; i++) |
| 138 | 140 | free(im[i].b); |
| 139 | 141 | free(im); |
| @@ -149,12 +151,12 @@ main(int argc, char **argv) · 9 unmodified lines | ||
| 149 | 151 | Glyf *g = otfglyf(o, gi); |
| 150 | 152 | if(g == nil){ |
| 151 | 153 | fprint(2, "%d: %r\n", gi); |
| 152 | − }else if(h > 0){ | |
| 154 | + }else if(ppem > 0){ | |
| 153 | 155 | if(g->component != nil) |
| 154 | 156 | fprint(2, "%d: component\n", gi); |
| 155 | 157 | else{ |
| 156 | − int w; | |
| 157 | − u8int *b = otfdrawglyf(g, h, &w); | |
| 158 | + int w, h; | |
| 159 | + u8int *b = otfdrawglyf(g, ppem, &w, &h); | |
| 158 | 160 | if(b == nil) |
| 159 | 161 | sysfatal("%r"); |
| 160 | 162 | fprint(1, "%11s %11d %11d %11d %11d ", "k8", 0, 0, w, h); |
| @@ -57,6 +57,8 @@ struct SegQ { · 56 unmodified lines | ||
| 57 | 57 | */ |
| 58 | 58 | #define QBZR_PIX_SCALE 4.0 |
| 59 | 59 | |
| 60 | +#define GAP 0 | |
| 61 | + | |
| 60 | 62 | #define ε 1.0e-10 |
| 61 | 63 | |
| 62 | 64 | static int |
| @@ -450,21 +452,17 @@ qbzr(SegQ *seg, int ns, int dw, int dh, Sval *p) · 387 unmodified lines | ||
| 450 | 452 | } |
| 451 | 453 | |
| 452 | 454 | u8int * |
| 453 | −otfdrawglyf(Glyf *g, int h, int *wo) | |
| 455 | +otfdrawglyf(Glyf *g, int ppem, int *wo, int *ho) | |
| 454 | 456 | { |
| 455 | − int w, i, r, k, npts, npx, ns; | |
| 457 | + int w, h, i, r, k, npts, npx, ns; | |
| 456 | 458 | Point *p₀, *p, *prev; |
| 457 | 459 | Spt *pts₀, *pts, *e; |
| 458 | − double scale; | |
| 459 | 460 | SegQ *s₀, *s; |
| 460 | 461 | Sval *fp; |
| 461 | 462 | u8int *b; |
| 462 | 463 | |
| 463 | − /* FIXME those epsilons and ceil is a rather dumb hack for now */ | |
| 464 | − scale = (double)h / (g->yMax - g->yMin) + ε; | |
| 465 | − w = *wo = ceil((g->xMax - g->xMin) * scale + ε); | |
| 464 | +#define scale (double)ppem/g->unitsPerEm | |
| 466 | 465 | |
| 467 | − npx = w * h; | |
| 468 | 466 | ns = 0; |
| 469 | 467 | s₀ = nil; |
| 470 | 468 | |
| @@ -507,16 +505,19 @@ otfdrawglyf(Glyf *g, int h, int *wo) · 36 unmodified lines | ||
| 507 | 505 | s = s₀ + ns; |
| 508 | 506 | pts = e; |
| 509 | 507 | for(e = pts₀; e <= pts-3; e += 2, s++, ns++){ |
| 510 | − s->v0[0] = (e[0].x - g->xMin) * scale; | |
| 511 | − s->v0[1] = (e[0].y - g->yMin) * scale; | |
| 512 | − s->v1[0] = (e[1].x - g->xMin) * scale; | |
| 513 | − s->v1[1] = (e[1].y - g->yMin) * scale; | |
| 514 | − s->v2[0] = (e[2].x - g->xMin) * scale; | |
| 515 | − s->v2[1] = (e[2].y - g->yMin) * scale; | |
| 508 | + s->v0[0] = (e[0].x - g->xMin) * scale + GAP; | |
| 509 | + s->v0[1] = (e[0].y - g->yMin) * scale + GAP; | |
| 510 | + s->v1[0] = (e[1].x - g->xMin) * scale + GAP; | |
| 511 | + s->v1[1] = (e[1].y - g->yMin) * scale + GAP; | |
| 512 | + s->v2[0] = (e[2].x - g->xMin) * scale + GAP; | |
| 513 | + s->v2[1] = (e[2].y - g->yMin) * scale + GAP; | |
| 516 | 514 | } |
| 517 | 515 | free(pts₀); |
| 518 | 516 | } |
| 519 | 517 | |
| 518 | + w = ceil((g->xMax - g->xMin)*scale + 2*GAP); | |
| 519 | + h = ceil((g->yMax - g->yMin)*scale + 2*GAP); | |
| 520 | + npx = w*h; | |
| 520 | 521 | fp = calloc(1, npx*sizeof(*fp)); |
| 521 | 522 | r = qbzr(s₀, ns, w, h, fp); |
| 522 | 523 | free(s₀); |
| @@ -526,8 +527,11 @@ otfdrawglyf(Glyf *g, int h, int *wo) · 3 unmodified lines | ||
| 526 | 527 | b = (u8int*)fp; |
| 527 | 528 | for(i = 0; i < npx; i++) |
| 528 | 529 | b[i] = 255 - (fp[i] <= 0 ? 0 : (fp[i] >= QBZR_PIX_SCALE ? 255 : fp[i]/QBZR_PIX_SCALE*255)); |
| 529 | − if((b = realloc(b, npx)) != nil) | |
| 530 | + if((b = realloc(b, npx)) != nil){ | |
| 531 | + *wo = w; | |
| 532 | + *ho = h; | |
| 530 | 533 | fp = nil; |
| 534 | + } | |
| 531 | 535 | } |
| 532 | 536 | free(fp); |
| 533 | 537 | return b; |
| @@ -9,37 +9,42 @@ typedef struct Image Image; · 8 unmodified lines | ||
| 9 | 9 | |
| 10 | 10 | struct Image { |
| 11 | 11 | int w; |
| 12 | + int h; | |
| 12 | 13 | u8int *b; |
| 13 | 14 | }; |
| 14 | 15 | |
| 15 | 16 | static void |
| 16 | −fit(u8int *b, int bw, int bh, Image *im, int h, int *x, int *y, int gap) | |
| 17 | +fit(u8int *b, int bw, int bh, Image *im, int maxh, int *x, int *y, int gap) | |
| 17 | 18 | { |
| 18 | 19 | int d; |
| 19 | 20 | |
| 20 | 21 | if((bw-*x) < im->w+gap){ |
| 21 | − *y += h + gap; | |
| 22 | + *y += maxh + gap; | |
| 22 | 23 | *x = gap; |
| 23 | 24 | } |
| 24 | − if((bh-*y) < h+gap) | |
| 25 | + if((bh-*y) < maxh+gap) | |
| 25 | 26 | return; |
| 26 | − for(d = 0; d < h; d++) | |
| 27 | + for(d = 0; d < im->h; d++) | |
| 27 | 28 | memcpy(b + (*y + d)*bw + *x, im->b + d*im->w, im->w); |
| 28 | 29 | *x += im->w + gap; |
| 29 | 30 | } |
| 30 | 31 | |
| 31 | 32 | static void |
| 32 | −dumpmap(FILE *out, Image *im, int n, int h) | |
| 33 | +dumpmap(FILE *out, Image *im, int n) | |
| 33 | 34 | { |
| 34 | −#define gap 2 | |
| 35 | − int total, mid, npix, bw, bh, x, y, i; | |
| 35 | +#define gap 1 | |
| 36 | + int total, mid, npix, bw, bh, x, y, i, maxh; | |
| 36 | 37 | u8int *b; |
| 37 | 38 | |
| 38 | 39 | total = 0; |
| 39 | − for(i = 0; i < n; i++) | |
| 40 | + maxh = 0; | |
| 41 | + for(i = 0; i < n; i++){ | |
| 42 | + if(maxh < im[i].h) | |
| 43 | + maxh = im[i].h; | |
| 40 | 44 | total += im[i].w; |
| 45 | + } | |
| 41 | 46 | mid = total / n; |
| 42 | − npix = (mid+gap)*(h+gap)*n; | |
| 47 | + npix = (mid+gap)*(maxh+gap)*n; | |
| 43 | 48 | bh = sqrt(npix); |
| 44 | 49 | bw = npix/bh; |
| 45 | 50 | bh *= 1.5; |
| @@ -51,9 +56,9 @@ dumpmap(FILE *out, Image *im, int n, int h) · 5 unmodified lines | ||
| 51 | 56 | memset(b, 0xff, npix); |
| 52 | 57 | x = y = gap; |
| 53 | 58 | for(i = 0; i < n; i++) |
| 54 | − fit(b, bw, bh, im+i, h, &x, &y, gap); | |
| 55 | − fprintf(out, "%11s %11d %11d %11d %11d ", "k8", 0, 0, bw, y+h+gap); | |
| 56 | − fwrite(b, 1, bw*(y+h+gap), out); | |
| 59 | + fit(b, bw, bh, im+i, maxh, &x, &y, gap); | |
| 60 | + fprintf(out, "%11s %11d %11d %11d %11d ", "k8", 0, 0, bw, y+maxh+gap); | |
| 61 | + fwrite(b, 1, bw*(y+maxh+gap), out); | |
| 57 | 62 | free(b); |
| 58 | 63 | } |
| 59 | 64 | |
| @@ -99,20 +104,20 @@ usage(void) · 39 unmodified lines | ||
| 99 | 104 | fprintf(stderr, "usage: %s [-g GLYPH_ID] [-G] [-i N] [-s PX] font.otf ...\n", argv0); |
| 100 | 105 | fprintf(stderr, " -g: specifies a single glyph id\n"); |
| 101 | 106 | fprintf(stderr, " -G: print out glyph ids, only ones that can be drawn atm (no compound yet)\n"); |
| 102 | − fprintf(stderr, " -s: draw (of size PX) and write the image to stdout\n"); | |
| 107 | + fprintf(stderr, " -p: draw (of size in pixels per em) and write the image to stdout\n"); | |
| 103 | 108 | exit(1); |
| 104 | 109 | } |
| 105 | 110 | |
| 106 | 111 | int |
| 107 | 112 | main(int argc, char **argv) |
| 108 | 113 | { |
| 109 | − int i, gi, G, h; | |
| 114 | + int i, gi, G, ppem; | |
| 110 | 115 | Otfile in, out; |
| 111 | 116 | Otf *o; |
| 112 | 117 | |
| 113 | 118 | gi = -1; |
| 114 | 119 | G = 0; |
| 115 | − h = 0; | |
| 120 | + ppem = 0; | |
| 116 | 121 | ARGBEGIN{ |
| 117 | 122 | case 'g': |
| 118 | 123 | gi = strtol(EARGF(usage()), NULL, 0); |
| @@ -120,8 +125,8 @@ main(int argc, char **argv) · 1 unmodified line | ||
| 120 | 125 | case 'G': |
| 121 | 126 | G++; |
| 122 | 127 | break; |
| 123 | − case 's': | |
| 124 | − h = strtol(EARGF(usage()), NULL, 0); | |
| 128 | + case 'p': | |
| 129 | + ppem = strtol(EARGF(usage()), NULL, 0); | |
| 125 | 130 | break; |
| 126 | 131 | default: |
| 127 | 132 | usage(); |
| @@ -137,30 +142,27 @@ main(int argc, char **argv) · 9 unmodified lines | ||
| 137 | 142 | err(1, "%s", argv[i]); |
| 138 | 143 | if((o = otfopen(&in)) == NULL) |
| 139 | 144 | errx(1, "%s: %s", argv[i], otferrstr()); |
| 140 | − if(h <= 0) | |
| 145 | + if(ppem <= 0) | |
| 141 | 146 | fprintf(out.aux, "%s\n", argv[i]); |
| 142 | 147 | if(G && gi < 0){ |
| 143 | 148 | int i, n = otfglyfnum(o); |
| 144 | − Image *im = h > 0 ? calloc(n, sizeof(*im)) : NULL; | |
| 149 | + Image *im = ppem > 0 ? calloc(n, sizeof(*im)) : NULL; | |
| 145 | 150 | for(i = 0; i < n; i++){ |
| 146 | 151 | Glyf *g = otfglyf(o, i); |
| 147 | 152 | if(g == NULL) |
| 148 | 153 | errx(1, "glyph %d: %s", i, otferrstr()); |
| 149 | − if(h > 0 && g->simple != NULL && g->numberOfContours > 0){ | |
| 150 | − int w; | |
| 151 | − u8int *b = otfdrawglyf(g, h, &w); | |
| 152 | − if(b == NULL) | |
| 154 | + if(ppem > 0 && g->simple != NULL && g->numberOfContours > 0){ | |
| 155 | + im[i].b = otfdrawglyf(g, ppem, &im[i].w, &im[i].h); | |
| 156 | + if(im[i].b == NULL) | |
| 153 | 157 | errx(1, "glyph %d: %s", i, otferrstr()); |
| 154 | − im[i].w = w; | |
| 155 | − im[i].b = b; | |
| 156 | − }else if(h <= 0){ | |
| 158 | + }else if(ppem <= 0){ | |
| 157 | 159 | fprintf(out.aux, "%d (%s):\n", i, g->simple ? "simple" : "component"); |
| 158 | 160 | print_Glyf(&out, indentΔ, o, g); |
| 159 | 161 | } |
| 160 | 162 | free(g); |
| 161 | 163 | } |
| 162 | − if(h > 0){ | |
| 163 | − dumpmap(out.aux, im, n, h); | |
| 164 | + if(ppem > 0){ | |
| 165 | + dumpmap(out.aux, im, n); | |
| 164 | 166 | for(i = 0; i < n; i++) |
| 165 | 167 | free(im[i].b); |
| 166 | 168 | free(im); |
| @@ -174,17 +176,17 @@ main(int argc, char **argv) · 7 unmodified lines | ||
| 174 | 176 | Glyf *g = otfglyf(o, gi); |
| 175 | 177 | if(g == NULL){ |
| 176 | 178 | errx(1, "glyph %d: %s", gi, otferrstr()); |
| 177 | − }else if(h > 0){ | |
| 179 | + }else if(ppem > 0){ | |
| 178 | 180 | if(g->component != NULL) |
| 179 | 181 | errx(1, "glyph %d: component", gi); |
| 180 | 182 | else{ |
| 181 | − int w; | |
| 182 | − u8int *b = otfdrawglyf(g, h, &w); | |
| 183 | − if(b == NULL) | |
| 183 | + Image im; | |
| 184 | + im.b = otfdrawglyf(g, ppem, &im.w, &im.h); | |
| 185 | + if(im.b == NULL) | |
| 184 | 186 | errx(1, "glyph %d: %s", gi, otferrstr()); |
| 185 | − fprintf(out.aux, "%11s %11d %11d %11d %11d ", "k8", 0, 0, w, h); | |
| 186 | − fwrite(b, 1, w*h, out.aux); | |
| 187 | − free(b); | |
| 187 | + fprintf(out.aux, "%11s %11d %11d %11d %11d ", "k8", 0, 0, im.w, im.h); | |
| 188 | + fwrite(im.b, 1, im.w*im.h, out.aux); | |
| 189 | + free(im.b); | |
| 188 | 190 | } |
| 189 | 191 | }else{ |
| 190 | 192 | fprintf(out.aux, "\n%d:\n", gi); |