1
0
Fork 0
forked from len0rd/rockbox

Allow to specify DWIDTH at font level making DWIDTH at char level optional (FS#10176 by Yoshihisa Uchida with minor modifications by me)

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@20828 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Alexander Levin 2009-04-29 21:51:04 +00:00
parent 19c2588471
commit ecd4394f62

View file

@ -72,6 +72,9 @@ struct font {
/* The number of clipped ascents/descents/total */ /* The number of clipped ascents/descents/total */
int num_clipped_ascent, num_clipped_descent, num_clipped; int num_clipped_ascent, num_clipped_descent, num_clipped;
/* default width in pixels (can be overwritten at char level) */
int default_width;
}; };
/* END font.h*/ /* END font.h*/
@ -567,11 +570,13 @@ int bdf_read_header(FILE *fp, struct font* pf)
char buf[256]; char buf[256];
char facename[256]; char facename[256];
char copyright[256]; char copyright[256];
int is_header = 1;
/* set certain values to errors for later error checking */ /* set certain values to errors for later error checking */
pf->defaultchar = -1; pf->defaultchar = -1;
pf->ascent = -1; pf->ascent = -1;
pf->descent = -1; pf->descent = -1;
pf->default_width = -1;
for (;;) { for (;;) {
if (!bdf_getline(fp, buf, sizeof(buf))) { if (!bdf_getline(fp, buf, sizeof(buf))) {
@ -631,6 +636,19 @@ int bdf_read_header(FILE *fp, struct font* pf)
} }
continue; continue;
} }
if (isprefix(buf, "ENDPROPERTIES") || isprefix(buf, "STARTCHAR")) {
is_header = 0;
continue;
}
/* for BDF version 2.2 */
if (is_header && isprefix(buf, "DWIDTH ")) {
if (sscanf(buf, "DWIDTH %d", &pf->default_width) != 1) {
print_error("bad 'DWIDTH' at font level\n");
return 0;
}
continue;
}
/* /*
* Reading ENCODING is necessary to get firstchar/lastchar * Reading ENCODING is necessary to get firstchar/lastchar
@ -751,6 +769,9 @@ int bdf_read_bitmaps(FILE *fp, struct font* pf)
if (encoding < 0) if (encoding < 0)
continue; continue;
if (width < 0 && pf->default_width > 0)
width = pf->default_width;
/* set bits offset in encode map*/ /* set bits offset in encode map*/
if (pf->offset[encoding-pf->firstchar] != -1) { if (pf->offset[encoding-pf->firstchar] != -1) {
print_error("duplicate encoding for character %d (0x%02x), ignoring duplicate\n", print_error("duplicate encoding for character %d (0x%02x), ignoring duplicate\n",
@ -992,6 +1013,11 @@ int bdf_analyze_font(FILE *fp, struct font* pf) {
} }
ignore_char = (encoding < start_char || encoding > limit_char); ignore_char = (encoding < start_char || encoding > limit_char);
if (!ignore_char) { if (!ignore_char) {
if (!read_width && pf->default_width > 0)
{
width = pf->default_width;
read_width = 1;
}
if (!read_width || !read_bbx) { if (!read_width || !read_bbx) {
print_error("WIDTH or BBX is not specified for character %d\n", print_error("WIDTH or BBX is not specified for character %d\n",
encoding); encoding);