diff --git a/tools/convbdf.c b/tools/convbdf.c old mode 100644 new mode 100755 index aae5b43..07808df --- a/tools/convbdf.c +++ b/tools/convbdf.c @@ -334,6 +334,10 @@ int bdf_read_header(FILE *fp, struct font* pf) char buf[256]; char facename[256]; char copyright[256]; + int bbw; + int bbh; + int bbx; + int bby; /* set certain values to errors for later error checking*/ pf->defaultchar = -1; @@ -418,6 +422,24 @@ int bdf_read_header(FILE *fp, struct font* pf) } continue; } + + /* BBX + * pf->ascent, pf->descent are set to the size suitable for the font. + */ + if (isprefix(buf, "BBX ")) { + if (sscanf(buf, "BBX %d %d %d %d", &bbw, &bbh, &bbx, &bby) != 4) { + fprintf(stderr, "Error: bad 'BBX'\n"); + return 0; + } + + if (bbh + bby > pf->ascent) + pf->ascent = bbh + bby; + if (-bby > pf->descent) + pf->descent = -bby; + + continue; + } + if (strequal(buf, "ENDFONT")) break; } @@ -427,6 +449,11 @@ int bdf_read_header(FILE *fp, struct font* pf) fprintf(stderr, "Error: Invalid BDF file, requires FONT_ASCENT/FONT_DESCENT/ENCODING\n"); return 0; } + if (pf->ascent > pf->fbbh + pf->fbby) + pf->ascent = pf->fbbh + pf->fbby; + if (pf->fbby < 0 && pf->descent > -pf->fbby) + pf->descent = -pf->fbby; + pf->height = pf->ascent + pf->descent; /* calc default char*/ @@ -473,6 +500,7 @@ int bdf_read_bitmaps(FILE *fp, struct font* pf) int encodetable = 0; int l; char buf[256]; + int r; /* reset file pointer*/ fseek(fp, 0L, SEEK_SET); @@ -561,6 +589,10 @@ int bdf_read_bitmaps(FILE *fp, struct font* pf) if (isprefix(buf, "ENDCHAR")) break; + r = pf->ascent - bby - bbh + i; + if (r < 0 || r >= pf->height) + continue; + hexnibbles = strlen(buf); for (k=0; kheight - pf->descent - bby - bbh + i, k) |= - value >> bbx; + BM(r, k) |= value >> bbx; /* handle overflow into next image word*/ if (bbx) { - BM(pf->height - pf->descent - bby - bbh + i, k+1) = - value << (BITMAP_BITSPERIMAGE - bbx); + BM(r, k+1) = value << (BITMAP_BITSPERIMAGE - bbx); } } }