diff options
-rw-r--r-- | apps/plugins/lib/gray_putsxy.c | 2 | ||||
-rw-r--r-- | firmware/drivers/lcd-recorder.c | 4 | ||||
-rw-r--r-- | firmware/export/font.h | 9 | ||||
-rw-r--r-- | firmware/font.c | 146 | ||||
-rw-r--r-- | tools/convbdf.c | 175 |
5 files changed, 169 insertions, 167 deletions
diff --git a/apps/plugins/lib/gray_putsxy.c b/apps/plugins/lib/gray_putsxy.c index 51f1ca166a..20af8a3cbf 100644 --- a/apps/plugins/lib/gray_putsxy.c +++ b/apps/plugins/lib/gray_putsxy.c | |||
@@ -37,7 +37,7 @@ | |||
37 | void gray_putsxy(int x, int y, const unsigned char *str) | 37 | void gray_putsxy(int x, int y, const unsigned char *str) |
38 | { | 38 | { |
39 | int ch, width; | 39 | int ch, width; |
40 | bitmap_t *bits; | 40 | unsigned char *bits; |
41 | struct font *pf = _graybuf->curfont; | 41 | struct font *pf = _graybuf->curfont; |
42 | 42 | ||
43 | if ((unsigned) x >= (unsigned) _graybuf->width | 43 | if ((unsigned) x >= (unsigned) _graybuf->width |
diff --git a/firmware/drivers/lcd-recorder.c b/firmware/drivers/lcd-recorder.c index c9781e77ef..a791a79f4c 100644 --- a/firmware/drivers/lcd-recorder.c +++ b/firmware/drivers/lcd-recorder.c | |||
@@ -407,14 +407,14 @@ static void lcd_putsxyofs(int x, int y, int ofs, const unsigned char *str) | |||
407 | if (width > 0) | 407 | if (width > 0) |
408 | { | 408 | { |
409 | unsigned int i; | 409 | unsigned int i; |
410 | bitmap_t* bits = pf->bits + | 410 | unsigned char* bits = pf->bits + |
411 | (pf->offset ? pf->offset[ch] : (pf->height * ch)); | 411 | (pf->offset ? pf->offset[ch] : (pf->height * ch)); |
412 | 412 | ||
413 | if (ofs != 0) | 413 | if (ofs != 0) |
414 | { | 414 | { |
415 | for (i = 0; i < pf->height; i += 8) | 415 | for (i = 0; i < pf->height; i += 8) |
416 | { | 416 | { |
417 | lcd_bitmap (((unsigned char*) bits) + ofs, x, y + i, width, | 417 | lcd_bitmap (bits + ofs, x, y + i, width, |
418 | MIN(8, pf->height - i), true); | 418 | MIN(8, pf->height - i), true); |
419 | bits = (bitmap_t *)((int)bits + gwidth); | 419 | bits = (bitmap_t *)((int)bits + gwidth); |
420 | } | 420 | } |
diff --git a/firmware/export/font.h b/firmware/export/font.h index 14a683a5f2..fff7d05c0b 100644 --- a/firmware/export/font.h +++ b/firmware/export/font.h | |||
@@ -72,7 +72,7 @@ enum { | |||
72 | */ | 72 | */ |
73 | 73 | ||
74 | /* loadable font magic and version #*/ | 74 | /* loadable font magic and version #*/ |
75 | #define VERSION "RB11" | 75 | #define VERSION "RB12" |
76 | 76 | ||
77 | typedef unsigned short bitmap_t; /* bitmap image unit size*/ | 77 | typedef unsigned short bitmap_t; /* bitmap image unit size*/ |
78 | 78 | ||
@@ -88,15 +88,14 @@ typedef unsigned short bitmap_t; /* bitmap image unit size*/ | |||
88 | /* builtin C-based proportional/fixed font structure */ | 88 | /* builtin C-based proportional/fixed font structure */ |
89 | /* based on The Microwindows Project http://microwindows.org */ | 89 | /* based on The Microwindows Project http://microwindows.org */ |
90 | struct font { | 90 | struct font { |
91 | char * name; /* font name*/ | ||
92 | int maxwidth; /* max width in pixels*/ | 91 | int maxwidth; /* max width in pixels*/ |
93 | unsigned int height; /* height in pixels*/ | 92 | unsigned int height; /* height in pixels*/ |
94 | int ascent; /* ascent (baseline) height*/ | 93 | int ascent; /* ascent (baseline) height*/ |
95 | int firstchar; /* first character in bitmap*/ | 94 | int firstchar; /* first character in bitmap*/ |
96 | int size; /* font size in glyphs*/ | 95 | int size; /* font size in glyphs*/ |
97 | bitmap_t *bits; /* 16-bit right-padded bitmap data*/ | 96 | const unsigned char *bits; /* 8-bit column bitmap data*/ |
98 | unsigned long *offset; /* offsets into bitmap data*/ | 97 | const unsigned short *offset; /* offsets into bitmap data*/ |
99 | unsigned char *width; /* character widths or NULL if fixed*/ | 98 | const unsigned char *width; /* character widths or NULL if fixed*/ |
100 | int defaultchar; /* default char (not glyph index)*/ | 99 | int defaultchar; /* default char (not glyph index)*/ |
101 | long bits_size; /* # words of bitmap_t bits*/ | 100 | long bits_size; /* # words of bitmap_t bits*/ |
102 | }; | 101 | }; |
diff --git a/firmware/font.c b/firmware/font.c index 343dd0b278..9d46e0d4ce 100644 --- a/firmware/font.c +++ b/firmware/font.c | |||
@@ -53,15 +53,8 @@ static unsigned char *freeptr = mbuf; | |||
53 | static unsigned char *fileptr; | 53 | static unsigned char *fileptr; |
54 | static unsigned char *eofptr; | 54 | static unsigned char *eofptr; |
55 | 55 | ||
56 | static void rotate_font_bits(const struct font* pf); | ||
57 | static void rotleft(unsigned char *dst, | ||
58 | const bitmap_t *src, | ||
59 | unsigned int width, | ||
60 | unsigned int height); | ||
61 | |||
62 | void font_init(void) | 56 | void font_init(void) |
63 | { | 57 | { |
64 | rotate_font_bits(&sysfont); | ||
65 | memset(&font_ui, 0, sizeof(struct font)); | 58 | memset(&font_ui, 0, sizeof(struct font)); |
66 | } | 59 | } |
67 | 60 | ||
@@ -95,25 +88,6 @@ static int readstr(char *buf, int count) | |||
95 | return (fileptr <= eofptr)? count: 0; | 88 | return (fileptr <= eofptr)? count: 0; |
96 | } | 89 | } |
97 | 90 | ||
98 | /* read totlen bytes, return NUL terminated string*/ | ||
99 | /* may write 1 past buf[totlen]; removes blank pad*/ | ||
100 | static int readstrpad(char *buf, int totlen) | ||
101 | { | ||
102 | char *p = buf; | ||
103 | int n = totlen; | ||
104 | |||
105 | while (--n >= 0) | ||
106 | *p++ = *fileptr++; | ||
107 | if (fileptr > eofptr) | ||
108 | return 0; | ||
109 | |||
110 | p = &buf[totlen]; | ||
111 | *p-- = 0; | ||
112 | while (*p == ' ' && p >= buf) | ||
113 | *p-- = '\0'; | ||
114 | return totlen; | ||
115 | } | ||
116 | |||
117 | void font_reset(void) | 91 | void font_reset(void) |
118 | { | 92 | { |
119 | memset(&font_ui, 0, sizeof(struct font)); | 93 | memset(&font_ui, 0, sizeof(struct font)); |
@@ -127,7 +101,6 @@ struct font* font_load(const char *path) | |||
127 | unsigned long firstchar, defaultchar, size; | 101 | unsigned long firstchar, defaultchar, size; |
128 | unsigned long i, nbits, noffset, nwidth; | 102 | unsigned long i, nbits, noffset, nwidth; |
129 | char version[4+1]; | 103 | char version[4+1]; |
130 | char copyright[256+1]; | ||
131 | struct font* pf = &font_ui; | 104 | struct font* pf = &font_ui; |
132 | 105 | ||
133 | /* open and read entire font file*/ | 106 | /* open and read entire font file*/ |
@@ -163,15 +136,6 @@ struct font* font_load(const char *path) | |||
163 | if (strcmp(version, VERSION) != 0) | 136 | if (strcmp(version, VERSION) != 0) |
164 | return NULL; | 137 | return NULL; |
165 | 138 | ||
166 | /* internal font name*/ | ||
167 | pf->name = fileptr; | ||
168 | if (readstrpad(pf->name, 64) != 64) | ||
169 | return NULL; | ||
170 | |||
171 | /* copyright, not currently stored*/ | ||
172 | if (readstrpad(copyright, 256) != 256) | ||
173 | return NULL; | ||
174 | |||
175 | /* font info*/ | 139 | /* font info*/ |
176 | if (!readshort(&maxwidth)) | 140 | if (!readshort(&maxwidth)) |
177 | return NULL; | 141 | return NULL; |
@@ -198,7 +162,6 @@ struct font* font_load(const char *path) | |||
198 | /* # words of bitmap_t*/ | 162 | /* # words of bitmap_t*/ |
199 | if (!readlong(&nbits)) | 163 | if (!readlong(&nbits)) |
200 | return NULL; | 164 | return NULL; |
201 | pf->bits_size = nbits; | ||
202 | 165 | ||
203 | /* # longs of offset*/ | 166 | /* # longs of offset*/ |
204 | if (!readlong(&noffset)) | 167 | if (!readlong(&noffset)) |
@@ -209,18 +172,21 @@ struct font* font_load(const char *path) | |||
209 | return NULL; | 172 | return NULL; |
210 | 173 | ||
211 | /* variable font data*/ | 174 | /* variable font data*/ |
212 | pf->bits = (bitmap_t *)fileptr; | 175 | pf->bits = (unsigned char *)fileptr; |
213 | for (i=0; i<nbits; ++i) | 176 | fileptr += nbits*sizeof(unsigned char); |
214 | if (!readshort(&pf->bits[i])) | 177 | |
215 | return NULL; | 178 | /* pad to 16 bit boundary*/ |
216 | /* pad to longword boundary*/ | 179 | fileptr = (unsigned char *)(((int)fileptr + 1) & ~1); |
217 | fileptr = (unsigned char *)(((int)fileptr + 3) & ~3); | ||
218 | 180 | ||
219 | if (noffset) { | 181 | if (noffset) { |
220 | pf->offset = (unsigned long *)fileptr; | 182 | pf->offset = (unsigned short *)fileptr; |
221 | for (i=0; i<noffset; ++i) | 183 | for (i=0; i<noffset; ++i) |
222 | if (!readlong(&pf->offset[i])) | 184 | { |
185 | unsigned short offset; | ||
186 | if (!readshort(&offset)) | ||
223 | return NULL; | 187 | return NULL; |
188 | ((unsigned short*)(pf->offset))[i] = (unsigned short)offset; | ||
189 | } | ||
224 | } | 190 | } |
225 | else | 191 | else |
226 | pf->offset = NULL; | 192 | pf->offset = NULL; |
@@ -235,9 +201,6 @@ struct font* font_load(const char *path) | |||
235 | if (fileptr > eofptr) | 201 | if (fileptr > eofptr) |
236 | return NULL; | 202 | return NULL; |
237 | 203 | ||
238 | /* one-time rotate font bits to rockbox format*/ | ||
239 | rotate_font_bits(pf); | ||
240 | |||
241 | return pf; /* success!*/ | 204 | return pf; /* success!*/ |
242 | } | 205 | } |
243 | 206 | ||
@@ -262,93 +225,6 @@ struct font* font_get(int font) | |||
262 | } | 225 | } |
263 | } | 226 | } |
264 | 227 | ||
265 | /* convert font bitmap data inplace to rockbox format*/ | ||
266 | static void rotate_font_bits(const struct font* pf) | ||
267 | { | ||
268 | int i; | ||
269 | unsigned long defaultchar = pf->defaultchar - pf->firstchar; | ||
270 | bool did_defaultchar = false; | ||
271 | unsigned char buf[256]; | ||
272 | |||
273 | for (i=0; i<pf->size; ++i) { | ||
274 | bitmap_t *bits = pf->bits + | ||
275 | (pf->offset ? pf->offset[i] : (pf->height * i)); | ||
276 | int width = pf->width? pf->width[i]: pf->maxwidth; | ||
277 | int src_bytes = BITMAP_BYTES(width) * pf->height; | ||
278 | |||
279 | /* | ||
280 | * Due to the way the offset map works, | ||
281 | * non-mapped characters are mapped to the default | ||
282 | * character, and shouldn't be rotated twice. | ||
283 | */ | ||
284 | |||
285 | if (pf->offset && pf->offset[i] == defaultchar) { | ||
286 | if (did_defaultchar) | ||
287 | continue; | ||
288 | did_defaultchar = true; | ||
289 | } | ||
290 | |||
291 | /* rotate left for lcd_bitmap function input*/ | ||
292 | rotleft(buf, bits, width, pf->height); | ||
293 | |||
294 | /* copy back into original location*/ | ||
295 | memcpy(bits, buf, src_bytes); | ||
296 | } | ||
297 | } | ||
298 | |||
299 | /* | ||
300 | * Take an bitmap_t bitmap and convert to Rockbox format. | ||
301 | * Used for converting font glyphs for the time being. | ||
302 | * Can use for standard X11 and Win32 images as well. | ||
303 | * See format description in lcd-recorder.c | ||
304 | * | ||
305 | * Doing it this way keeps fonts in standard formats, | ||
306 | * as well as keeping Rockbox hw bitmap format. | ||
307 | */ | ||
308 | static void rotleft(unsigned char *dst, const bitmap_t *src, | ||
309 | unsigned int width, unsigned int height) | ||
310 | { | ||
311 | unsigned int i,j; | ||
312 | unsigned int src_words; /* # words of input image*/ | ||
313 | unsigned int dst_mask; /* bit mask for destination */ | ||
314 | bitmap_t src_mask; /* bit mask for source */ | ||
315 | |||
316 | /* calc words of input image*/ | ||
317 | src_words = BITMAP_WORDS(width) * height; | ||
318 | |||
319 | /* clear background*/ | ||
320 | memset(dst, 0, ((height + 7) / 8) * width); | ||
321 | |||
322 | dst_mask = 1; | ||
323 | |||
324 | for (i=0; i < src_words; i++) { | ||
325 | |||
326 | /* calc src input bit*/ | ||
327 | src_mask = 1 << (sizeof (bitmap_t) * 8 - 1); | ||
328 | |||
329 | /* for each input column...*/ | ||
330 | for(j=0; j < width; j++) { | ||
331 | |||
332 | /* if set in input, set in rotated output */ | ||
333 | if (src[i] & src_mask) | ||
334 | dst[j] |= dst_mask; | ||
335 | |||
336 | src_mask >>= 1; /* next input bit */ | ||
337 | if (src_mask == 0) /* input word done? */ | ||
338 | { | ||
339 | src_mask = 1 << (sizeof (bitmap_t) * 8 - 1); | ||
340 | i++; /* next input word */ | ||
341 | } | ||
342 | } | ||
343 | |||
344 | dst_mask <<= 1; /* next output bit (row) */ | ||
345 | if (dst_mask > (1 << 7)) /* output bit > 7? */ | ||
346 | { | ||
347 | dst_mask = 1; | ||
348 | dst += width; /* next output byte row */ | ||
349 | } | ||
350 | } | ||
351 | } | ||
352 | #endif /* HAVE_LCD_BITMAP */ | 228 | #endif /* HAVE_LCD_BITMAP */ |
353 | 229 | ||
354 | /* ----------------------------------------------------------------- | 230 | /* ----------------------------------------------------------------- |
diff --git a/tools/convbdf.c b/tools/convbdf.c index ac88ea889b..e369a91966 100644 --- a/tools/convbdf.c +++ b/tools/convbdf.c | |||
@@ -12,9 +12,15 @@ | |||
12 | #include <string.h> | 12 | #include <string.h> |
13 | #include <time.h> | 13 | #include <time.h> |
14 | 14 | ||
15 | #define ROTATE /* define this for the new, rotated format */ | ||
16 | |||
15 | /* BEGIN font.h*/ | 17 | /* BEGIN font.h*/ |
16 | /* loadable font magic and version #*/ | 18 | /* loadable font magic and version #*/ |
19 | #ifdef ROTATE | ||
20 | #define VERSION "RB12" /* newer version */ | ||
21 | #else | ||
17 | #define VERSION "RB11" | 22 | #define VERSION "RB11" |
23 | #endif | ||
18 | 24 | ||
19 | /* bitmap_t helper macros*/ | 25 | /* bitmap_t helper macros*/ |
20 | #define BITMAP_WORDS(x) (((x)+15)/16) /* image size in words*/ | 26 | #define BITMAP_WORDS(x) (((x)+15)/16) /* image size in words*/ |
@@ -30,7 +36,6 @@ typedef unsigned short bitmap_t; /* bitmap image unit size*/ | |||
30 | /* builtin C-based proportional/fixed font structure */ | 36 | /* builtin C-based proportional/fixed font structure */ |
31 | /* based on The Microwindows Project http://microwindows.org */ | 37 | /* based on The Microwindows Project http://microwindows.org */ |
32 | struct font { | 38 | struct font { |
33 | char * name; /* font name*/ | ||
34 | int maxwidth; /* max width in pixels*/ | 39 | int maxwidth; /* max width in pixels*/ |
35 | int height; /* height in pixels*/ | 40 | int height; /* height in pixels*/ |
36 | int ascent; /* ascent (baseline) height*/ | 41 | int ascent; /* ascent (baseline) height*/ |
@@ -43,6 +48,8 @@ struct font { | |||
43 | long bits_size; /* # words of bitmap_t bits*/ | 48 | long bits_size; /* # words of bitmap_t bits*/ |
44 | 49 | ||
45 | /* unused by runtime system, read in by convbdf*/ | 50 | /* unused by runtime system, read in by convbdf*/ |
51 | unsigned long* offrot; /* offsets into rotated bitmap data*/ | ||
52 | char * name; /* font name*/ | ||
46 | char * facename; /* facename of font*/ | 53 | char * facename; /* facename of font*/ |
47 | char * copyright; /* copyright info for loadable fonts*/ | 54 | char * copyright; /* copyright info for loadable fonts*/ |
48 | int pixel_size; | 55 | int pixel_size; |
@@ -259,6 +266,8 @@ void free_font(struct font* pf) | |||
259 | free(pf->bits); | 266 | free(pf->bits); |
260 | if (pf->offset) | 267 | if (pf->offset) |
261 | free(pf->offset); | 268 | free(pf->offset); |
269 | if (pf->offrot) | ||
270 | free(pf->offrot); | ||
262 | if (pf->width) | 271 | if (pf->width) |
263 | free(pf->width); | 272 | free(pf->width); |
264 | free(pf); | 273 | free(pf); |
@@ -426,9 +435,10 @@ int bdf_read_header(FILE *fp, struct font* pf) | |||
426 | /* allocate bits, offset, and width arrays*/ | 435 | /* allocate bits, offset, and width arrays*/ |
427 | pf->bits = (bitmap_t *)malloc(pf->bits_size * sizeof(bitmap_t) + EXTRA); | 436 | pf->bits = (bitmap_t *)malloc(pf->bits_size * sizeof(bitmap_t) + EXTRA); |
428 | pf->offset = (unsigned long *)malloc(pf->size * sizeof(unsigned long)); | 437 | pf->offset = (unsigned long *)malloc(pf->size * sizeof(unsigned long)); |
438 | pf->offrot = (unsigned long *)malloc(pf->size * sizeof(unsigned long)); | ||
429 | pf->width = (unsigned char *)malloc(pf->size * sizeof(unsigned char)); | 439 | pf->width = (unsigned char *)malloc(pf->size * sizeof(unsigned char)); |
430 | 440 | ||
431 | if (!pf->bits || !pf->offset || !pf->width) { | 441 | if (!pf->bits || !pf->offset || !pf->offrot || !pf->width) { |
432 | fprintf(stderr, "Error: no memory for font load\n"); | 442 | fprintf(stderr, "Error: no memory for font load\n"); |
433 | return 0; | 443 | return 0; |
434 | } | 444 | } |
@@ -440,6 +450,7 @@ int bdf_read_header(FILE *fp, struct font* pf) | |||
440 | int bdf_read_bitmaps(FILE *fp, struct font* pf) | 450 | int bdf_read_bitmaps(FILE *fp, struct font* pf) |
441 | { | 451 | { |
442 | long ofs = 0; | 452 | long ofs = 0; |
453 | long ofr = 0; | ||
443 | int maxwidth = 0; | 454 | int maxwidth = 0; |
444 | int i, k, encoding, width; | 455 | int i, k, encoding, width; |
445 | int bbw, bbh, bbx, bby; | 456 | int bbw, bbh, bbx, bby; |
@@ -504,6 +515,7 @@ int bdf_read_bitmaps(FILE *fp, struct font* pf) | |||
504 | continue; | 515 | continue; |
505 | } | 516 | } |
506 | pf->offset[encoding-pf->firstchar] = ofs; | 517 | pf->offset[encoding-pf->firstchar] = ofs; |
518 | pf->offrot[encoding-pf->firstchar] = ofr; | ||
507 | 519 | ||
508 | /* calc char width*/ | 520 | /* calc char width*/ |
509 | if (bbx < 0) { | 521 | if (bbx < 0) { |
@@ -560,6 +572,7 @@ int bdf_read_bitmaps(FILE *fp, struct font* pf) | |||
560 | } | 572 | } |
561 | 573 | ||
562 | ofs += BITMAP_WORDS(width) * pf->height; | 574 | ofs += BITMAP_WORDS(width) * pf->height; |
575 | ofr += pf->width[encoding-pf->firstchar] * ((pf->height+7)/8); | ||
563 | 576 | ||
564 | continue; | 577 | continue; |
565 | } | 578 | } |
@@ -576,6 +589,7 @@ int bdf_read_bitmaps(FILE *fp, struct font* pf) | |||
576 | 589 | ||
577 | if (pf->offset[i] == (unsigned long)-1) { | 590 | if (pf->offset[i] == (unsigned long)-1) { |
578 | pf->offset[i] = pf->offset[defchar]; | 591 | pf->offset[i] = pf->offset[defchar]; |
592 | pf->offrot[i] = pf->offrot[defchar]; | ||
579 | pf->width[i] = pf->width[defchar]; | 593 | pf->width[i] = pf->width[defchar]; |
580 | } | 594 | } |
581 | } | 595 | } |
@@ -622,6 +636,10 @@ int bdf_read_bitmaps(FILE *fp, struct font* pf) | |||
622 | } | 636 | } |
623 | } | 637 | } |
624 | 638 | ||
639 | #ifdef ROTATE | ||
640 | pf->bits_size = ofr; /* always update, rotated is smaller */ | ||
641 | #endif | ||
642 | |||
625 | return 1; | 643 | return 1; |
626 | } | 644 | } |
627 | 645 | ||
@@ -674,6 +692,62 @@ bitmap_t bdf_hexval(unsigned char *buf, int ndx1, int ndx2) | |||
674 | return val; | 692 | return val; |
675 | } | 693 | } |
676 | 694 | ||
695 | /* | ||
696 | * Take an bitmap_t bitmap and convert to Rockbox format. | ||
697 | * Used for converting font glyphs for the time being. | ||
698 | * Can use for standard X11 and Win32 images as well. | ||
699 | * See format description in lcd-recorder.c | ||
700 | * | ||
701 | * Doing it this way keeps fonts in standard formats, | ||
702 | * as well as keeping Rockbox hw bitmap format. | ||
703 | */ | ||
704 | int rotleft(unsigned char *dst, bitmap_t *src, unsigned int width, | ||
705 | unsigned int height) | ||
706 | { | ||
707 | unsigned int i,j; | ||
708 | unsigned int src_words; /* # words of input image*/ | ||
709 | unsigned int dst_mask; /* bit mask for destination */ | ||
710 | bitmap_t src_mask; /* bit mask for source */ | ||
711 | |||
712 | /* calc words of input image*/ | ||
713 | src_words = BITMAP_WORDS(width) * height; | ||
714 | |||
715 | /* clear background*/ | ||
716 | memset(dst, 0, ((height + 7) / 8) * width); | ||
717 | |||
718 | dst_mask = 1; | ||
719 | |||
720 | for (i=0; i < src_words; i++) { | ||
721 | |||
722 | /* calc src input bit*/ | ||
723 | src_mask = 1 << (sizeof (bitmap_t) * 8 - 1); | ||
724 | |||
725 | /* for each input column...*/ | ||
726 | for(j=0; j < width; j++) { | ||
727 | |||
728 | /* if set in input, set in rotated output */ | ||
729 | if (src[i] & src_mask) | ||
730 | dst[j] |= dst_mask; | ||
731 | |||
732 | src_mask >>= 1; /* next input bit */ | ||
733 | if (src_mask == 0) /* input word done? */ | ||
734 | { | ||
735 | src_mask = 1 << (sizeof (bitmap_t) * 8 - 1); | ||
736 | i++; /* next input word */ | ||
737 | } | ||
738 | } | ||
739 | |||
740 | dst_mask <<= 1; /* next output bit (row) */ | ||
741 | if (dst_mask > (1 << 7)) /* output bit > 7? */ | ||
742 | { | ||
743 | dst_mask = 1; | ||
744 | dst += width; /* next output byte row */ | ||
745 | } | ||
746 | } | ||
747 | return ((height + 7) / 8) * width; /* return result size in bytes */ | ||
748 | } | ||
749 | |||
750 | |||
677 | /* generate C source from in-core font*/ | 751 | /* generate C source from in-core font*/ |
678 | int gen_c_source(struct font* pf, char *path) | 752 | int gen_c_source(struct font* pf, char *path) |
679 | { | 753 | { |
@@ -704,7 +778,7 @@ int gen_c_source(struct font* pf, char *path) | |||
704 | "*/\n" | 778 | "*/\n" |
705 | "\n" | 779 | "\n" |
706 | "/* Font character bitmap data. */\n" | 780 | "/* Font character bitmap data. */\n" |
707 | "static bitmap_t _font_bits[] = {\n" | 781 | "static const unsigned char _font_bits[] = {\n" |
708 | }; | 782 | }; |
709 | 783 | ||
710 | ofp = fopen(path, "w"); | 784 | ofp = fopen(path, "w"); |
@@ -786,6 +860,27 @@ int gen_c_source(struct font* pf, char *path) | |||
786 | fprintf(ofp, " */\n"); | 860 | fprintf(ofp, " */\n"); |
787 | 861 | ||
788 | bits = pf->bits + (pf->offset? pf->offset[i]: (pf->height * i)); | 862 | bits = pf->bits + (pf->offset? pf->offset[i]: (pf->height * i)); |
863 | #ifdef ROTATE /* pre-rotated into Rockbox bitmap format */ | ||
864 | { | ||
865 | unsigned char bytemap[256]; | ||
866 | int y8, ix=0; | ||
867 | |||
868 | rotleft(bytemap, bits, width, pf->height); | ||
869 | ofs = (bitmap_t*)bytemap; | ||
870 | for (y8=0; y8<pf->height; y8+=8) /* column rows */ | ||
871 | { | ||
872 | for (x=0; x<width; x++) { | ||
873 | fprintf(ofp, "0x%02x, ", bytemap[ix]); | ||
874 | if (!did_syncmsg && bytemap[ix] != *ofs++) { | ||
875 | fprintf(stderr, "Warning: found encoding values in non-sorted order (not an error).\n"); | ||
876 | did_syncmsg = 1; | ||
877 | } | ||
878 | ix++; | ||
879 | } | ||
880 | fprintf(ofp, "\n"); | ||
881 | } | ||
882 | } | ||
883 | #else | ||
789 | for (x=BITMAP_WORDS(width)*pf->height; x>0; --x) { | 884 | for (x=BITMAP_WORDS(width)*pf->height; x>0; --x) { |
790 | fprintf(ofp, "0x%04x,\n", *bits); | 885 | fprintf(ofp, "0x%04x,\n", *bits); |
791 | if (!did_syncmsg && *bits++ != *ofs++) { | 886 | if (!did_syncmsg && *bits++ != *ofs++) { |
@@ -793,24 +888,29 @@ int gen_c_source(struct font* pf, char *path) | |||
793 | did_syncmsg = 1; | 888 | did_syncmsg = 1; |
794 | } | 889 | } |
795 | } | 890 | } |
891 | #endif | ||
796 | } | 892 | } |
797 | fprintf(ofp, "};\n\n"); | 893 | fprintf(ofp, "};\n\n"); |
798 | 894 | ||
799 | if (pf->offset) { | 895 | if (pf->offset) { |
800 | /* output offset table*/ | 896 | /* output offset table*/ |
801 | fprintf(ofp, "/* Character->glyph mapping. */\n" | 897 | fprintf(ofp, "/* Character->glyph mapping. */\n" |
802 | "static unsigned long _sysfont_offset[] = {\n"); | 898 | "static const unsigned short _sysfont_offset[] = {\n"); |
803 | 899 | ||
804 | for (i=0; i<pf->size; ++i) | 900 | for (i=0; i<pf->size; ++i) |
805 | fprintf(ofp, " %ld,\t/* (0x%02x) */\n", | 901 | fprintf(ofp, " %ld,\t/* (0x%02x) */\n", |
902 | #ifdef ROTATE | ||
903 | pf->offrot[i], i+pf->firstchar); | ||
904 | #else | ||
806 | pf->offset[i], i+pf->firstchar); | 905 | pf->offset[i], i+pf->firstchar); |
906 | #endif | ||
807 | fprintf(ofp, "};\n\n"); | 907 | fprintf(ofp, "};\n\n"); |
808 | } | 908 | } |
809 | 909 | ||
810 | /* output width table for proportional fonts*/ | 910 | /* output width table for proportional fonts*/ |
811 | if (pf->width) { | 911 | if (pf->width) { |
812 | fprintf(ofp, "/* Character width data. */\n" | 912 | fprintf(ofp, "/* Character width data. */\n" |
813 | "static unsigned char _sysfont_width[] = {\n"); | 913 | "static const unsigned char _sysfont_width[] = {\n"); |
814 | 914 | ||
815 | for (i=0; i<pf->size; ++i) | 915 | for (i=0; i<pf->size; ++i) |
816 | fprintf(ofp, " %d,\t/* (0x%02x) */\n", | 916 | fprintf(ofp, " %d,\t/* (0x%02x) */\n", |
@@ -822,28 +922,25 @@ int gen_c_source(struct font* pf, char *path) | |||
822 | if (pf->offset) | 922 | if (pf->offset) |
823 | sprintf(obuf, "_sysfont_offset,"); | 923 | sprintf(obuf, "_sysfont_offset,"); |
824 | else | 924 | else |
825 | sprintf(obuf, "0, /* no encode table*/"); | 925 | sprintf(obuf, "0, /* no encode table */"); |
826 | 926 | ||
827 | if (pf->width) | 927 | if (pf->width) |
828 | sprintf(buf, "_sysfont_width,"); | 928 | sprintf(buf, "_sysfont_width, /* width */"); |
829 | else | 929 | else |
830 | sprintf(buf, "0, /* fixed width*/"); | 930 | sprintf(buf, "0, /* fixed width */"); |
831 | 931 | ||
832 | fprintf(ofp, "/* Exported structure definition. */\n" | 932 | fprintf(ofp, "/* Exported structure definition. */\n" |
833 | "struct font sysfont = {\n" | 933 | "const struct font sysfont = {\n" |
834 | " \"%s\",\n" | 934 | " %d, /* maxwidth */\n" |
835 | " %d,\n" | 935 | " %d, /* height */\n" |
836 | " %d,\n" | 936 | " %d, /* ascent */\n" |
837 | " %d,\n" | 937 | " %d, /* firstchar */\n" |
838 | " %d,\n" | 938 | " %d, /* size */\n" |
839 | " %d,\n" | 939 | " _font_bits, /* bits */\n" |
840 | " _font_bits,\n" | 940 | " %s /* offset */\n" |
841 | " %s\n" | 941 | " %s\n" |
842 | " %s\n" | 942 | " %d, /* defaultchar */\n" |
843 | " %d,\n" | ||
844 | " sizeof(_font_bits)/sizeof(bitmap_t),\n" | ||
845 | "};\n", | 943 | "};\n", |
846 | pf->name, | ||
847 | pf->maxwidth, pf->height, | 944 | pf->maxwidth, pf->height, |
848 | pf->ascent, | 945 | pf->ascent, |
849 | pf->firstchar, | 946 | pf->firstchar, |
@@ -899,6 +996,7 @@ int gen_fnt_file(struct font* pf, char *path) | |||
899 | { | 996 | { |
900 | FILE *ofp; | 997 | FILE *ofp; |
901 | int i; | 998 | int i; |
999 | int did_defaultchar = 0; | ||
902 | 1000 | ||
903 | ofp = fopen(path, "wb"); | 1001 | ofp = fopen(path, "wb"); |
904 | if (!ofp) { | 1002 | if (!ofp) { |
@@ -908,13 +1006,13 @@ int gen_fnt_file(struct font* pf, char *path) | |||
908 | 1006 | ||
909 | /* write magic and version #*/ | 1007 | /* write magic and version #*/ |
910 | writestr(ofp, VERSION, 4); | 1008 | writestr(ofp, VERSION, 4); |
911 | 1009 | #ifndef ROTATE | |
912 | /* internal font name*/ | 1010 | /* internal font name*/ |
913 | writestrpad(ofp, pf->name, 64); | 1011 | writestrpad(ofp, pf->name, 64); |
914 | 1012 | ||
915 | /* copyright*/ | 1013 | /* copyright*/ |
916 | writestrpad(ofp, pf->copyright, 256); | 1014 | writestrpad(ofp, pf->copyright, 256); |
917 | 1015 | #endif | |
918 | /* font info*/ | 1016 | /* font info*/ |
919 | writeshort(ofp, pf->maxwidth); | 1017 | writeshort(ofp, pf->maxwidth); |
920 | writeshort(ofp, pf->height); | 1018 | writeshort(ofp, pf->height); |
@@ -928,8 +1026,37 @@ int gen_fnt_file(struct font* pf, char *path) | |||
928 | writelong(ofp, pf->bits_size); /* # words of bitmap_t*/ | 1026 | writelong(ofp, pf->bits_size); /* # words of bitmap_t*/ |
929 | writelong(ofp, pf->offset? pf->size: 0); /* # longs of offset*/ | 1027 | writelong(ofp, pf->offset? pf->size: 0); /* # longs of offset*/ |
930 | writelong(ofp, pf->width? pf->size: 0); /* # bytes of width*/ | 1028 | writelong(ofp, pf->width? pf->size: 0); /* # bytes of width*/ |
931 | |||
932 | /* variable font data*/ | 1029 | /* variable font data*/ |
1030 | #ifdef ROTATE | ||
1031 | for (i=0; i<pf->size; ++i) | ||
1032 | { | ||
1033 | bitmap_t* bits = pf->bits + (pf->offset? pf->offset[i]: (pf->height * i)); | ||
1034 | int width = pf->width ? pf->width[i] : pf->maxwidth; | ||
1035 | int size; | ||
1036 | unsigned char bytemap[256]; | ||
1037 | |||
1038 | if (pf->offset && | ||
1039 | (pf->offset[i] == pf->offset[pf->defaultchar-pf->firstchar])) { | ||
1040 | if (did_defaultchar) | ||
1041 | continue; | ||
1042 | did_defaultchar = 1; | ||
1043 | } | ||
1044 | |||
1045 | size = rotleft(bytemap, bits, width, pf->height); | ||
1046 | writestr(ofp, bytemap, size); | ||
1047 | } | ||
1048 | |||
1049 | if (ftell(ofp) & 1) | ||
1050 | writebyte(ofp, 0); /* pad to 16-bit boundary*/ | ||
1051 | |||
1052 | if (pf->offset) | ||
1053 | for (i=0; i<pf->size; ++i) | ||
1054 | writeshort(ofp, pf->offrot[i]); | ||
1055 | |||
1056 | if (pf->width) | ||
1057 | for (i=0; i<pf->size; ++i) | ||
1058 | writebyte(ofp, pf->width[i]); | ||
1059 | #else | ||
933 | for (i=0; i<pf->bits_size; ++i) | 1060 | for (i=0; i<pf->bits_size; ++i) |
934 | writeshort(ofp, pf->bits[i]); | 1061 | writeshort(ofp, pf->bits[i]); |
935 | if (ftell(ofp) & 2) | 1062 | if (ftell(ofp) & 2) |
@@ -942,7 +1069,7 @@ int gen_fnt_file(struct font* pf, char *path) | |||
942 | if (pf->width) | 1069 | if (pf->width) |
943 | for (i=0; i<pf->size; ++i) | 1070 | for (i=0; i<pf->size; ++i) |
944 | writebyte(ofp, pf->width[i]); | 1071 | writebyte(ofp, pf->width[i]); |
945 | 1072 | #endif | |
946 | fclose(ofp); | 1073 | fclose(ofp); |
947 | return 0; | 1074 | return 0; |
948 | } | 1075 | } |