| @@ -14,6 +14,7 @@ · 13 unmodified lines |
| 14 | 14 | |
| 15 | 15 | enum { |
| 16 | 16 | Substitute = 0xfffd, |
| 17 | + Maxsubfwidth = 3000, /* rough */ |
| 17 | 18 | }; |
| 18 | 19 | |
| 19 | 20 | static uint8_t pjw[] = { |
| @@ -102,7 +103,7 @@ err2: · 82 unmodified lines |
| 102 | 103 | int |
| 103 | 104 | main(int argc, char **argv) |
| 104 | 105 | { |
| 105 | | − int c, optend, nr, i, fdfont, h, maxh, pjwface, hdr, usemaxh; |
| 106 | + int c, optend, nr, i, fdfont, minx, maxx, advance, dummy, w, h, maxh, pjwface, hdr, usemaxh; |
| 106 | 107 | struct parg_state ps; |
| 107 | 108 | Range *ranges, *rn; |
| 108 | 109 | char *ofile, *s; |
| @@ -233,7 +234,36 @@ usage: · 124 unmodified lines |
| 233 | 234 | return 1; |
| 234 | 235 | |
| 235 | 236 | for(i = 0; i < nr; i++){ |
| 236 | | − int minx, maxx, dummy, advance, ncs, w, x, y; |
| 237 | + rn = ranges+i; |
| 238 | + w = 0; |
| 239 | + for(r = rn->min; r <= rn->max; r++){ |
| 240 | + if(TTF_GlyphMetrics32(f, r, &minx, &maxx, &dummy, &dummy, &advance) == 0){ |
| 241 | + if((c = maxx-minx) < advance) |
| 242 | + c = advance; |
| 243 | + if(w+c > Maxsubfwidth){ |
| 244 | + /* subfont too wide - split the range */ |
| 245 | + ranges = realloc(ranges, (nr+1)*sizeof(Range)); |
| 246 | + rn = ranges+i; |
| 247 | + memmove(rn+1, rn, (nr-i)*sizeof(Range)); |
| 248 | + rn[0].max = r-1; |
| 249 | + rn[1].min = r; |
| 250 | + nr++; |
| 251 | + break; |
| 252 | + } |
| 253 | + w += c; |
| 254 | + } |
| 255 | + } |
| 256 | + |
| 257 | + if(w == 0){ |
| 258 | + /* skip zero-width subfonts altogether */ |
| 259 | + memmove(rn, rn+1, (nr-i-1)*sizeof(Range)); |
| 260 | + nr--; |
| 261 | + i--; |
| 262 | + } |
| 263 | + } |
| 264 | + |
| 265 | + for(i = 0; i < nr; i++){ |
| 266 | + int ncs, x, y; |
| 237 | 267 | SDL_Surface *g, *line; |
| 238 | 268 | Fontchar *cs; |
| 239 | 269 | SDL_Rect dst; |