History

split ranges based on line width to make compression possible

Sigrid Solveig Haflínudóttir committed 3 years ago

Commit bb1bf1e1 parent 89f944a2 files · +33 −3Browse files

Unified · Split

2 files
  1. charset.c +1 −1
  2. ttfs.c +32 −2
charset.c+1−1
@@ -8,7 +8,7 @@ · 7 unmodified lines
88 #include "common.h"
99
1010 enum {
11− Maxrange = 0x7ff,
11+ Maxrange = 0x1fff,
1212 };
1313
1414 Range *
ttfs.c+32−2
@@ -14,6 +14,7 @@ · 13 unmodified lines
1414
1515 enum {
1616 Substitute = 0xfffd,
17+ Maxsubfwidth = 3000, /* rough */
1718 };
1819
1920 static uint8_t pjw[] = {
@@ -102,7 +103,7 @@ err2: · 82 unmodified lines
102103 int
103104 main(int argc, char **argv)
104105 {
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;
106107 struct parg_state ps;
107108 Range *ranges, *rn;
108109 char *ofile, *s;
@@ -233,7 +234,36 @@ usage: · 124 unmodified lines
233234 return 1;
234235
235236 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;
237267 SDL_Surface *g, *line;
238268 Fontchar *cs;
239269 SDL_Rect dst;

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