History

make otfdrawglyf itself allocate the image

Sigrid Solveig Haflínudóttir committed 2 years ago

Commit 2cfe3c21 parent a5576434 files · +57 −55Browse files

Unified · Split

4 files
  1. otf.h.in +5 −5
  2. plan9/otf.h +5 −5
  3. rast.c +19 −15
  4. test.h +28 −30
otf.h.in+5−5
@@ -94,19 +94,19 @@ void otfclose(Otf *o); · 93 unmodified lines
9494
9595 /* FIXME these might go eventually */
9696
97+typedef struct Glyf Glyf;
9798 typedef struct GlyfImage GlyfImage;
9899
99100 struct GlyfImage {
100− u8int *b;
101101 int w;
102102 int h;
103103 int baseline;
104+ u8int b[];
104105 };
105106
106−typedef struct Glyf Glyf;
107−Glyf *otfglyf(Otf *o, int index);
108107 int otfglyfnum(Otf *o);
109−int otfdrawglyf(Otf *o, Glyf *g, double ppem, GlyfImage *im);
110−int otfupem(Otf *o);
111108 int otfrune2glyph(Otf *o, Rune r);
112109 Rune otfglyph2rune(Otf *o, int g);
110+
111+Glyf *otfglyf(Otf *o, int index);
112+GlyfImage *otfdrawglyf(Otf *o, Glyf *g, double ppem);
plan9/otf.h+5−5
@@ -95,23 +95,23 @@ void otfclose(Otf *o); · 94 unmodified lines
9595
9696 /* FIXME these might go eventually */
9797
98+typedef struct Glyf Glyf;
9899 typedef struct GlyfImage GlyfImage;
99100
100101 struct GlyfImage {
101− u8int *b;
102102 int w;
103103 int h;
104104 int baseline;
105+ u8int b[];
105106 };
106107
107−typedef struct Glyf Glyf;
108−Glyf *otfglyf(Otf *o, int index);
109108 int otfglyfnum(Otf *o);
110−int otfdrawglyf(Otf *o, Glyf *g, double ppem, GlyfImage *im);
111−int otfupem(Otf *o);
112109 int otfrune2glyph(Otf *o, Rune r);
113110 Rune otfglyph2rune(Otf *o, int g);
114111
112+Glyf *otfglyf(Otf *o, int index);
113+GlyfImage *otfdrawglyf(Otf *o, Glyf *g, double ppem);
114+
115115 typedef struct SubHeader SubHeader;
116116 typedef struct MapGroup MapGroup;
117117 typedef struct SubtableCmap0 SubtableCmap0;
rast.c+19−15
@@ -547,20 +547,21 @@ glyfmaxnpts(Glyf *g) · 546 unmodified lines
547547 return npts < 2 ? 0 : npts;
548548 }
549549
550−int
551−otfdrawglyf(Otf *o, Glyf *g, double ppem, GlyfImage *im)
550+GlyfImage *
551+otfdrawglyf(Otf *o, Glyf *g, double ppem)
552552 {
553− int i, j, maxptstotal, maxpts, ngs, w, h, r, npx, baseline;
553+ int i, j, maxptstotal, maxpts, ngs, w, h, npx, baseline;
554554 Glyf *gs[MAXCOMPONENTS];
555555 ComponentGlyph *cg;
556556 Sval scale, offY;
557557 SegQ *s₀, *s, *p;
558+ GlyfImage *im;
559+ Sval bb[4];
558560 Spt *pts;
559− u8int *b;
560561
561− r = -1;
562562 ngs = 0;
563563 pts = nil;
564+ im = nil;
564565
565566 if(g->simple != nil){
566567 gs[ngs++] = g;
@@ -587,9 +588,12 @@ FIXME metrics (lsb+rsb) · 20 unmodified lines
587588 }
588589 */
589590
590− scale = ppem / o->td.head->unitsPerEm;
591− Sval bb[4] = {g->xMin*scale, g->yMin*scale, g->xMax*scale, g->yMax*scale};
592591 pts = calloc(1, maxpts*sizeof(*pts) + maxptstotal/2*sizeof(*s));
592+ scale = ppem / o->td.head->unitsPerEm;
593+ bb[0] = g->xMin*scale;
594+ bb[1] = g->yMin*scale;
595+ bb[2] = g->xMax*scale;
596+ bb[3] = g->yMax*scale;
593597 s = s₀ = (SegQ*)(pts + maxpts);
594598 cg = g->component;
595599 for(i = 0; i < ngs; i++){
@@ -656,16 +660,16 @@ FIXME metrics (lsb+rsb) · 60 unmodified lines
656660 }
657661
658662 npx = w*h;
659− b = malloc(npx);
660− b[0] = 0;
661− if(qbzr(s₀, s-s₀, w, h, b) == 0){
662− im->b = b;
663+ im = malloc(sizeof(*im) + npx);
664+ im->b[0] = 0;
665+ if(qbzr(s₀, s-s₀, w, h, im->b) == 0){
663666 im->w = w;
664667 im->h = h;
665668 im->baseline = baseline;
666− r = 0;
667− }else
668− free(b);
669+ }else{
670+ free(im);
671+ im = nil;
672+ }
669673
670674 done:
671675 for(i = 0; i < ngs; i++){
@@ -673,5 +677,5 @@ done: · 1 unmodified line
673677 free(gs[i]);
674678 }
675679 free(pts);
676− return r;
680+ return im;
677681 }
test.h+28−30
@@ -19,7 +19,7 @@ static double ppem; · 18 unmodified lines
1919 static Rune rune = NoRune;
2020
2121 static int
22−dumpmap(Otfile *f, GlyfImage *im, int n)
22+dumpmap(Otfile *f, GlyfImage **im, int n)
2323 {
2424 int x, y, i, j, t, maxh, prebase, postbase, d, border;
2525 int gap, total, mid, npix, bw, bh, lines, fill;
@@ -31,20 +31,20 @@ dumpmap(Otfile *f, GlyfImage *im, int n) · 5 unmodified lines
3131 fill = map > 2;
3232 if(n == 1){
3333 gap = 8;
34− maxh = im->h;
35− if(im->baseline)
36− maxh += im->baseline;
37− bw = 2*gap + im->w;
34+ maxh = im[0]->h;
35+ if(im[0]->baseline)
36+ maxh += im[0]->baseline;
37+ bw = 2*gap + im[0]->w;
3838 bh = 2*gap + maxh;
3939 npix = bw * bh;
4040 }else{
4141 gap = 1;
4242 for(i = 0; i < n; i++){
43− if(im[i].b == nil)
43+ if(im[i] == nil)
4444 continue;
45− if(maxh < im[i].h)
46− maxh = im[i].h;
47− total += im[i].w;
45+ if(maxh < im[i]->h)
46+ maxh = im[i]->h;
47+ total += im[i]->w;
4848 }
4949 mid = total / n;
5050 npix = (mid+gap)*(maxh+gap)*n;
@@ -61,31 +61,29 @@ dumpmap(Otfile *f, GlyfImage *im, int n) · 10 unmodified lines
6161 for(i = 0; i < n;){
6262 prebase = postbase = 0;
6363 for(x = 0, j = i; j < n; j++){
64− if(im[j].b == nil)
64+ if(im[j] == nil)
6565 continue;
66− x += im[j].w + gap;
66+ x += im[j]->w + gap;
6767 if(x > bw)
6868 break;
69− if(prebase < im[j].h+im[j].baseline)
70− prebase = im[j].h+im[j].baseline;
71− if(im[j].baseline < 0 && postbase < -im[j].baseline)
72− postbase = -im[j].baseline;
69+ if(prebase < im[j]->h+im[j]->baseline)
70+ prebase = im[j]->h+im[j]->baseline;
71+ if(im[j]->baseline < 0 && postbase < -im[j]->baseline)
72+ postbase = -im[j]->baseline;
7373 }
7474 maxh = prebase + postbase;
7575 if(j == i || y+maxh > bh)
7676 break;
7777
7878 for(x = 0; i < j; i++){
79− if(im[i].b == nil)
80− continue;
81− u8int *lt = b + ((y + prebase - (im[i].h+im[i].baseline))*bw + x)*3;
82− x += im[i].w + gap;
83− for(d = 0; d < im[i].h; d++, lt += bw*3){
84− for(t = 0; t < im[i].w; t++){
79+ u8int *lt = b + ((y + prebase - (im[i]->h+im[i]->baseline))*bw + x)*3;
80+ x += im[i]->w + gap;
81+ for(d = 0; d < im[i]->h; d++, lt += bw*3){
82+ for(t = 0; t < im[i]->w; t++){
8583 u8int r, g, b;
86− r = g = b = im[i].b[d*im[i].w + t];
87− border = d == 0 || t == 0 || t == im[i].w-1 || d == im[i].h-1;
88− if((lines || highlight == i) && g == 0xff && (d == im[i].h+im[i].baseline)){
84+ r = g = b = im[i]->b[d*im[i]->w + t];
85+ border = d == 0 || t == 0 || t == im[i]->w-1 || d == im[i]->h-1;
86+ if((lines || highlight == i) && g == 0xff && (d == im[i]->h+im[i]->baseline)){
8987 g = 0;
9088 b = 0;
9189 }else if((lines || highlight == i) && g == 0xff && (fill || border)){
@@ -117,7 +115,7 @@ dumpmap(Otfile *f, GlyfImage *im, int n) · 25 unmodified lines
117115 static int
118116 process(Otfile *in, Otfile *out)
119117 {
120− GlyfImage *im;
118+ GlyfImage **im;
121119 int i, n;
122120 Glyf *g;
123121 Otf *o;
@@ -150,7 +148,7 @@ glypherr: · 26 unmodified lines
150148 return -1;
151149 }
152150 if(ppem > 0 && g->numberOfContours != 0){
153− if(otfdrawglyf(o, g, ppem, im+i) != 0)
151+ if((im[i] = otfdrawglyf(o, g, ppem)) == nil)
154152 goto glypherr;
155153 }else if(ppem <= 0){
156154 out->print(out->aux, "%d (%s):\n", i,
@@ -163,7 +161,7 @@ glypherr: · 6 unmodified lines
163161 if(out->write != otfdiscard && dumpmap(out, im, n) != 0)
164162 return -1;
165163 for(i = 0; i < n; i++)
166− free(im[i].b);
164+ free(im[i]);
167165 free(im);
168166 }
169167 }else if(gind < 0){
@@ -172,12 +170,12 @@ glypherr: · 2 unmodified lines
172170 if((g = otfglyf(o, gind)) == nil){
173171 goto glypherr;
174172 }else if(ppem > 0){
175− GlyfImage im;
176− if(otfdrawglyf(o, g, ppem, &im) != 0)
173+ GlyfImage *im;
174+ if((im = otfdrawglyf(o, g, ppem)) == nil)
177175 goto glypherr;
178176 if(out->write != otfdiscard && dumpmap(out, &im, 1) != 0)
179177 return -1;
180− free(im.b);
178+ free(im);
181179 }else{
182180 out->print(out->aux, "\n%d:\n", gind);
183181 print_Glyf(out, indentΔ, o, g);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t