diff options
-rw-r--r-- | tools/convbdf.c | 57 |
1 files changed, 56 insertions, 1 deletions
diff --git a/tools/convbdf.c b/tools/convbdf.c index aae5b4302d..e8d3f9d36c 100644 --- a/tools/convbdf.c +++ b/tools/convbdf.c | |||
@@ -55,6 +55,12 @@ struct font { | |||
55 | int pixel_size; | 55 | int pixel_size; |
56 | int descent; | 56 | int descent; |
57 | int fbbw, fbbh, fbbx, fbby; | 57 | int fbbw, fbbh, fbbx, fbby; |
58 | |||
59 | /* Max 'overflow' of a char's ascent (descent) over the font's one */ | ||
60 | int max_over_ascent, max_over_descent; | ||
61 | |||
62 | /* The number of clipped ascents/descents/total */ | ||
63 | int num_clipped_ascent, num_clipped_descent, num_clipped; | ||
58 | }; | 64 | }; |
59 | /* END font.h*/ | 65 | /* END font.h*/ |
60 | 66 | ||
@@ -310,10 +316,21 @@ struct font* bdf_read_font(char *path) | |||
310 | goto errout; | 316 | goto errout; |
311 | } | 317 | } |
312 | 318 | ||
319 | pf->max_over_ascent = pf->max_over_descent = 0; | ||
320 | pf->num_clipped_ascent = pf->num_clipped_descent = pf->num_clipped = 0; | ||
321 | |||
313 | if (!bdf_read_bitmaps(fp, pf)) { | 322 | if (!bdf_read_bitmaps(fp, pf)) { |
314 | fprintf(stderr, "Error reading font bitmaps\n"); | 323 | fprintf(stderr, "Error reading font bitmaps\n"); |
315 | goto errout; | 324 | goto errout; |
316 | } | 325 | } |
326 | |||
327 | if (pf->num_clipped > 0) { | ||
328 | fprintf(stderr, "Warning: %d characters were clipped " | ||
329 | "(%d at ascent, %d at descent)\n", | ||
330 | pf->num_clipped, pf->num_clipped_ascent, pf->num_clipped_descent); | ||
331 | fprintf(stderr, " max overflows: ascent: %d, descent: %d\n", | ||
332 | pf->max_over_ascent, pf->max_over_descent); | ||
333 | } | ||
317 | 334 | ||
318 | fclose(fp); | 335 | fclose(fp); |
319 | return pf; | 336 | return pf; |
@@ -487,7 +504,11 @@ int bdf_read_bitmaps(FILE *fp, struct font* pf) | |||
487 | return 0; | 504 | return 0; |
488 | } | 505 | } |
489 | if (isprefix(buf, "STARTCHAR")) { | 506 | if (isprefix(buf, "STARTCHAR")) { |
490 | encoding = width = bbw = bbh = bbx = bby = -1; | 507 | encoding = width = -1; |
508 | bbw = pf->fbbw; | ||
509 | bbh = pf->fbbh; | ||
510 | bbx = pf->fbbx; | ||
511 | bby = pf->fbby; | ||
491 | continue; | 512 | continue; |
492 | } | 513 | } |
493 | if (isprefix(buf, "ENCODING ")) { | 514 | if (isprefix(buf, "ENCODING ")) { |
@@ -519,6 +540,8 @@ int bdf_read_bitmaps(FILE *fp, struct font* pf) | |||
519 | if (strequal(buf, "BITMAP") || strequal(buf, "BITMAP ")) { | 540 | if (strequal(buf, "BITMAP") || strequal(buf, "BITMAP ")) { |
520 | bitmap_t *ch_bitmap = pf->bits + ofs; | 541 | bitmap_t *ch_bitmap = pf->bits + ofs; |
521 | int ch_words; | 542 | int ch_words; |
543 | int overflow_asc, overflow_desc; | ||
544 | int y; | ||
522 | 545 | ||
523 | if (encoding < 0) | 546 | if (encoding < 0) |
524 | continue; | 547 | continue; |
@@ -550,6 +573,32 @@ int bdf_read_bitmaps(FILE *fp, struct font* pf) | |||
550 | #define BM(row,col) (*(ch_bitmap + ((row)*ch_words) + (col))) | 573 | #define BM(row,col) (*(ch_bitmap + ((row)*ch_words) + (col))) |
551 | #define BITMAP_NIBBLES (BITMAP_BITSPERIMAGE/4) | 574 | #define BITMAP_NIBBLES (BITMAP_BITSPERIMAGE/4) |
552 | 575 | ||
576 | overflow_asc = bby + bbh - pf->ascent; | ||
577 | if (overflow_asc > 0) { | ||
578 | pf->num_clipped_ascent++; | ||
579 | if (overflow_asc > pf->max_over_ascent) { | ||
580 | pf->max_over_ascent = overflow_asc; | ||
581 | } | ||
582 | fprintf(stderr, "Warning: character %d goes %d pixel(s)" | ||
583 | " beyond the font's ascent, it will be clipped\n", | ||
584 | encoding, overflow_asc); | ||
585 | } | ||
586 | overflow_desc = -bby - pf->descent; | ||
587 | if (overflow_desc > 0) { | ||
588 | pf->num_clipped_descent++; | ||
589 | if (overflow_desc > pf->max_over_descent) { | ||
590 | pf->max_over_descent = overflow_desc; | ||
591 | } | ||
592 | fprintf(stderr, "Warning: character %d goes %d pixel(s)" | ||
593 | " beyond the font's descent, it will be clipped\n", | ||
594 | encoding, overflow_desc); | ||
595 | } | ||
596 | if (overflow_asc > 0 || overflow_desc > 0) { | ||
597 | pf->num_clipped++; | ||
598 | } | ||
599 | |||
600 | y = bby + bbh; /* 0-based y within the char */ | ||
601 | |||
553 | /* read bitmaps*/ | 602 | /* read bitmaps*/ |
554 | for (i=0; ; ++i) { | 603 | for (i=0; ; ++i) { |
555 | int hexnibbles; | 604 | int hexnibbles; |
@@ -560,6 +609,12 @@ int bdf_read_bitmaps(FILE *fp, struct font* pf) | |||
560 | } | 609 | } |
561 | if (isprefix(buf, "ENDCHAR")) | 610 | if (isprefix(buf, "ENDCHAR")) |
562 | break; | 611 | break; |
612 | |||
613 | y--; | ||
614 | if ((y >= pf->ascent) || (y < -pf->descent)) { | ||
615 | /* We're beyond the area that Rockbox can render -> clip */ | ||
616 | continue; | ||
617 | } | ||
563 | 618 | ||
564 | hexnibbles = strlen(buf); | 619 | hexnibbles = strlen(buf); |
565 | for (k=0; k<ch_words; ++k) { | 620 | for (k=0; k<ch_words; ++k) { |