summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorAlexander Levin <al.le@rockbox.org>2009-03-04 21:42:26 +0000
committerAlexander Levin <al.le@rockbox.org>2009-03-04 21:42:26 +0000
commit67c6f6048e3e7f81e337793f141c19a3d57c2c78 (patch)
treef0ae59e675d2d17c955365400b261a7b7dfbc9d4 /tools
parentd8b6a950c67f21d09898fe32d0917d0970dab738 (diff)
downloadrockbox-67c6f6048e3e7f81e337793f141c19a3d57c2c78.tar.gz
rockbox-67c6f6048e3e7f81e337793f141c19a3d57c2c78.tar.bz2
rockbox-67c6f6048e3e7f81e337793f141c19a3d57c2c78.zip
Clip the glyphs that wouldn't be correctly rendered by Rockbox thus avoiding "noise" in glyphs. See also the attachment in FS#9931 for the list of
the "offending" fonts. Further steps would be to decide how such fonts can be handled better. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@20204 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'tools')
-rw-r--r--tools/convbdf.c57
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 {
int pixel_size;
int descent;
int fbbw, fbbh, fbbx, fbby;
+
+ /* Max 'overflow' of a char's ascent (descent) over the font's one */
+ int max_over_ascent, max_over_descent;
+
+ /* The number of clipped ascents/descents/total */
+ int num_clipped_ascent, num_clipped_descent, num_clipped;
};
/* END font.h*/
@@ -310,10 +316,21 @@ struct font* bdf_read_font(char *path)
goto errout;
}
+ pf->max_over_ascent = pf->max_over_descent = 0;
+ pf->num_clipped_ascent = pf->num_clipped_descent = pf->num_clipped = 0;
+
if (!bdf_read_bitmaps(fp, pf)) {
fprintf(stderr, "Error reading font bitmaps\n");
goto errout;
}
+
+ if (pf->num_clipped > 0) {
+ fprintf(stderr, "Warning: %d characters were clipped "
+ "(%d at ascent, %d at descent)\n",
+ pf->num_clipped, pf->num_clipped_ascent, pf->num_clipped_descent);
+ fprintf(stderr, " max overflows: ascent: %d, descent: %d\n",
+ pf->max_over_ascent, pf->max_over_descent);
+ }
fclose(fp);
return pf;
@@ -487,7 +504,11 @@ int bdf_read_bitmaps(FILE *fp, struct font* pf)
return 0;
}
if (isprefix(buf, "STARTCHAR")) {
- encoding = width = bbw = bbh = bbx = bby = -1;
+ encoding = width = -1;
+ bbw = pf->fbbw;
+ bbh = pf->fbbh;
+ bbx = pf->fbbx;
+ bby = pf->fbby;
continue;
}
if (isprefix(buf, "ENCODING ")) {
@@ -519,6 +540,8 @@ int bdf_read_bitmaps(FILE *fp, struct font* pf)
if (strequal(buf, "BITMAP") || strequal(buf, "BITMAP ")) {
bitmap_t *ch_bitmap = pf->bits + ofs;
int ch_words;
+ int overflow_asc, overflow_desc;
+ int y;
if (encoding < 0)
continue;
@@ -550,6 +573,32 @@ int bdf_read_bitmaps(FILE *fp, struct font* pf)
#define BM(row,col) (*(ch_bitmap + ((row)*ch_words) + (col)))
#define BITMAP_NIBBLES (BITMAP_BITSPERIMAGE/4)
+ overflow_asc = bby + bbh - pf->ascent;
+ if (overflow_asc > 0) {
+ pf->num_clipped_ascent++;
+ if (overflow_asc > pf->max_over_ascent) {
+ pf->max_over_ascent = overflow_asc;
+ }
+ fprintf(stderr, "Warning: character %d goes %d pixel(s)"
+ " beyond the font's ascent, it will be clipped\n",
+ encoding, overflow_asc);
+ }
+ overflow_desc = -bby - pf->descent;
+ if (overflow_desc > 0) {
+ pf->num_clipped_descent++;
+ if (overflow_desc > pf->max_over_descent) {
+ pf->max_over_descent = overflow_desc;
+ }
+ fprintf(stderr, "Warning: character %d goes %d pixel(s)"
+ " beyond the font's descent, it will be clipped\n",
+ encoding, overflow_desc);
+ }
+ if (overflow_asc > 0 || overflow_desc > 0) {
+ pf->num_clipped++;
+ }
+
+ y = bby + bbh; /* 0-based y within the char */
+
/* read bitmaps*/
for (i=0; ; ++i) {
int hexnibbles;
@@ -560,6 +609,12 @@ int bdf_read_bitmaps(FILE *fp, struct font* pf)
}
if (isprefix(buf, "ENDCHAR"))
break;
+
+ y--;
+ if ((y >= pf->ascent) || (y < -pf->descent)) {
+ /* We're beyond the area that Rockbox can render -> clip */
+ continue;
+ }
hexnibbles = strlen(buf);
for (k=0; k<ch_words; ++k) {