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
94 94
95/* FIXME these might go eventually */95/* FIXME these might go eventually */
96 96
97typedef struct Glyf Glyf;
97typedef struct GlyfImage GlyfImage;98typedef struct GlyfImage GlyfImage;
98 99
99struct GlyfImage {100struct GlyfImage {
100 u8int *b;
101 int w;101 int w;
102 int h;102 int h;
103 int baseline;103 int baseline;
104 u8int b[];
104};105};
105 106
106typedef struct Glyf Glyf;
107Glyf *otfglyf(Otf *o, int index);
108int otfglyfnum(Otf *o);107int otfglyfnum(Otf *o);
109int otfdrawglyf(Otf *o, Glyf *g, double ppem, GlyfImage *im);
110int otfupem(Otf *o);
111int otfrune2glyph(Otf *o, Rune r);108int otfrune2glyph(Otf *o, Rune r);
112Rune otfglyph2rune(Otf *o, int g);109Rune otfglyph2rune(Otf *o, int g);
110
111Glyf *otfglyf(Otf *o, int index);
112GlyfImage *otfdrawglyf(Otf *o, Glyf *g, double ppem);
plan9/otf.h+5−5
@@ -95,23 +95,23 @@ void otfclose(Otf *o); · 94 unmodified lines
95 95
96/* FIXME these might go eventually */96/* FIXME these might go eventually */
97 97
98typedef struct Glyf Glyf;
98typedef struct GlyfImage GlyfImage;99typedef struct GlyfImage GlyfImage;
99 100
100struct GlyfImage {101struct GlyfImage {
101 u8int *b;
102 int w;102 int w;
103 int h;103 int h;
104 int baseline;104 int baseline;
105 u8int b[];
105};106};
106 107
107typedef struct Glyf Glyf;
108Glyf *otfglyf(Otf *o, int index);
109int otfglyfnum(Otf *o);108int otfglyfnum(Otf *o);
110int otfdrawglyf(Otf *o, Glyf *g, double ppem, GlyfImage *im);
111int otfupem(Otf *o);
112int otfrune2glyph(Otf *o, Rune r);109int otfrune2glyph(Otf *o, Rune r);
113Rune otfglyph2rune(Otf *o, int g);110Rune otfglyph2rune(Otf *o, int g);
114 111
112Glyf *otfglyf(Otf *o, int index);
113GlyfImage *otfdrawglyf(Otf *o, Glyf *g, double ppem);
114
115typedef struct SubHeader SubHeader;115typedef struct SubHeader SubHeader;
116typedef struct MapGroup MapGroup;116typedef struct MapGroup MapGroup;
117typedef struct SubtableCmap0 SubtableCmap0;117typedef struct SubtableCmap0 SubtableCmap0;
rast.c+19−15
@@ -547,20 +547,21 @@ glyfmaxnpts(Glyf *g) · 546 unmodified lines
547 return npts < 2 ? 0 : npts;547 return npts < 2 ? 0 : npts;
548}548}
549 549
550int550GlyfImage *
551otfdrawglyf(Otf *o, Glyf *g, double ppem, GlyfImage *im)551otfdrawglyf(Otf *o, Glyf *g, double ppem)
552{552{
553 int i, j, maxptstotal, maxpts, ngs, w, h, r, npx, baseline;553 int i, j, maxptstotal, maxpts, ngs, w, h, npx, baseline;
554 Glyf *gs[MAXCOMPONENTS];554 Glyf *gs[MAXCOMPONENTS];
555 ComponentGlyph *cg;555 ComponentGlyph *cg;
556 Sval scale, offY;556 Sval scale, offY;
557 SegQ *s₀, *s, *p;557 SegQ *s₀, *s, *p;
558 GlyfImage *im;
559 Sval bb[4];
558 Spt *pts;560 Spt *pts;
559 u8int *b;
560 561
561 r = -1;
562 ngs = 0;562 ngs = 0;
563 pts = nil;563 pts = nil;
564 im = nil;
564 565
565 if(g->simple != nil){566 if(g->simple != nil){
566 gs[ngs++] = g;567 gs[ngs++] = g;
@@ -587,9 +588,12 @@ FIXME metrics (lsb+rsb) · 20 unmodified lines
587 }588 }
588*/589*/
589 590
590 scale = ppem / o->td.head->unitsPerEm;
591 Sval bb[4] = {g->xMin*scale, g->yMin*scale, g->xMax*scale, g->yMax*scale};
592 pts = calloc(1, maxpts*sizeof(*pts) + maxptstotal/2*sizeof(*s));591 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;
593 s = s₀ = (SegQ*)(pts + maxpts);597 s = s₀ = (SegQ*)(pts + maxpts);
594 cg = g->component;598 cg = g->component;
595 for(i = 0; i < ngs; i++){599 for(i = 0; i < ngs; i++){
@@ -656,16 +660,16 @@ FIXME metrics (lsb+rsb) · 60 unmodified lines
656 }660 }
657 661
658 npx = w*h;662 npx = w*h;
659 b = malloc(npx);663 im = malloc(sizeof(*im) + npx);
660 b[0] = 0;664 im->b[0] = 0;
661 if(qbzr(s₀, s-s₀, w, h, b) == 0){665 if(qbzr(s₀, s-s₀, w, h, im->b) == 0){
662 im->b = b;
663 im->w = w;666 im->w = w;
664 im->h = h;667 im->h = h;
665 im->baseline = baseline;668 im->baseline = baseline;
666 r = 0;669 }else{
667 }else670 free(im);
668 free(b);671 im = nil;
672 }
669 673
670done:674done:
671 for(i = 0; i < ngs; i++){675 for(i = 0; i < ngs; i++){
@@ -673,5 +677,5 @@ done: · 1 unmodified line
673 free(gs[i]);677 free(gs[i]);
674 }678 }
675 free(pts);679 free(pts);
676 return r;680 return im;
677}681}
test.h+28−30
@@ -19,7 +19,7 @@ static double ppem; · 18 unmodified lines
19static Rune rune = NoRune;19static Rune rune = NoRune;
20 20
21static int21static int
22dumpmap(Otfile *f, GlyfImage *im, int n)22dumpmap(Otfile *f, GlyfImage **im, int n)
23{23{
24 int x, y, i, j, t, maxh, prebase, postbase, d, border;24 int x, y, i, j, t, maxh, prebase, postbase, d, border;
25 int gap, total, mid, npix, bw, bh, lines, fill;25 int gap, total, mid, npix, bw, bh, lines, fill;
@@ -31,20 +31,20 @@ dumpmap(Otfile *f, GlyfImage *im, int n) · 5 unmodified lines
31 fill = map > 2;31 fill = map > 2;
32 if(n == 1){32 if(n == 1){
33 gap = 8;33 gap = 8;
34 maxh = im->h;34 maxh = im[0]->h;
35 if(im->baseline)35 if(im[0]->baseline)
36 maxh += im->baseline;36 maxh += im[0]->baseline;
37 bw = 2*gap + im->w;37 bw = 2*gap + im[0]->w;
38 bh = 2*gap + maxh;38 bh = 2*gap + maxh;
39 npix = bw * bh;39 npix = bw * bh;
40 }else{40 }else{
41 gap = 1;41 gap = 1;
42 for(i = 0; i < n; i++){42 for(i = 0; i < n; i++){
43 if(im[i].b == nil)43 if(im[i] == nil)
44 continue;44 continue;
45 if(maxh < im[i].h)45 if(maxh < im[i]->h)
46 maxh = im[i].h;46 maxh = im[i]->h;
47 total += im[i].w;47 total += im[i]->w;
48 }48 }
49 mid = total / n;49 mid = total / n;
50 npix = (mid+gap)*(maxh+gap)*n;50 npix = (mid+gap)*(maxh+gap)*n;
@@ -61,31 +61,29 @@ dumpmap(Otfile *f, GlyfImage *im, int n) · 10 unmodified lines
61 for(i = 0; i < n;){61 for(i = 0; i < n;){
62 prebase = postbase = 0;62 prebase = postbase = 0;
63 for(x = 0, j = i; j < n; j++){63 for(x = 0, j = i; j < n; j++){
64 if(im[j].b == nil)64 if(im[j] == nil)
65 continue;65 continue;
66 x += im[j].w + gap;66 x += im[j]->w + gap;
67 if(x > bw)67 if(x > bw)
68 break;68 break;
69 if(prebase < im[j].h+im[j].baseline)69 if(prebase < im[j]->h+im[j]->baseline)
70 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)71 if(im[j]->baseline < 0 && postbase < -im[j]->baseline)
72 postbase = -im[j].baseline;72 postbase = -im[j]->baseline;
73 }73 }
74 maxh = prebase + postbase;74 maxh = prebase + postbase;
75 if(j == i || y+maxh > bh)75 if(j == i || y+maxh > bh)
76 break;76 break;
77 77
78 for(x = 0; i < j; i++){78 for(x = 0; i < j; i++){
79 if(im[i].b == nil)79 u8int *lt = b + ((y + prebase - (im[i]->h+im[i]->baseline))*bw + x)*3;
80 continue;80 x += im[i]->w + gap;
81 u8int *lt = b + ((y + prebase - (im[i].h+im[i].baseline))*bw + x)*3;81 for(d = 0; d < im[i]->h; d++, lt += bw*3){
82 x += im[i].w + gap;82 for(t = 0; t < im[i]->w; t++){
83 for(d = 0; d < im[i].h; d++, lt += bw*3){
84 for(t = 0; t < im[i].w; t++){
85 u8int r, g, b;83 u8int r, g, b;
86 r = g = b = im[i].b[d*im[i].w + t];84 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;85 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)){86 if((lines || highlight == i) && g == 0xff && (d == im[i]->h+im[i]->baseline)){
89 g = 0;87 g = 0;
90 b = 0;88 b = 0;
91 }else if((lines || highlight == i) && g == 0xff && (fill || border)){89 }else if((lines || highlight == i) && g == 0xff && (fill || border)){
@@ -117,7 +115,7 @@ dumpmap(Otfile *f, GlyfImage *im, int n) · 25 unmodified lines
117static int115static int
118process(Otfile *in, Otfile *out)116process(Otfile *in, Otfile *out)
119{117{
120 GlyfImage *im;118 GlyfImage **im;
121 int i, n;119 int i, n;
122 Glyf *g;120 Glyf *g;
123 Otf *o;121 Otf *o;
@@ -150,7 +148,7 @@ glypherr: · 26 unmodified lines
150 return -1;148 return -1;
151 }149 }
152 if(ppem > 0 && g->numberOfContours != 0){150 if(ppem > 0 && g->numberOfContours != 0){
153 if(otfdrawglyf(o, g, ppem, im+i) != 0)151 if((im[i] = otfdrawglyf(o, g, ppem)) == nil)
154 goto glypherr;152 goto glypherr;
155 }else if(ppem <= 0){153 }else if(ppem <= 0){
156 out->print(out->aux, "%d (%s):\n", i,154 out->print(out->aux, "%d (%s):\n", i,
@@ -163,7 +161,7 @@ glypherr: · 6 unmodified lines
163 if(out->write != otfdiscard && dumpmap(out, im, n) != 0)161 if(out->write != otfdiscard && dumpmap(out, im, n) != 0)
164 return -1;162 return -1;
165 for(i = 0; i < n; i++)163 for(i = 0; i < n; i++)
166 free(im[i].b);164 free(im[i]);
167 free(im);165 free(im);
168 }166 }
169 }else if(gind < 0){167 }else if(gind < 0){
@@ -172,12 +170,12 @@ glypherr: · 2 unmodified lines
172 if((g = otfglyf(o, gind)) == nil){170 if((g = otfglyf(o, gind)) == nil){
173 goto glypherr;171 goto glypherr;
174 }else if(ppem > 0){172 }else if(ppem > 0){
175 GlyfImage im;173 GlyfImage *im;
176 if(otfdrawglyf(o, g, ppem, &im) != 0)174 if((im = otfdrawglyf(o, g, ppem)) == nil)
177 goto glypherr;175 goto glypherr;
178 if(out->write != otfdiscard && dumpmap(out, &im, 1) != 0)176 if(out->write != otfdiscard && dumpmap(out, &im, 1) != 0)
179 return -1;177 return -1;
180 free(im.b);178 free(im);
181 }else{179 }else{
182 out->print(out->aux, "\n%d:\n", gind);180 out->print(out->aux, "\n%d:\n", gind);
183 print_Glyf(out, indentΔ, o, g);181 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