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
8#include "common.h"8#include "common.h"
9 9
10enum {10enum {
11 Maxrange = 0x7ff,11 Maxrange = 0x1fff,
12};12};
13 13
14Range *14Range *
ttfs.c+32−2
@@ -14,6 +14,7 @@ · 13 unmodified lines
14 14
15enum {15enum {
16 Substitute = 0xfffd,16 Substitute = 0xfffd,
17 Maxsubfwidth = 3000, /* rough */
17};18};
18 19
19static uint8_t pjw[] = {20static uint8_t pjw[] = {
@@ -102,7 +103,7 @@ err2: · 82 unmodified lines
102int103int
103main(int argc, char **argv)104main(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 struct parg_state ps;107 struct parg_state ps;
107 Range *ranges, *rn;108 Range *ranges, *rn;
108 char *ofile, *s;109 char *ofile, *s;
@@ -233,7 +234,36 @@ usage: · 124 unmodified lines
233 return 1;234 return 1;
234 235
235 for(i = 0; i < nr; i++){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 SDL_Surface *g, *line;267 SDL_Surface *g, *line;
238 Fontchar *cs;268 Fontchar *cs;
239 SDL_Rect dst;269 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