forked from len0rd/rockbox
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
This commit is contained in:
parent
d8b6a950c6
commit
67c6f6048e
1 changed files with 56 additions and 1 deletions
|
@ -55,6 +55,12 @@ struct font {
|
||||||
int pixel_size;
|
int pixel_size;
|
||||||
int descent;
|
int descent;
|
||||||
int fbbw, fbbh, fbbx, fbby;
|
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*/
|
/* END font.h*/
|
||||||
|
|
||||||
|
@ -310,10 +316,21 @@ struct font* bdf_read_font(char *path)
|
||||||
goto errout;
|
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)) {
|
if (!bdf_read_bitmaps(fp, pf)) {
|
||||||
fprintf(stderr, "Error reading font bitmaps\n");
|
fprintf(stderr, "Error reading font bitmaps\n");
|
||||||
goto errout;
|
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);
|
fclose(fp);
|
||||||
return pf;
|
return pf;
|
||||||
|
@ -487,7 +504,11 @@ int bdf_read_bitmaps(FILE *fp, struct font* pf)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (isprefix(buf, "STARTCHAR")) {
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
if (isprefix(buf, "ENCODING ")) {
|
if (isprefix(buf, "ENCODING ")) {
|
||||||
|
@ -519,6 +540,8 @@ int bdf_read_bitmaps(FILE *fp, struct font* pf)
|
||||||
if (strequal(buf, "BITMAP") || strequal(buf, "BITMAP ")) {
|
if (strequal(buf, "BITMAP") || strequal(buf, "BITMAP ")) {
|
||||||
bitmap_t *ch_bitmap = pf->bits + ofs;
|
bitmap_t *ch_bitmap = pf->bits + ofs;
|
||||||
int ch_words;
|
int ch_words;
|
||||||
|
int overflow_asc, overflow_desc;
|
||||||
|
int y;
|
||||||
|
|
||||||
if (encoding < 0)
|
if (encoding < 0)
|
||||||
continue;
|
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 BM(row,col) (*(ch_bitmap + ((row)*ch_words) + (col)))
|
||||||
#define BITMAP_NIBBLES (BITMAP_BITSPERIMAGE/4)
|
#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*/
|
/* read bitmaps*/
|
||||||
for (i=0; ; ++i) {
|
for (i=0; ; ++i) {
|
||||||
int hexnibbles;
|
int hexnibbles;
|
||||||
|
@ -560,6 +609,12 @@ int bdf_read_bitmaps(FILE *fp, struct font* pf)
|
||||||
}
|
}
|
||||||
if (isprefix(buf, "ENDCHAR"))
|
if (isprefix(buf, "ENDCHAR"))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
y--;
|
||||||
|
if ((y >= pf->ascent) || (y < -pf->descent)) {
|
||||||
|
/* We're beyond the area that Rockbox can render -> clip */
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
hexnibbles = strlen(buf);
|
hexnibbles = strlen(buf);
|
||||||
for (k=0; k<ch_words; ++k) {
|
for (k=0; k<ch_words; ++k) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue