forked from len0rd/rockbox
Revamp of the bitmap allocation for the fonts. Implements the idea from FS#9907 (reallocate when maxwidth grows), but does it correctly. Also gets rid of the warning "DWIDTH spec > ..." which is irritating since the bounding box header of the font is not required to specify the MAX width.
Also replaced TABs with spaces. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@20219 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
c8a60784d0
commit
cbcef6700c
1 changed files with 132 additions and 128 deletions
174
tools/convbdf.c
174
tools/convbdf.c
|
@ -22,37 +22,41 @@
|
||||||
#define VERSION "RB11"
|
#define VERSION "RB11"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* bitmap_t helper macros*/
|
/*
|
||||||
#define BITMAP_WORDS(x) (((x)+15)/16) /* image size in words*/
|
* bitmap_t helper macros
|
||||||
#define BITMAP_BYTES(x) (BITMAP_WORDS(x)*sizeof(bitmap_t))
|
*/
|
||||||
|
typedef unsigned short bitmap_t; /* bitmap image unit size*/
|
||||||
|
|
||||||
|
/* Number of words to hold a pixel line of width x pixels */
|
||||||
#define BITMAP_BITSPERIMAGE (sizeof(bitmap_t) * 8)
|
#define BITMAP_BITSPERIMAGE (sizeof(bitmap_t) * 8)
|
||||||
|
#define BITMAP_WORDS(x) (((x)+BITMAP_BITSPERIMAGE-1)/BITMAP_BITSPERIMAGE)
|
||||||
|
#define BITMAP_BYTES(x) (BITMAP_WORDS(x)*sizeof(bitmap_t))
|
||||||
#define BITMAP_BITVALUE(n) ((bitmap_t) (((bitmap_t) 1) << (n)))
|
#define BITMAP_BITVALUE(n) ((bitmap_t) (((bitmap_t) 1) << (n)))
|
||||||
#define BITMAP_FIRSTBIT (BITMAP_BITVALUE(BITMAP_BITSPERIMAGE - 1))
|
#define BITMAP_FIRSTBIT (BITMAP_BITVALUE(BITMAP_BITSPERIMAGE - 1))
|
||||||
#define BITMAP_TESTBIT(m) ((m) & BITMAP_FIRSTBIT)
|
#define BITMAP_TESTBIT(m) ((m) & BITMAP_FIRSTBIT)
|
||||||
#define BITMAP_SHIFTBIT(m) ((bitmap_t) ((m) << 1))
|
#define BITMAP_SHIFTBIT(m) ((bitmap_t) ((m) << 1))
|
||||||
|
|
||||||
typedef unsigned short bitmap_t; /* bitmap image unit size*/
|
|
||||||
|
|
||||||
/* builtin C-based proportional/fixed font structure */
|
/* builtin C-based proportional/fixed font structure */
|
||||||
/* based on The Microwindows Project http://microwindows.org */
|
/* based on The Microwindows Project http://microwindows.org */
|
||||||
struct font {
|
struct font {
|
||||||
int maxwidth; /* max width in pixels*/
|
int maxwidth; /* max width in pixels */
|
||||||
int height; /* height in pixels*/
|
int height; /* height in pixels */
|
||||||
int ascent; /* ascent (baseline) height*/
|
int ascent; /* ascent (baseline) height */
|
||||||
int firstchar; /* first character in bitmap*/
|
int firstchar; /* first character in bitmap */
|
||||||
int size; /* font size in glyphs ('holes' included) */
|
int size; /* font size in glyphs ('holes' included) */
|
||||||
bitmap_t* bits; /* 16-bit right-padded bitmap data*/
|
bitmap_t* bits; /* 16-bit right-padded bitmap data */
|
||||||
unsigned int* offset; /* offsets into bitmap data*/
|
int* offset; /* offsets into bitmap data */
|
||||||
unsigned char* width; /* character widths or NULL if fixed*/
|
unsigned char* width; /* character widths or NULL if fixed */
|
||||||
int defaultchar; /* default char (not glyph index)*/
|
int defaultchar; /* default char (not glyph index) */
|
||||||
int bits_size; /* # words of bitmap_t bits*/
|
int bits_size; /* # words of bitmap_t bits */
|
||||||
|
|
||||||
/* unused by runtime system, read in by convbdf */
|
/* unused by runtime system, read in by convbdf */
|
||||||
int nchars; /* number of different glyphs */
|
int nchars; /* number of different glyphs */
|
||||||
unsigned int* offrot; /* offsets into rotated bitmap data*/
|
unsigned int* offrot; /* offsets into rotated bitmap data */
|
||||||
char * name; /* font name*/
|
char* name; /* font name */
|
||||||
char * facename; /* facename of font*/
|
char* facename; /* facename of font */
|
||||||
char * copyright; /* copyright info for loadable fonts*/
|
char* copyright; /* copyright info for loadable fonts */
|
||||||
int pixel_size;
|
int pixel_size;
|
||||||
int descent;
|
int descent;
|
||||||
int fbbw, fbbh, fbbx, fbby;
|
int fbbw, fbbh, fbbx, fbby;
|
||||||
|
@ -71,8 +75,6 @@ struct font {
|
||||||
#define MAX(a,b) ((a) > (b) ? (a) : (b))
|
#define MAX(a,b) ((a) > (b) ? (a) : (b))
|
||||||
#define MIN(a,b) ((a) < (b) ? (a) : (b))
|
#define MIN(a,b) ((a) < (b) ? (a) : (b))
|
||||||
|
|
||||||
#define EXTRA 300 /* # bytes extra allocation for buggy .bdf files*/
|
|
||||||
|
|
||||||
int gen_c = 0;
|
int gen_c = 0;
|
||||||
int gen_h = 0;
|
int gen_h = 0;
|
||||||
int gen_fnt = 0;
|
int gen_fnt = 0;
|
||||||
|
@ -92,6 +94,7 @@ int bdf_read_header(FILE *fp, struct font* pf);
|
||||||
int bdf_read_bitmaps(FILE *fp, struct font* pf);
|
int bdf_read_bitmaps(FILE *fp, struct font* pf);
|
||||||
char * bdf_getline(FILE *fp, char *buf, int len);
|
char * bdf_getline(FILE *fp, char *buf, int len);
|
||||||
bitmap_t bdf_hexval(unsigned char *buf, int ndx1, int ndx2);
|
bitmap_t bdf_hexval(unsigned char *buf, int ndx1, int ndx2);
|
||||||
|
void bitmap_buf_alloc(struct font* pf);
|
||||||
|
|
||||||
int gen_c_source(struct font* pf, char *path);
|
int gen_c_source(struct font* pf, char *path);
|
||||||
int gen_h_header(struct font* pf, char *path);
|
int gen_h_header(struct font* pf, char *path);
|
||||||
|
@ -192,13 +195,13 @@ void getopts(int *pac, char ***pav)
|
||||||
*pav = av;
|
*pav = av;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* remove directory prefix and file suffix from full path*/
|
/* remove directory prefix and file suffix from full path */
|
||||||
char *basename(char *path)
|
char *basename(char *path)
|
||||||
{
|
{
|
||||||
char *p, *b;
|
char *p, *b;
|
||||||
static char base[256];
|
static char base[256];
|
||||||
|
|
||||||
/* remove prepended path and extension*/
|
/* remove prepended path and extension */
|
||||||
b = path;
|
b = path;
|
||||||
for (p=path; *p; ++p) {
|
for (p=path; *p; ++p) {
|
||||||
if (*p == '/')
|
if (*p == '/')
|
||||||
|
@ -255,8 +258,8 @@ int main(int ac, char **av)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
++av; --ac; /* skip av[0]*/
|
++av; --ac; /* skip av[0] */
|
||||||
getopts(&ac, &av); /* read command line options*/
|
getopts(&ac, &av); /* read command line options */
|
||||||
|
|
||||||
if (ac < 1 || (!gen_c && !gen_h && !gen_fnt)) {
|
if (ac < 1 || (!gen_c && !gen_h && !gen_fnt)) {
|
||||||
usage();
|
usage();
|
||||||
|
@ -277,7 +280,7 @@ int main(int ac, char **av)
|
||||||
exit(ret);
|
exit(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* free font structure*/
|
/* free font structure */
|
||||||
void free_font(struct font* pf)
|
void free_font(struct font* pf)
|
||||||
{
|
{
|
||||||
if (!pf)
|
if (!pf)
|
||||||
|
@ -297,7 +300,7 @@ void free_font(struct font* pf)
|
||||||
free(pf);
|
free(pf);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* build incore structure from .bdf file*/
|
/* build incore structure from .bdf file */
|
||||||
struct font* bdf_read_font(char *path)
|
struct font* bdf_read_font(char *path)
|
||||||
{
|
{
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
|
@ -312,6 +315,7 @@ struct font* bdf_read_font(char *path)
|
||||||
pf = (struct font*)calloc(1, sizeof(struct font));
|
pf = (struct font*)calloc(1, sizeof(struct font));
|
||||||
if (!pf)
|
if (!pf)
|
||||||
goto errout;
|
goto errout;
|
||||||
|
memset(pf, 0, sizeof(struct font));
|
||||||
|
|
||||||
pf->name = strdup(basename(path));
|
pf->name = strdup(basename(path));
|
||||||
|
|
||||||
|
@ -346,18 +350,17 @@ struct font* bdf_read_font(char *path)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* read bdf font header information, return 0 on error*/
|
/* read bdf font header information, return 0 on error */
|
||||||
int bdf_read_header(FILE *fp, struct font* pf)
|
int bdf_read_header(FILE *fp, struct font* pf)
|
||||||
{
|
{
|
||||||
int encoding;
|
int encoding;
|
||||||
int maxwidth;
|
|
||||||
int firstchar = 65535;
|
int firstchar = 65535;
|
||||||
int lastchar = -1;
|
int lastchar = -1;
|
||||||
char buf[256];
|
char buf[256];
|
||||||
char facename[256];
|
char facename[256];
|
||||||
char copyright[256];
|
char copyright[256];
|
||||||
|
|
||||||
/* 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;
|
||||||
|
@ -367,7 +370,7 @@ int bdf_read_header(FILE *fp, struct font* pf)
|
||||||
fprintf(stderr, "Error: EOF on file\n");
|
fprintf(stderr, "Error: EOF on file\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (isprefix(buf, "FONT ")) { /* not required*/
|
if (isprefix(buf, "FONT ")) { /* not required */
|
||||||
if (sscanf(buf, "FONT %[^\n]", facename) != 1) {
|
if (sscanf(buf, "FONT %[^\n]", facename) != 1) {
|
||||||
fprintf(stderr, "Error: bad 'FONT'\n");
|
fprintf(stderr, "Error: bad 'FONT'\n");
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -375,7 +378,7 @@ int bdf_read_header(FILE *fp, struct font* pf)
|
||||||
pf->facename = strdup(facename);
|
pf->facename = strdup(facename);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (isprefix(buf, "COPYRIGHT ")) { /* not required*/
|
if (isprefix(buf, "COPYRIGHT ")) { /* not required */
|
||||||
if (sscanf(buf, "COPYRIGHT \"%[^\"]", copyright) != 1) {
|
if (sscanf(buf, "COPYRIGHT \"%[^\"]", copyright) != 1) {
|
||||||
fprintf(stderr, "Error: bad 'COPYRIGHT'\n");
|
fprintf(stderr, "Error: bad 'COPYRIGHT'\n");
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -383,7 +386,7 @@ int bdf_read_header(FILE *fp, struct font* pf)
|
||||||
pf->copyright = strdup(copyright);
|
pf->copyright = strdup(copyright);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (isprefix(buf, "DEFAULT_CHAR ")) { /* not required*/
|
if (isprefix(buf, "DEFAULT_CHAR ")) { /* not required */
|
||||||
if (sscanf(buf, "DEFAULT_CHAR %d", &pf->defaultchar) != 1) {
|
if (sscanf(buf, "DEFAULT_CHAR %d", &pf->defaultchar) != 1) {
|
||||||
fprintf(stderr, "Error: bad 'DEFAULT_CHAR'\n");
|
fprintf(stderr, "Error: bad 'DEFAULT_CHAR'\n");
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -451,27 +454,27 @@ int bdf_read_header(FILE *fp, struct font* pf)
|
||||||
}
|
}
|
||||||
pf->height = pf->ascent + pf->descent;
|
pf->height = pf->ascent + pf->descent;
|
||||||
|
|
||||||
/* calc default char*/
|
/* calc default char */
|
||||||
if (pf->defaultchar < 0 ||
|
if (pf->defaultchar < 0 ||
|
||||||
pf->defaultchar < firstchar ||
|
pf->defaultchar < firstchar ||
|
||||||
pf->defaultchar > limit_char ||
|
pf->defaultchar > limit_char ||
|
||||||
pf->defaultchar > lastchar)
|
pf->defaultchar > lastchar)
|
||||||
pf->defaultchar = firstchar;
|
pf->defaultchar = firstchar;
|
||||||
|
|
||||||
/* calc font size (offset/width entries)*/
|
/* calc font size (offset/width entries) */
|
||||||
pf->firstchar = firstchar;
|
pf->firstchar = firstchar;
|
||||||
pf->size = lastchar - firstchar + 1;
|
pf->size = lastchar - firstchar + 1;
|
||||||
|
if (pf->size < pf->nchars) {
|
||||||
|
fprintf(stderr, "Error: NCHARS and max code mismatch\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* use the font boundingbox to get initial maxwidth*/
|
/* use the font boundingbox to get initial maxwidth */
|
||||||
/*maxwidth = pf->fbbw - pf->fbbx;*/
|
/*maxwidth = pf->fbbw - pf->fbbx;*/
|
||||||
maxwidth = pf->fbbw;
|
pf->maxwidth = pf->fbbw;
|
||||||
|
bitmap_buf_alloc(pf); /* Allocate bitmaps */
|
||||||
|
|
||||||
/* initially use font maxwidth * height for bits allocation*/
|
pf->offset = (int *)malloc(pf->size * sizeof(int));
|
||||||
pf->bits_size = pf->nchars * BITMAP_WORDS(maxwidth) * pf->height;
|
|
||||||
|
|
||||||
/* allocate bits, offset, and width arrays*/
|
|
||||||
pf->bits = (bitmap_t *)malloc(pf->bits_size * sizeof(bitmap_t) + EXTRA);
|
|
||||||
pf->offset = (unsigned int *)malloc(pf->size * sizeof(unsigned int));
|
|
||||||
pf->offrot = (unsigned int *)malloc(pf->size * sizeof(unsigned int));
|
pf->offrot = (unsigned int *)malloc(pf->size * sizeof(unsigned int));
|
||||||
pf->width = (unsigned char *)malloc(pf->size * sizeof(unsigned char));
|
pf->width = (unsigned char *)malloc(pf->size * sizeof(unsigned char));
|
||||||
|
|
||||||
|
@ -483,23 +486,24 @@ int bdf_read_header(FILE *fp, struct font* pf)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* read bdf font bitmaps, return 0 on error*/
|
/* read bdf font bitmaps, return 0 on error */
|
||||||
int bdf_read_bitmaps(FILE *fp, struct font* pf)
|
int bdf_read_bitmaps(FILE *fp, struct font* pf)
|
||||||
{
|
{
|
||||||
int ofs = 0;
|
int ofs = 0;
|
||||||
int ofr = 0;
|
int ofr = 0;
|
||||||
int maxwidth = 0;
|
|
||||||
int i, k, encoding, width;
|
int i, k, encoding, width;
|
||||||
int bbw, bbh, bbx, bby;
|
int bbw, bbh, bbx, bby;
|
||||||
int proportional = 0;
|
int proportional = 0;
|
||||||
int encodetable = 0;
|
int encodetable = 0;
|
||||||
int l;
|
int l;
|
||||||
char buf[256];
|
char buf[256];
|
||||||
|
bitmap_t *ch_bitmap;
|
||||||
|
int ch_words;
|
||||||
|
|
||||||
/* reset file pointer*/
|
/* reset file pointer */
|
||||||
fseek(fp, 0L, SEEK_SET);
|
fseek(fp, 0L, SEEK_SET);
|
||||||
|
|
||||||
/* initially mark offsets as not used*/
|
/* initially mark offsets as not used */
|
||||||
for (i=0; i<pf->size; ++i)
|
for (i=0; i<pf->size; ++i)
|
||||||
pf->offset[i] = -1;
|
pf->offset[i] = -1;
|
||||||
|
|
||||||
|
@ -530,7 +534,7 @@ int bdf_read_bitmaps(FILE *fp, struct font* pf)
|
||||||
fprintf(stderr, "Error: bad 'DWIDTH'\n");
|
fprintf(stderr, "Error: bad 'DWIDTH'\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/* use font boundingbox width if DWIDTH <= 0*/
|
/* use font boundingbox width if DWIDTH <= 0 */
|
||||||
if (width <= 0)
|
if (width <= 0)
|
||||||
width = pf->fbbw - pf->fbbx;
|
width = pf->fbbw - pf->fbbx;
|
||||||
continue;
|
continue;
|
||||||
|
@ -543,8 +547,6 @@ int bdf_read_bitmaps(FILE *fp, struct font* pf)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (strequal(buf, "BITMAP") || strequal(buf, "BITMAP ")) {
|
if (strequal(buf, "BITMAP") || strequal(buf, "BITMAP ")) {
|
||||||
bitmap_t *ch_bitmap = pf->bits + ofs;
|
|
||||||
int ch_words;
|
|
||||||
int overflow_asc, overflow_desc;
|
int overflow_asc, overflow_desc;
|
||||||
int bbh_orig, bby_orig, y;
|
int bbh_orig, bby_orig, y;
|
||||||
|
|
||||||
|
@ -552,7 +554,7 @@ int bdf_read_bitmaps(FILE *fp, struct font* pf)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* set bits offset in encode map*/
|
/* set bits offset in encode map*/
|
||||||
if (pf->offset[encoding-pf->firstchar] != (unsigned int)-1) {
|
if (pf->offset[encoding-pf->firstchar] != -1) {
|
||||||
fprintf(stderr, "Error: duplicate encoding for character %d (0x%02x), ignoring duplicate\n",
|
fprintf(stderr, "Error: duplicate encoding for character %d (0x%02x), ignoring duplicate\n",
|
||||||
encoding, encoding);
|
encoding, encoding);
|
||||||
continue;
|
continue;
|
||||||
|
@ -560,21 +562,22 @@ int bdf_read_bitmaps(FILE *fp, struct font* pf)
|
||||||
pf->offset[encoding-pf->firstchar] = ofs;
|
pf->offset[encoding-pf->firstchar] = ofs;
|
||||||
pf->offrot[encoding-pf->firstchar] = ofr;
|
pf->offrot[encoding-pf->firstchar] = ofr;
|
||||||
|
|
||||||
/* calc char width*/
|
/* calc char width */
|
||||||
if (bbx < 0) {
|
if (bbx < 0) {
|
||||||
|
/* Rockbox can't render overlapping glyphs */
|
||||||
width -= bbx;
|
width -= bbx;
|
||||||
/*if (width > maxwidth)
|
|
||||||
width = maxwidth;*/
|
|
||||||
bbx = 0;
|
bbx = 0;
|
||||||
}
|
}
|
||||||
if (width > maxwidth)
|
if (width > pf->maxwidth) {
|
||||||
maxwidth = width;
|
pf->maxwidth = width;
|
||||||
|
bitmap_buf_alloc(pf); /* Re-allocate bitmaps since the maxwidth has grown */
|
||||||
|
}
|
||||||
pf->width[encoding-pf->firstchar] = width;
|
pf->width[encoding-pf->firstchar] = width;
|
||||||
|
|
||||||
/* clear bitmap*/
|
ch_bitmap = pf->bits + ofs;
|
||||||
memset(ch_bitmap, 0, BITMAP_BYTES(width) * pf->height);
|
|
||||||
|
|
||||||
ch_words = BITMAP_WORDS(width);
|
ch_words = BITMAP_WORDS(width);
|
||||||
|
memset(ch_bitmap, 0, BITMAP_BYTES(width) * pf->height); /* clear bitmap */
|
||||||
|
|
||||||
#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)
|
||||||
|
|
||||||
|
@ -610,12 +613,13 @@ int bdf_read_bitmaps(FILE *fp, struct font* pf)
|
||||||
|
|
||||||
y = bby_orig + bbh_orig; /* 0-based y within the char */
|
y = bby_orig + bbh_orig; /* 0-based y within the char */
|
||||||
|
|
||||||
/* read bitmaps*/
|
/* read bitmaps */
|
||||||
for (i=0; ; ++i) {
|
for (i=0; ; ++i) {
|
||||||
int hexnibbles;
|
int hexnibbles;
|
||||||
|
|
||||||
if (!bdf_getline(fp, buf, sizeof(buf))) {
|
if (!bdf_getline(fp, buf, sizeof(buf))) {
|
||||||
fprintf(stderr, "Error: EOF reading BITMAP data\n");
|
fprintf(stderr, "Error: EOF reading BITMAP data for character %d\n",
|
||||||
|
encoding);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (isprefix(buf, "ENDCHAR"))
|
if (isprefix(buf, "ENDCHAR"))
|
||||||
|
@ -645,7 +649,7 @@ int bdf_read_bitmaps(FILE *fp, struct font* pf)
|
||||||
|
|
||||||
BM(pf->height - pf->descent - bby - bbh + i, k) |=
|
BM(pf->height - pf->descent - bby - bbh + i, k) |=
|
||||||
value >> bbx;
|
value >> bbx;
|
||||||
/* handle overflow into next image word*/
|
/* handle overflow into next image word */
|
||||||
if (bbx) {
|
if (bbx) {
|
||||||
BM(pf->height - pf->descent - bby - bbh + i, k+1) =
|
BM(pf->height - pf->descent - bby - bbh + i, k+1) =
|
||||||
value << (BITMAP_BITSPERIMAGE - bbx);
|
value << (BITMAP_BITSPERIMAGE - bbx);
|
||||||
|
@ -662,18 +666,15 @@ int bdf_read_bitmaps(FILE *fp, struct font* pf)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* set max width*/
|
/* change unused width values to default char values */
|
||||||
pf->maxwidth = maxwidth;
|
|
||||||
|
|
||||||
/* change unused width values to default char values*/
|
|
||||||
for (i=0; i<pf->size; ++i) {
|
for (i=0; i<pf->size; ++i) {
|
||||||
int defchar = pf->defaultchar - pf->firstchar;
|
int defchar = pf->defaultchar - pf->firstchar;
|
||||||
|
|
||||||
if (pf->offset[i] == (unsigned int)-1)
|
if (pf->offset[i] == -1)
|
||||||
pf->width[i] = pf->width[defchar];
|
pf->width[i] = pf->width[defchar];
|
||||||
}
|
}
|
||||||
|
|
||||||
/* determine whether font doesn't require encode table*/
|
/* determine whether font doesn't require encode table */
|
||||||
#ifdef ROTATE
|
#ifdef ROTATE
|
||||||
l = 0;
|
l = 0;
|
||||||
for (i=0; i<pf->size; ++i) {
|
for (i=0; i<pf->size; ++i) {
|
||||||
|
@ -698,9 +699,9 @@ int bdf_read_bitmaps(FILE *fp, struct font* pf)
|
||||||
pf->offset = NULL;
|
pf->offset = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* determine whether font is fixed-width*/
|
/* determine whether font is fixed-width */
|
||||||
for (i=0; i<pf->size; ++i) {
|
for (i=0; i<pf->size; ++i) {
|
||||||
if (pf->width[i] != maxwidth) {
|
if (pf->width[i] != pf->maxwidth) {
|
||||||
proportional = 1;
|
proportional = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -710,21 +711,11 @@ int bdf_read_bitmaps(FILE *fp, struct font* pf)
|
||||||
pf->width = NULL;
|
pf->width = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* reallocate bits array to actual bits used*/
|
/* reallocate bits array to actual bits used */
|
||||||
if (ofs < pf->bits_size) {
|
if (ofs < pf->bits_size) {
|
||||||
pf->bits = realloc(pf->bits, ofs * sizeof(bitmap_t));
|
pf->bits = realloc(pf->bits, ofs * sizeof(bitmap_t));
|
||||||
pf->bits_size = ofs;
|
pf->bits_size = ofs;
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
if (ofs > pf->bits_size) {
|
|
||||||
fprintf(stderr, "Warning: DWIDTH spec > max FONTBOUNDINGBOX\n");
|
|
||||||
if (ofs > pf->bits_size+EXTRA) {
|
|
||||||
fprintf(stderr, "Error: Not enough bits initially allocated\n");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
pf->bits_size = ofs;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef ROTATE
|
#ifdef ROTATE
|
||||||
pf->bits_size = ofr; /* always update, rotated is smaller */
|
pf->bits_size = ofr; /* always update, rotated is smaller */
|
||||||
|
@ -733,7 +724,7 @@ int bdf_read_bitmaps(FILE *fp, struct font* pf)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* read the next non-comment line, returns buf or NULL if EOF*/
|
/* read the next non-comment line, returns buf or NULL if EOF */
|
||||||
char *bdf_getline(FILE *fp, char *buf, int len)
|
char *bdf_getline(FILE *fp, char *buf, int len)
|
||||||
{
|
{
|
||||||
int c;
|
int c;
|
||||||
|
@ -759,6 +750,19 @@ char *bdf_getline(FILE *fp, char *buf, int len)
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Calculates the necessary size of the bit buffer to hold all the
|
||||||
|
bitmaps for the glyphs in the font. Shoud be called every time
|
||||||
|
the max width of the font grows. Font height, the max width and
|
||||||
|
the number of chars in the font must have been already set.
|
||||||
|
*/
|
||||||
|
void bitmap_buf_alloc(struct font* pf)
|
||||||
|
{
|
||||||
|
pf->bits_size = pf->size * BITMAP_WORDS(pf->maxwidth) * pf->height;
|
||||||
|
pf->bits = (bitmap_t *)realloc(pf->bits, pf->bits_size * sizeof(bitmap_t));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* return hex value of portion of buffer*/
|
/* return hex value of portion of buffer*/
|
||||||
bitmap_t bdf_hexval(unsigned char *buf, int ndx1, int ndx2)
|
bitmap_t bdf_hexval(unsigned char *buf, int ndx1, int ndx2)
|
||||||
{
|
{
|
||||||
|
@ -796,7 +800,7 @@ int rotleft(unsigned char *dst, /* output buffer */
|
||||||
bitmap_t *src, unsigned int width, unsigned int height)
|
bitmap_t *src, unsigned int width, unsigned int height)
|
||||||
{
|
{
|
||||||
unsigned int i,j;
|
unsigned int i,j;
|
||||||
unsigned int src_words; /* # words of input image*/
|
unsigned int src_words; /* # words of input image */
|
||||||
unsigned int dst_mask; /* bit mask for destination */
|
unsigned int dst_mask; /* bit mask for destination */
|
||||||
bitmap_t src_mask; /* bit mask for source */
|
bitmap_t src_mask; /* bit mask for source */
|
||||||
|
|
||||||
|
@ -913,7 +917,7 @@ int gen_c_source(struct font* pf, char *path)
|
||||||
bitmap_t bitvalue=0;
|
bitmap_t bitvalue=0;
|
||||||
|
|
||||||
/* Skip missing glyphs */
|
/* Skip missing glyphs */
|
||||||
if (pf->offset && (pf->offset[i] == (unsigned int)-1))
|
if (pf->offset && (pf->offset[i] == -1))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
bits = pf->bits + (pf->offset? (int)pf->offset[i]: (pf->height * i));
|
bits = pf->bits + (pf->offset? (int)pf->offset[i]: (pf->height * i));
|
||||||
|
@ -994,7 +998,7 @@ int gen_c_source(struct font* pf, char *path)
|
||||||
"static const unsigned short _sysfont_offset[] = {\n");
|
"static const unsigned short _sysfont_offset[] = {\n");
|
||||||
|
|
||||||
for (i=0; i<pf->size; ++i) {
|
for (i=0; i<pf->size; ++i) {
|
||||||
if (pf->offset[i] == (unsigned int)-1) {
|
if (pf->offset[i] == -1) {
|
||||||
pf->offset[i] = pf->offset[pf->defaultchar - pf->firstchar];
|
pf->offset[i] = pf->offset[pf->defaultchar - pf->firstchar];
|
||||||
pf->offrot[i] = pf->offrot[pf->defaultchar - pf->firstchar];
|
pf->offrot[i] = pf->offrot[pf->defaultchar - pf->firstchar];
|
||||||
}
|
}
|
||||||
|
@ -1201,7 +1205,7 @@ int gen_fnt_file(struct font* pf, char *path)
|
||||||
unsigned char bytemap[512];
|
unsigned char bytemap[512];
|
||||||
|
|
||||||
/* Skip missing glyphs */
|
/* Skip missing glyphs */
|
||||||
if (pf->offset && (pf->offset[i] == (unsigned int)-1))
|
if (pf->offset && (pf->offset[i] == -1))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
bits = pf->bits + (pf->offset? (int)pf->offset[i]: (pf->height * i));
|
bits = pf->bits + (pf->offset? (int)pf->offset[i]: (pf->height * i));
|
||||||
|
@ -1231,7 +1235,7 @@ int gen_fnt_file(struct font* pf, char *path)
|
||||||
{
|
{
|
||||||
for (i=0; i<pf->size; ++i)
|
for (i=0; i<pf->size; ++i)
|
||||||
{
|
{
|
||||||
if (pf->offset[i] == (unsigned int)-1) {
|
if (pf->offset[i] == -1) {
|
||||||
pf->offrot[i] = pf->offrot[pf->defaultchar - pf->firstchar];
|
pf->offrot[i] = pf->offrot[pf->defaultchar - pf->firstchar];
|
||||||
}
|
}
|
||||||
if ( pf->bits_size < 0xFFDB )
|
if ( pf->bits_size < 0xFFDB )
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue