2002-09-18 15:38:49 +00:00
|
|
|
/*
|
|
|
|
* Convert BDF files to C source and/or Rockbox .fnt file format
|
|
|
|
*
|
|
|
|
* Copyright (c) 2002 by Greg Haerr <greg@censoft.com>
|
|
|
|
*
|
|
|
|
* What fun it is converting font data...
|
|
|
|
*
|
2009-03-06 22:50:47 +00:00
|
|
|
* 09/17/02 Version 1.0
|
2002-09-18 15:38:49 +00:00
|
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2009-03-07 22:09:00 +00:00
|
|
|
#include <stdarg.h>
|
2002-09-18 15:38:49 +00:00
|
|
|
#include <time.h>
|
|
|
|
|
2004-08-26 21:15:07 +00:00
|
|
|
#define ROTATE /* define this for the new, rotated format */
|
|
|
|
|
2010-05-17 20:55:55 +00:00
|
|
|
/* BEGIN font.h */
|
2010-05-16 15:15:29 +00:00
|
|
|
/* loadable font magic and version number */
|
2004-08-26 21:15:07 +00:00
|
|
|
#ifdef ROTATE
|
2009-03-06 22:50:47 +00:00
|
|
|
#define VERSION "RB12" /* newer version */
|
2004-08-26 21:15:07 +00:00
|
|
|
#else
|
2009-03-06 22:50:47 +00:00
|
|
|
#define VERSION "RB11"
|
2004-08-26 21:15:07 +00:00
|
|
|
#endif
|
2002-09-18 15:38:49 +00:00
|
|
|
|
2009-03-06 22:50:47 +00:00
|
|
|
/*
|
|
|
|
* bitmap_t helper macros
|
|
|
|
*/
|
2010-05-16 15:15:29 +00:00
|
|
|
typedef unsigned short bitmap_t; /* bitmap image unit size */
|
2009-03-06 22:50:47 +00:00
|
|
|
|
|
|
|
/* Number of words to hold a pixel line of width x pixels */
|
|
|
|
#define BITMAP_BITSPERIMAGE (sizeof(bitmap_t) * 8)
|
|
|
|
#define BITMAP_WORDS(x) (((x)+BITMAP_BITSPERIMAGE-1)/BITMAP_BITSPERIMAGE)
|
2002-09-20 08:07:51 +00:00
|
|
|
#define BITMAP_BYTES(x) (BITMAP_WORDS(x)*sizeof(bitmap_t))
|
2009-03-06 22:50:47 +00:00
|
|
|
#define BITMAP_BITVALUE(n) ((bitmap_t) (((bitmap_t) 1) << (n)))
|
|
|
|
#define BITMAP_FIRSTBIT (BITMAP_BITVALUE(BITMAP_BITSPERIMAGE - 1))
|
|
|
|
#define BITMAP_TESTBIT(m) ((m) & BITMAP_FIRSTBIT)
|
|
|
|
#define BITMAP_SHIFTBIT(m) ((bitmap_t) ((m) << 1))
|
2002-09-18 15:38:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* builtin C-based proportional/fixed font structure */
|
|
|
|
/* based on The Microwindows Project http://microwindows.org */
|
2002-09-20 08:07:51 +00:00
|
|
|
struct font {
|
2009-03-06 22:50:47 +00:00
|
|
|
int maxwidth; /* max width in pixels */
|
|
|
|
int height; /* height in pixels */
|
|
|
|
int ascent; /* ascent (baseline) height */
|
|
|
|
int firstchar; /* first character in bitmap */
|
|
|
|
int size; /* font size in glyphs ('holes' included) */
|
2011-03-05 18:36:51 +00:00
|
|
|
int depth; /* depth of the font, 0=1bit 1=4bit */
|
2009-03-06 22:50:47 +00:00
|
|
|
bitmap_t* bits; /* 16-bit right-padded bitmap data */
|
|
|
|
int* offset; /* offsets into bitmap data */
|
|
|
|
unsigned char* width; /* character widths or NULL if fixed */
|
|
|
|
int defaultchar; /* default char (not glyph index) */
|
|
|
|
int bits_size; /* # words of bitmap_t bits */
|
2002-09-18 15:38:49 +00:00
|
|
|
|
2009-03-05 23:06:00 +00:00
|
|
|
/* unused by runtime system, read in by convbdf */
|
2009-03-05 23:09:19 +00:00
|
|
|
int nchars; /* number of different glyphs */
|
2009-03-08 16:23:14 +00:00
|
|
|
int nchars_declared; /* number of glyphs as declared in the header */
|
|
|
|
int ascent_declared; /* ascent as declared in the header */
|
|
|
|
int descent_declared; /* descent as declared in the header */
|
2009-03-12 19:55:07 +00:00
|
|
|
int max_char_ascent; /* max. char ascent (before adjusting) */
|
|
|
|
int max_char_descent; /* max. char descent (before adjusting) */
|
2009-03-06 22:50:47 +00:00
|
|
|
unsigned int* offrot; /* offsets into rotated bitmap data */
|
|
|
|
char* name; /* font name */
|
|
|
|
char* facename; /* facename of font */
|
|
|
|
char* copyright; /* copyright info for loadable fonts */
|
|
|
|
int pixel_size;
|
|
|
|
int descent;
|
|
|
|
int fbbw, fbbh, fbbx, fbby;
|
2009-03-04 21:42:26 +00:00
|
|
|
|
|
|
|
/* 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;
|
2009-04-29 21:51:04 +00:00
|
|
|
|
|
|
|
/* default width in pixels (can be overwritten at char level) */
|
|
|
|
int default_width;
|
2002-09-20 08:07:51 +00:00
|
|
|
};
|
2010-05-17 20:55:55 +00:00
|
|
|
/* END font.h */
|
2002-09-18 15:38:49 +00:00
|
|
|
|
2009-03-08 16:23:14 +00:00
|
|
|
/* Description of how the ascent/descent is allowed to grow */
|
|
|
|
struct stretch {
|
|
|
|
int value; /* The delta value (in pixels or percents) */
|
|
|
|
int percent; /* Is the value in percents (true) or pixels (false)? */
|
|
|
|
int force; /* MUST the value be set (true) or is it just a max (false) */
|
|
|
|
};
|
|
|
|
|
2009-03-06 22:50:47 +00:00
|
|
|
#define isprefix(buf,str) (!strncmp(buf, str, strlen(str)))
|
|
|
|
#define strequal(s1,s2) (!strcmp(s1, s2))
|
2002-09-18 15:38:49 +00:00
|
|
|
|
2009-03-05 21:27:55 +00:00
|
|
|
#define MAX(a,b) ((a) > (b) ? (a) : (b))
|
|
|
|
#define MIN(a,b) ((a) < (b) ? (a) : (b))
|
|
|
|
|
2009-03-13 18:56:55 +00:00
|
|
|
#ifdef ROTATE
|
|
|
|
#define ROTATION_BUF_SIZE 2048
|
|
|
|
#endif
|
|
|
|
|
2009-03-06 23:32:08 +00:00
|
|
|
/* Depending on the verbosity level some warnings are printed or not */
|
2009-03-07 22:09:00 +00:00
|
|
|
int verbosity_level = 0;
|
2009-03-08 16:23:14 +00:00
|
|
|
int trace = 0;
|
2009-03-07 22:09:00 +00:00
|
|
|
|
|
|
|
/* Prints a warning of the specified verbosity level. It will only be
|
|
|
|
really printed if the level is >= the level set in the settings */
|
|
|
|
void print_warning(int level, const char *fmt, ...);
|
|
|
|
void print_error(const char *fmt, ...);
|
|
|
|
void print_info(const char *fmt, ...);
|
2009-03-08 16:23:14 +00:00
|
|
|
void print_trace(const char *fmt, ...);
|
|
|
|
#define VL_CLIP_FONT 1 /* Verbosity level for clip related warnings at font level */
|
|
|
|
#define VL_CLIP_CHAR 2 /* Verbosity level for clip related warnings at char level */
|
|
|
|
#define VL_MISC 1 /* Verbosity level for other warnings */
|
2009-03-06 23:32:08 +00:00
|
|
|
|
2002-09-18 15:38:49 +00:00
|
|
|
int gen_c = 0;
|
Make the build system create a sysfont.h which includes font information for the system font. Available #defines are: SYSFONT_NAME, SYSFONT_FACENAME, SYSFONT_WIDTH, SYSFONT_HEIGHT, SYSFONT_SIZE, SYSFONT_ASCENT, SYSFONT_DESCENT, SYSFONT_FIRST_CHAR, SYSFONT_LAST_CHAR, SYSFONT_DEFAULT_CHAR, SYSFONT_PROPORTIONAL, SYSFONT_COPYRIGHT, SYSFONT_BITS_SIZE.
Also fix a small bug in the iPod bootloader printf() code and use printf() for PortalPlayer bootloaders too.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@12041 a1c6a512-1295-4272-9138-f99709370657
2007-01-17 12:20:38 +00:00
|
|
|
int gen_h = 0;
|
2002-09-18 15:38:49 +00:00
|
|
|
int gen_fnt = 0;
|
|
|
|
int gen_map = 1;
|
|
|
|
int start_char = 0;
|
|
|
|
int limit_char = 65535;
|
|
|
|
int oflag = 0;
|
|
|
|
char outfile[256];
|
|
|
|
|
2009-03-08 16:23:14 +00:00
|
|
|
struct stretch stretch_ascent = { 0, 0, 1 }; /* Don't allow ascent to grow by default */
|
|
|
|
struct stretch stretch_descent = { 0, 0, 1 }; /* Don't allow descent to grow by default */
|
|
|
|
|
|
|
|
|
2002-09-20 08:07:51 +00:00
|
|
|
void usage(void);
|
|
|
|
void getopts(int *pac, char ***pav);
|
|
|
|
int convbdf(char *path);
|
2002-09-18 15:38:49 +00:00
|
|
|
|
2002-09-20 08:07:51 +00:00
|
|
|
void free_font(struct font* pf);
|
|
|
|
struct font* bdf_read_font(char *path);
|
|
|
|
int bdf_read_header(FILE *fp, struct font* pf);
|
|
|
|
int bdf_read_bitmaps(FILE *fp, struct font* pf);
|
2009-03-08 16:23:14 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
Counts the glyphs and determines the max dimensions of glyphs
|
|
|
|
(fills the fields nchars, maxwidth, max_over_ascent, max_over_descent).
|
|
|
|
Returns 0 on failure or not-0 on success.
|
|
|
|
*/
|
|
|
|
int bdf_analyze_font(FILE *fp, struct font* pf);
|
|
|
|
void bdf_correct_bbx(int *width, int *bbx); /* Corrects bbx and width if bbx<0 */
|
|
|
|
|
|
|
|
/* Corrects the ascent and returns the new value (value to use) */
|
|
|
|
int adjust_ascent(int ascent, int overflow, struct stretch *stretch);
|
|
|
|
|
2002-09-20 08:07:51 +00:00
|
|
|
char * bdf_getline(FILE *fp, char *buf, int len);
|
|
|
|
bitmap_t bdf_hexval(unsigned char *buf, int ndx1, int ndx2);
|
2002-09-18 15:38:49 +00:00
|
|
|
|
2002-09-20 08:07:51 +00:00
|
|
|
int gen_c_source(struct font* pf, char *path);
|
Make the build system create a sysfont.h which includes font information for the system font. Available #defines are: SYSFONT_NAME, SYSFONT_FACENAME, SYSFONT_WIDTH, SYSFONT_HEIGHT, SYSFONT_SIZE, SYSFONT_ASCENT, SYSFONT_DESCENT, SYSFONT_FIRST_CHAR, SYSFONT_LAST_CHAR, SYSFONT_DEFAULT_CHAR, SYSFONT_PROPORTIONAL, SYSFONT_COPYRIGHT, SYSFONT_BITS_SIZE.
Also fix a small bug in the iPod bootloader printf() code and use printf() for PortalPlayer bootloaders too.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@12041 a1c6a512-1295-4272-9138-f99709370657
2007-01-17 12:20:38 +00:00
|
|
|
int gen_h_header(struct font* pf, char *path);
|
2002-09-20 08:07:51 +00:00
|
|
|
int gen_fnt_file(struct font* pf, char *path);
|
2002-09-18 15:38:49 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
usage(void)
|
|
|
|
{
|
2009-03-08 16:23:14 +00:00
|
|
|
/* We use string array because some C compilers issue warnings about too long strings */
|
|
|
|
char *help[] = {
|
|
|
|
"Usage: convbdf [options] [input-files]\n",
|
|
|
|
" convbdf [options] [-o output-file] [single-input-file]\n",
|
|
|
|
"Options:\n",
|
|
|
|
" -c Convert .bdf to .c source file\n",
|
|
|
|
" -h Convert .bdf to .h header file (to create sysfont.h)\n",
|
|
|
|
" -f Convert .bdf to .fnt font file\n",
|
|
|
|
" -s N Start output at character encodings >= N\n",
|
|
|
|
" -l N Limit output to character encodings <= N\n",
|
|
|
|
" -n Don't generate bitmaps as comments in .c file\n",
|
|
|
|
" -a N[%][!] Allow the ascent to grow N pixels/% to avoid glyph clipping\n",
|
|
|
|
" -d N[%][!] Allow the descent to grow N pixels/% to avoid glyph clipping\n",
|
2010-07-21 19:33:16 +00:00
|
|
|
" An ! in the -a and -d options forces the growth; N may be negative\n",
|
2009-03-08 16:23:14 +00:00
|
|
|
" -v N Verbosity level: 0=quite quiet, 1=more verbose, 2=even more, etc.\n",
|
|
|
|
" -t Print internal tracing messages\n",
|
|
|
|
NULL /* Must be the last element in the array */
|
2009-03-06 22:50:47 +00:00
|
|
|
};
|
2002-09-18 15:38:49 +00:00
|
|
|
|
2009-03-08 16:23:14 +00:00
|
|
|
char **p = help;
|
|
|
|
while (*p != NULL)
|
|
|
|
print_info("%s", *(p++));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void parse_ascent_opt(char *val, struct stretch *opt) {
|
|
|
|
char buf[256];
|
|
|
|
char *p;
|
|
|
|
strcpy(buf, val);
|
|
|
|
|
|
|
|
opt->force = 0;
|
|
|
|
opt->percent = 0;
|
|
|
|
p = buf + strlen(buf);
|
|
|
|
while (p > buf) {
|
|
|
|
p--;
|
|
|
|
if (*p == '%') {
|
|
|
|
opt->percent = 1;
|
|
|
|
*p = '\0';
|
|
|
|
}
|
|
|
|
else if (*p == '!') {
|
|
|
|
opt->force = 1;
|
|
|
|
*p = '\0';
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
opt->value = atoi(buf);
|
2002-09-18 15:38:49 +00:00
|
|
|
}
|
|
|
|
|
2010-05-17 20:55:55 +00:00
|
|
|
/* parse command line options */
|
2002-09-20 08:07:51 +00:00
|
|
|
void getopts(int *pac, char ***pav)
|
2002-09-18 15:38:49 +00:00
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
char **av;
|
|
|
|
int ac;
|
|
|
|
|
|
|
|
ac = *pac;
|
|
|
|
av = *pav;
|
|
|
|
while (ac > 0 && av[0][0] == '-') {
|
|
|
|
p = &av[0][1];
|
|
|
|
while( *p)
|
|
|
|
switch(*p++) {
|
2009-03-07 22:09:00 +00:00
|
|
|
case ' ': /* multiple -args on av[] */
|
2002-09-18 15:38:49 +00:00
|
|
|
while( *p && *p == ' ')
|
|
|
|
p++;
|
2009-03-07 22:09:00 +00:00
|
|
|
if( *p++ != '-') /* next option must have dash */
|
2002-09-18 15:38:49 +00:00
|
|
|
p = "";
|
2009-03-07 22:09:00 +00:00
|
|
|
break; /* proceed to next option */
|
|
|
|
case 'c': /* generate .c output */
|
2002-09-18 15:38:49 +00:00
|
|
|
gen_c = 1;
|
|
|
|
break;
|
2009-03-07 22:09:00 +00:00
|
|
|
case 'h': /* generate .h output */
|
Make the build system create a sysfont.h which includes font information for the system font. Available #defines are: SYSFONT_NAME, SYSFONT_FACENAME, SYSFONT_WIDTH, SYSFONT_HEIGHT, SYSFONT_SIZE, SYSFONT_ASCENT, SYSFONT_DESCENT, SYSFONT_FIRST_CHAR, SYSFONT_LAST_CHAR, SYSFONT_DEFAULT_CHAR, SYSFONT_PROPORTIONAL, SYSFONT_COPYRIGHT, SYSFONT_BITS_SIZE.
Also fix a small bug in the iPod bootloader printf() code and use printf() for PortalPlayer bootloaders too.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@12041 a1c6a512-1295-4272-9138-f99709370657
2007-01-17 12:20:38 +00:00
|
|
|
gen_h = 1;
|
|
|
|
break;
|
2009-03-07 22:09:00 +00:00
|
|
|
case 'f': /* generate .fnt output */
|
2002-09-18 15:38:49 +00:00
|
|
|
gen_fnt = 1;
|
|
|
|
break;
|
2009-03-07 22:09:00 +00:00
|
|
|
case 'n': /* don't gen bitmap comments */
|
2002-09-18 15:38:49 +00:00
|
|
|
gen_map = 0;
|
|
|
|
break;
|
2009-03-07 22:09:00 +00:00
|
|
|
case 'o': /* set output file */
|
2002-09-18 15:38:49 +00:00
|
|
|
oflag = 1;
|
|
|
|
if (*p) {
|
|
|
|
strcpy(outfile, p);
|
|
|
|
while (*p && *p != ' ')
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
av++; ac--;
|
|
|
|
if (ac > 0)
|
|
|
|
strcpy(outfile, av[0]);
|
|
|
|
}
|
|
|
|
break;
|
2009-03-07 22:09:00 +00:00
|
|
|
case 'l': /* set encoding limit */
|
2002-09-18 15:38:49 +00:00
|
|
|
if (*p) {
|
|
|
|
limit_char = atoi(p);
|
|
|
|
while (*p && *p != ' ')
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
av++; ac--;
|
|
|
|
if (ac > 0)
|
|
|
|
limit_char = atoi(av[0]);
|
|
|
|
}
|
|
|
|
break;
|
2009-03-07 22:09:00 +00:00
|
|
|
case 's': /* set encoding start */
|
2002-09-18 15:38:49 +00:00
|
|
|
if (*p) {
|
|
|
|
start_char = atoi(p);
|
|
|
|
while (*p && *p != ' ')
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
av++; ac--;
|
|
|
|
if (ac > 0)
|
|
|
|
start_char = atoi(av[0]);
|
|
|
|
}
|
|
|
|
break;
|
2009-03-08 16:23:14 +00:00
|
|
|
case 'a': /* ascent growth */
|
|
|
|
if (*p) {
|
|
|
|
parse_ascent_opt(p, &stretch_ascent);
|
|
|
|
while (*p && *p != ' ')
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
av++; ac--;
|
|
|
|
if (ac > 0)
|
|
|
|
parse_ascent_opt(av[0], &stretch_ascent);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'd': /* descent growth */
|
|
|
|
if (*p) {
|
|
|
|
parse_ascent_opt(p, &stretch_descent);
|
|
|
|
while (*p && *p != ' ')
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
av++; ac--;
|
|
|
|
if (ac > 0)
|
|
|
|
parse_ascent_opt(av[0], &stretch_descent);
|
|
|
|
}
|
|
|
|
break;
|
2009-03-06 23:32:08 +00:00
|
|
|
case 'v': /* verbosity */
|
|
|
|
if (*p) {
|
2009-03-07 22:09:00 +00:00
|
|
|
verbosity_level = atoi(p);
|
2009-03-06 23:32:08 +00:00
|
|
|
while (*p && *p != ' ')
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
av++; ac--;
|
|
|
|
if (ac > 0)
|
2009-03-07 22:09:00 +00:00
|
|
|
verbosity_level = atoi(av[0]);
|
2009-03-06 23:32:08 +00:00
|
|
|
}
|
|
|
|
break;
|
2009-03-08 16:23:14 +00:00
|
|
|
case 't': /* tracing */
|
|
|
|
trace = 1;
|
|
|
|
break;
|
2002-09-18 15:38:49 +00:00
|
|
|
default:
|
2009-03-07 22:09:00 +00:00
|
|
|
print_info("Unknown option ignored: %c\n", *(p-1));
|
2002-09-18 15:38:49 +00:00
|
|
|
}
|
|
|
|
++av; --ac;
|
|
|
|
}
|
|
|
|
*pac = ac;
|
|
|
|
*pav = av;
|
|
|
|
}
|
|
|
|
|
2009-03-07 22:09:00 +00:00
|
|
|
void print_warning(int level, const char *fmt, ...) {
|
|
|
|
if (verbosity_level >= level) {
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, fmt);
|
|
|
|
fprintf(stderr, " WARN: ");
|
|
|
|
vfprintf(stderr, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-08 16:23:14 +00:00
|
|
|
void print_trace(const char *fmt, ...) {
|
|
|
|
if (trace) {
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, fmt);
|
|
|
|
fprintf(stderr, "TRACE: ");
|
|
|
|
vfprintf(stderr, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-07 22:09:00 +00:00
|
|
|
void print_error(const char *fmt, ...) {
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, fmt);
|
|
|
|
fprintf(stderr, "ERROR: ");
|
|
|
|
vfprintf(stderr, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
void print_info(const char *fmt, ...) {
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, fmt);
|
|
|
|
fprintf(stderr, " INFO: ");
|
|
|
|
vfprintf(stderr, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
2009-03-06 22:50:47 +00:00
|
|
|
/* remove directory prefix and file suffix from full path */
|
2002-09-20 08:07:51 +00:00
|
|
|
char *basename(char *path)
|
2002-09-18 15:38:49 +00:00
|
|
|
{
|
|
|
|
char *p, *b;
|
|
|
|
static char base[256];
|
|
|
|
|
2009-03-06 22:50:47 +00:00
|
|
|
/* remove prepended path and extension */
|
2002-09-18 15:38:49 +00:00
|
|
|
b = path;
|
|
|
|
for (p=path; *p; ++p) {
|
|
|
|
if (*p == '/')
|
|
|
|
b = p + 1;
|
|
|
|
}
|
|
|
|
strcpy(base, b);
|
|
|
|
for (p=base; *p; ++p) {
|
|
|
|
if (*p == '.') {
|
|
|
|
*p = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return base;
|
|
|
|
}
|
|
|
|
|
2002-09-20 08:07:51 +00:00
|
|
|
int convbdf(char *path)
|
2002-09-18 15:38:49 +00:00
|
|
|
{
|
2002-09-20 08:07:51 +00:00
|
|
|
struct font* pf;
|
2002-09-18 15:38:49 +00:00
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
pf = bdf_read_font(path);
|
|
|
|
if (!pf)
|
|
|
|
exit(1);
|
|
|
|
|
|
|
|
if (gen_c) {
|
|
|
|
if (!oflag) {
|
|
|
|
strcpy(outfile, basename(path));
|
|
|
|
strcat(outfile, ".c");
|
|
|
|
}
|
|
|
|
ret |= gen_c_source(pf, outfile);
|
|
|
|
}
|
Make the build system create a sysfont.h which includes font information for the system font. Available #defines are: SYSFONT_NAME, SYSFONT_FACENAME, SYSFONT_WIDTH, SYSFONT_HEIGHT, SYSFONT_SIZE, SYSFONT_ASCENT, SYSFONT_DESCENT, SYSFONT_FIRST_CHAR, SYSFONT_LAST_CHAR, SYSFONT_DEFAULT_CHAR, SYSFONT_PROPORTIONAL, SYSFONT_COPYRIGHT, SYSFONT_BITS_SIZE.
Also fix a small bug in the iPod bootloader printf() code and use printf() for PortalPlayer bootloaders too.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@12041 a1c6a512-1295-4272-9138-f99709370657
2007-01-17 12:20:38 +00:00
|
|
|
|
|
|
|
if (gen_h) {
|
|
|
|
if (!oflag) {
|
|
|
|
strcpy(outfile, basename(path));
|
|
|
|
strcat(outfile, ".h");
|
|
|
|
}
|
|
|
|
ret |= gen_h_header(pf, outfile);
|
|
|
|
}
|
2002-09-18 15:38:49 +00:00
|
|
|
|
|
|
|
if (gen_fnt) {
|
|
|
|
if (!oflag) {
|
|
|
|
strcpy(outfile, basename(path));
|
|
|
|
strcat(outfile, ".fnt");
|
|
|
|
}
|
|
|
|
ret |= gen_fnt_file(pf, outfile);
|
|
|
|
}
|
|
|
|
|
|
|
|
free_font(pf);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2002-09-20 08:07:51 +00:00
|
|
|
int main(int ac, char **av)
|
2002-09-18 15:38:49 +00:00
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
2009-03-06 22:50:47 +00:00
|
|
|
++av; --ac; /* skip av[0] */
|
|
|
|
getopts(&ac, &av); /* read command line options */
|
2002-09-18 15:38:49 +00:00
|
|
|
|
Make the build system create a sysfont.h which includes font information for the system font. Available #defines are: SYSFONT_NAME, SYSFONT_FACENAME, SYSFONT_WIDTH, SYSFONT_HEIGHT, SYSFONT_SIZE, SYSFONT_ASCENT, SYSFONT_DESCENT, SYSFONT_FIRST_CHAR, SYSFONT_LAST_CHAR, SYSFONT_DEFAULT_CHAR, SYSFONT_PROPORTIONAL, SYSFONT_COPYRIGHT, SYSFONT_BITS_SIZE.
Also fix a small bug in the iPod bootloader printf() code and use printf() for PortalPlayer bootloaders too.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@12041 a1c6a512-1295-4272-9138-f99709370657
2007-01-17 12:20:38 +00:00
|
|
|
if (ac < 1 || (!gen_c && !gen_h && !gen_fnt)) {
|
2002-09-18 15:38:49 +00:00
|
|
|
usage();
|
|
|
|
exit(1);
|
|
|
|
}
|
2010-05-13 21:27:42 +00:00
|
|
|
|
2002-09-18 15:38:49 +00:00
|
|
|
if (oflag) {
|
Make the build system create a sysfont.h which includes font information for the system font. Available #defines are: SYSFONT_NAME, SYSFONT_FACENAME, SYSFONT_WIDTH, SYSFONT_HEIGHT, SYSFONT_SIZE, SYSFONT_ASCENT, SYSFONT_DESCENT, SYSFONT_FIRST_CHAR, SYSFONT_LAST_CHAR, SYSFONT_DEFAULT_CHAR, SYSFONT_PROPORTIONAL, SYSFONT_COPYRIGHT, SYSFONT_BITS_SIZE.
Also fix a small bug in the iPod bootloader printf() code and use printf() for PortalPlayer bootloaders too.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@12041 a1c6a512-1295-4272-9138-f99709370657
2007-01-17 12:20:38 +00:00
|
|
|
if (ac > 1 || (gen_c && gen_fnt) || (gen_c && gen_h) || (gen_h && gen_fnt)) {
|
2002-09-18 15:38:49 +00:00
|
|
|
usage();
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
while (ac > 0) {
|
|
|
|
ret |= convbdf(av[0]);
|
|
|
|
++av; --ac;
|
|
|
|
}
|
|
|
|
|
|
|
|
exit(ret);
|
|
|
|
}
|
|
|
|
|
2009-03-06 22:50:47 +00:00
|
|
|
/* free font structure */
|
2002-09-20 08:07:51 +00:00
|
|
|
void free_font(struct font* pf)
|
2002-09-18 15:38:49 +00:00
|
|
|
{
|
|
|
|
if (!pf)
|
|
|
|
return;
|
|
|
|
if (pf->name)
|
|
|
|
free(pf->name);
|
|
|
|
if (pf->facename)
|
|
|
|
free(pf->facename);
|
|
|
|
if (pf->bits)
|
|
|
|
free(pf->bits);
|
|
|
|
if (pf->offset)
|
|
|
|
free(pf->offset);
|
2004-08-26 21:15:07 +00:00
|
|
|
if (pf->offrot)
|
|
|
|
free(pf->offrot);
|
2002-09-18 15:38:49 +00:00
|
|
|
if (pf->width)
|
|
|
|
free(pf->width);
|
|
|
|
free(pf);
|
|
|
|
}
|
|
|
|
|
2009-03-06 22:50:47 +00:00
|
|
|
/* build incore structure from .bdf file */
|
2002-09-20 08:07:51 +00:00
|
|
|
struct font* bdf_read_font(char *path)
|
2002-09-18 15:38:49 +00:00
|
|
|
{
|
|
|
|
FILE *fp;
|
2002-09-20 08:07:51 +00:00
|
|
|
struct font* pf;
|
2002-09-18 15:38:49 +00:00
|
|
|
|
|
|
|
fp = fopen(path, "rb");
|
|
|
|
if (!fp) {
|
2009-03-07 22:09:00 +00:00
|
|
|
print_error("Error opening file: %s\n", path);
|
2002-09-18 15:38:49 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2002-09-20 08:07:51 +00:00
|
|
|
pf = (struct font*)calloc(1, sizeof(struct font));
|
2002-09-18 15:38:49 +00:00
|
|
|
if (!pf)
|
|
|
|
goto errout;
|
2009-03-06 22:50:47 +00:00
|
|
|
memset(pf, 0, sizeof(struct font));
|
|
|
|
|
2002-09-18 15:38:49 +00:00
|
|
|
pf->name = strdup(basename(path));
|
|
|
|
|
|
|
|
if (!bdf_read_header(fp, pf)) {
|
2009-03-07 22:09:00 +00:00
|
|
|
print_error("Error reading font header\n");
|
2002-09-18 15:38:49 +00:00
|
|
|
goto errout;
|
|
|
|
}
|
2009-03-08 16:23:14 +00:00
|
|
|
print_trace("Read font header, nchars_decl=%d\n", pf->nchars_declared);
|
|
|
|
|
|
|
|
if (!bdf_analyze_font(fp, pf)) {
|
|
|
|
print_error("Error analyzing the font\n");
|
|
|
|
goto errout;
|
|
|
|
}
|
|
|
|
print_trace("Analyzed font, nchars=%d, maxwidth=%d, asc_over=%d, desc_over=%d\n",
|
|
|
|
pf->nchars, pf->maxwidth, pf->max_over_ascent, pf->max_over_descent);
|
|
|
|
|
|
|
|
if (pf->nchars != pf->nchars_declared) {
|
|
|
|
print_warning(VL_MISC, "The declared number of chars (%d) "
|
|
|
|
"does not match the real number (%d)\n",
|
|
|
|
pf->nchars_declared, pf->nchars);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Correct ascent/descent if necessary */
|
|
|
|
pf->ascent = adjust_ascent(pf->ascent_declared, pf->max_over_ascent, &stretch_ascent);
|
|
|
|
if (pf->ascent != pf->ascent_declared) {
|
|
|
|
print_info("Font ascent has been changed from %d to %d\n",
|
|
|
|
pf->ascent_declared, pf->ascent);
|
|
|
|
}
|
|
|
|
pf->descent = adjust_ascent(pf->descent, pf->max_over_descent, &stretch_descent);
|
|
|
|
if (pf->descent != pf->descent_declared) {
|
|
|
|
print_info("Font descent has been changed from %d to %d\n",
|
|
|
|
pf->descent_declared, pf->descent);
|
|
|
|
}
|
|
|
|
pf->height = pf->ascent + pf->descent;
|
|
|
|
if (pf->height != pf->ascent_declared + pf->descent_declared) {
|
|
|
|
print_warning(VL_CLIP_FONT, "Generated font's height: %d\n", pf->height);
|
|
|
|
}
|
|
|
|
|
2009-03-12 19:55:07 +00:00
|
|
|
if (pf->ascent > pf->max_char_ascent) {
|
|
|
|
print_trace("Font's ascent could be reduced by %d to %d without clipping\n",
|
|
|
|
(pf->ascent - pf->max_char_ascent), pf->max_char_ascent);
|
|
|
|
}
|
|
|
|
if (pf->descent > pf->max_char_descent) {
|
|
|
|
print_trace("Font's descent could be reduced by %d to %d without clipping\n",
|
|
|
|
(pf->descent - pf->max_char_descent), pf->max_char_descent);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-03-08 16:23:14 +00:00
|
|
|
/* Alocate memory */
|
|
|
|
pf->bits_size = pf->size * BITMAP_WORDS(pf->maxwidth) * pf->height;
|
|
|
|
pf->bits = (bitmap_t *)malloc(pf->bits_size * sizeof(bitmap_t));
|
|
|
|
pf->offset = (int *)malloc(pf->size * sizeof(int));
|
|
|
|
pf->offrot = (unsigned int *)malloc(pf->size * sizeof(unsigned int));
|
|
|
|
pf->width = (unsigned char *)malloc(pf->size * sizeof(unsigned char));
|
|
|
|
|
|
|
|
if (!pf->bits || !pf->offset || !pf->offrot || !pf->width) {
|
|
|
|
print_error("no memory for font load\n");
|
|
|
|
goto errout;
|
|
|
|
}
|
2002-09-18 15:38:49 +00:00
|
|
|
|
2009-03-04 21:42:26 +00:00
|
|
|
pf->num_clipped_ascent = pf->num_clipped_descent = pf->num_clipped = 0;
|
2009-03-08 16:23:14 +00:00
|
|
|
pf->max_over_ascent = pf->max_over_descent = 0;
|
2009-03-04 21:42:26 +00:00
|
|
|
|
2002-09-18 15:38:49 +00:00
|
|
|
if (!bdf_read_bitmaps(fp, pf)) {
|
2009-03-07 22:09:00 +00:00
|
|
|
print_error("Error reading font bitmaps\n");
|
2002-09-18 15:38:49 +00:00
|
|
|
goto errout;
|
|
|
|
}
|
2009-03-08 16:23:14 +00:00
|
|
|
print_trace("Read bitmaps\n");
|
2009-03-04 21:42:26 +00:00
|
|
|
|
2009-03-07 22:09:00 +00:00
|
|
|
if (pf->num_clipped > 0) {
|
2009-03-08 16:23:14 +00:00
|
|
|
print_warning(VL_CLIP_FONT, "%d character(s) out of %d were clipped "
|
2009-03-07 22:09:00 +00:00
|
|
|
"(%d at ascent, %d at descent)\n",
|
|
|
|
pf->num_clipped, pf->nchars,
|
|
|
|
pf->num_clipped_ascent, pf->num_clipped_descent);
|
2009-03-08 16:23:14 +00:00
|
|
|
print_warning(VL_CLIP_FONT, "max overflows: %d pixel(s) at ascent, %d pixel(s) at descent\n",
|
2009-03-07 22:09:00 +00:00
|
|
|
pf->max_over_ascent, pf->max_over_descent);
|
2009-03-04 21:42:26 +00:00
|
|
|
}
|
2002-09-18 15:38:49 +00:00
|
|
|
|
|
|
|
fclose(fp);
|
|
|
|
return pf;
|
|
|
|
|
|
|
|
errout:
|
|
|
|
fclose(fp);
|
|
|
|
free_font(pf);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-03-06 22:50:47 +00:00
|
|
|
/* read bdf font header information, return 0 on error */
|
2002-09-20 08:07:51 +00:00
|
|
|
int bdf_read_header(FILE *fp, struct font* pf)
|
2002-09-18 15:38:49 +00:00
|
|
|
{
|
|
|
|
int encoding;
|
|
|
|
int firstchar = 65535;
|
|
|
|
int lastchar = -1;
|
|
|
|
char buf[256];
|
|
|
|
char facename[256];
|
|
|
|
char copyright[256];
|
2009-04-29 21:51:04 +00:00
|
|
|
int is_header = 1;
|
2002-09-18 15:38:49 +00:00
|
|
|
|
2009-03-06 22:50:47 +00:00
|
|
|
/* set certain values to errors for later error checking */
|
2002-09-18 15:38:49 +00:00
|
|
|
pf->defaultchar = -1;
|
|
|
|
pf->ascent = -1;
|
|
|
|
pf->descent = -1;
|
2009-04-29 21:51:04 +00:00
|
|
|
pf->default_width = -1;
|
2002-09-18 15:38:49 +00:00
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
if (!bdf_getline(fp, buf, sizeof(buf))) {
|
2009-03-07 22:09:00 +00:00
|
|
|
print_error("EOF on file\n");
|
2002-09-18 15:38:49 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2009-03-06 22:50:47 +00:00
|
|
|
if (isprefix(buf, "FONT ")) { /* not required */
|
2002-09-18 15:38:49 +00:00
|
|
|
if (sscanf(buf, "FONT %[^\n]", facename) != 1) {
|
2009-03-07 22:09:00 +00:00
|
|
|
print_error("bad 'FONT'\n");
|
2002-09-18 15:38:49 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
pf->facename = strdup(facename);
|
|
|
|
continue;
|
|
|
|
}
|
2009-03-06 22:50:47 +00:00
|
|
|
if (isprefix(buf, "COPYRIGHT ")) { /* not required */
|
2002-09-18 15:38:49 +00:00
|
|
|
if (sscanf(buf, "COPYRIGHT \"%[^\"]", copyright) != 1) {
|
2009-03-07 22:09:00 +00:00
|
|
|
print_error("bad 'COPYRIGHT'\n");
|
2002-09-18 15:38:49 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
pf->copyright = strdup(copyright);
|
|
|
|
continue;
|
|
|
|
}
|
2009-03-06 22:50:47 +00:00
|
|
|
if (isprefix(buf, "DEFAULT_CHAR ")) { /* not required */
|
2002-09-18 15:38:49 +00:00
|
|
|
if (sscanf(buf, "DEFAULT_CHAR %d", &pf->defaultchar) != 1) {
|
2009-03-07 22:09:00 +00:00
|
|
|
print_error("bad 'DEFAULT_CHAR'\n");
|
2002-09-18 15:38:49 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (isprefix(buf, "FONT_DESCENT ")) {
|
2009-03-08 16:23:14 +00:00
|
|
|
if (sscanf(buf, "FONT_DESCENT %d", &pf->descent_declared) != 1) {
|
2009-03-07 22:09:00 +00:00
|
|
|
print_error("bad 'FONT_DESCENT'\n");
|
2002-09-18 15:38:49 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2009-03-08 16:23:14 +00:00
|
|
|
pf->descent = pf->descent_declared; /* For now */
|
2002-09-18 15:38:49 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (isprefix(buf, "FONT_ASCENT ")) {
|
2009-03-08 16:23:14 +00:00
|
|
|
if (sscanf(buf, "FONT_ASCENT %d", &pf->ascent_declared) != 1) {
|
2009-03-07 22:09:00 +00:00
|
|
|
print_error("bad 'FONT_ASCENT'\n");
|
2002-09-18 15:38:49 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2009-03-08 16:23:14 +00:00
|
|
|
pf->ascent = pf->ascent_declared; /* For now */
|
2002-09-18 15:38:49 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (isprefix(buf, "FONTBOUNDINGBOX ")) {
|
|
|
|
if (sscanf(buf, "FONTBOUNDINGBOX %d %d %d %d",
|
|
|
|
&pf->fbbw, &pf->fbbh, &pf->fbbx, &pf->fbby) != 4) {
|
2009-03-07 22:09:00 +00:00
|
|
|
print_error("bad 'FONTBOUNDINGBOX'\n");
|
2002-09-18 15:38:49 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (isprefix(buf, "CHARS ")) {
|
2009-03-08 16:23:14 +00:00
|
|
|
if (sscanf(buf, "CHARS %d", &pf->nchars_declared) != 1) {
|
2009-03-07 22:09:00 +00:00
|
|
|
print_error("bad 'CHARS'\n");
|
2002-09-18 15:38:49 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
2009-04-30 05:07:45 +00:00
|
|
|
if (isprefix(buf, "STARTCHAR")) {
|
2009-04-29 21:51:04 +00:00
|
|
|
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;
|
|
|
|
}
|
2002-09-18 15:38:49 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Reading ENCODING is necessary to get firstchar/lastchar
|
|
|
|
* which is needed to pre-calculate our offset and widths
|
|
|
|
* array sizes.
|
|
|
|
*/
|
|
|
|
if (isprefix(buf, "ENCODING ")) {
|
|
|
|
if (sscanf(buf, "ENCODING %d", &encoding) != 1) {
|
2009-03-07 22:09:00 +00:00
|
|
|
print_error("bad 'ENCODING'\n");
|
2002-09-18 15:38:49 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2004-08-27 00:34:15 +00:00
|
|
|
if (encoding >= 0 &&
|
2002-09-20 08:07:51 +00:00
|
|
|
encoding <= limit_char &&
|
|
|
|
encoding >= start_char) {
|
|
|
|
|
2002-09-18 15:38:49 +00:00
|
|
|
if (firstchar > encoding)
|
|
|
|
firstchar = encoding;
|
|
|
|
if (lastchar < encoding)
|
|
|
|
lastchar = encoding;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (strequal(buf, "ENDFONT"))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-05-17 20:55:55 +00:00
|
|
|
/* calc font height */
|
2002-09-18 15:38:49 +00:00
|
|
|
if (pf->ascent < 0 || pf->descent < 0 || firstchar < 0) {
|
2009-03-07 22:09:00 +00:00
|
|
|
print_error("Invalid BDF file, requires FONT_ASCENT/FONT_DESCENT/ENCODING\n");
|
2002-09-18 15:38:49 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
pf->height = pf->ascent + pf->descent;
|
|
|
|
|
2009-03-06 22:50:47 +00:00
|
|
|
/* calc default char */
|
2002-09-20 08:07:51 +00:00
|
|
|
if (pf->defaultchar < 0 ||
|
|
|
|
pf->defaultchar < firstchar ||
|
2005-12-08 19:25:15 +00:00
|
|
|
pf->defaultchar > limit_char ||
|
|
|
|
pf->defaultchar > lastchar)
|
2002-09-18 15:38:49 +00:00
|
|
|
pf->defaultchar = firstchar;
|
|
|
|
|
2009-03-06 22:50:47 +00:00
|
|
|
/* calc font size (offset/width entries) */
|
2002-09-18 15:38:49 +00:00
|
|
|
pf->firstchar = firstchar;
|
|
|
|
pf->size = lastchar - firstchar + 1;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2009-03-09 21:09:26 +00:00
|
|
|
/*
|
|
|
|
* TODO: rework the code to avoid logics duplication in
|
|
|
|
* bdf_read_bitmaps and bdf_analyze_font
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2009-03-06 22:50:47 +00:00
|
|
|
/* read bdf font bitmaps, return 0 on error */
|
2002-09-20 08:07:51 +00:00
|
|
|
int bdf_read_bitmaps(FILE *fp, struct font* pf)
|
2002-09-18 15:38:49 +00:00
|
|
|
{
|
2006-02-08 13:05:37 +00:00
|
|
|
int ofs = 0;
|
|
|
|
int ofr = 0;
|
2002-09-18 15:38:49 +00:00
|
|
|
int i, k, encoding, width;
|
|
|
|
int bbw, bbh, bbx, bby;
|
|
|
|
int proportional = 0;
|
|
|
|
int encodetable = 0;
|
2010-05-17 20:55:55 +00:00
|
|
|
int offset;
|
2002-09-18 15:38:49 +00:00
|
|
|
char buf[256];
|
2009-03-06 22:50:47 +00:00
|
|
|
bitmap_t *ch_bitmap;
|
|
|
|
int ch_words;
|
2002-09-18 15:38:49 +00:00
|
|
|
|
2009-03-06 22:50:47 +00:00
|
|
|
/* reset file pointer */
|
2002-09-18 15:38:49 +00:00
|
|
|
fseek(fp, 0L, SEEK_SET);
|
|
|
|
|
2009-03-06 22:50:47 +00:00
|
|
|
/* initially mark offsets as not used */
|
2002-09-18 15:38:49 +00:00
|
|
|
for (i=0; i<pf->size; ++i)
|
|
|
|
pf->offset[i] = -1;
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
if (!bdf_getline(fp, buf, sizeof(buf))) {
|
2009-03-07 22:09:00 +00:00
|
|
|
print_error("EOF on file\n");
|
2002-09-18 15:38:49 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (isprefix(buf, "STARTCHAR")) {
|
2009-03-04 21:42:26 +00:00
|
|
|
encoding = width = -1;
|
|
|
|
bbw = pf->fbbw;
|
|
|
|
bbh = pf->fbbh;
|
|
|
|
bbx = pf->fbbx;
|
|
|
|
bby = pf->fbby;
|
2002-09-18 15:38:49 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (isprefix(buf, "ENCODING ")) {
|
|
|
|
if (sscanf(buf, "ENCODING %d", &encoding) != 1) {
|
2009-03-07 22:09:00 +00:00
|
|
|
print_error("bad 'ENCODING'\n");
|
2002-09-18 15:38:49 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (encoding < start_char || encoding > limit_char)
|
|
|
|
encoding = -1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (isprefix(buf, "DWIDTH ")) {
|
|
|
|
if (sscanf(buf, "DWIDTH %d", &width) != 1) {
|
2009-03-07 22:09:00 +00:00
|
|
|
print_error("bad 'DWIDTH'\n");
|
2002-09-18 15:38:49 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2009-03-06 22:50:47 +00:00
|
|
|
/* use font boundingbox width if DWIDTH <= 0 */
|
2002-09-18 15:38:49 +00:00
|
|
|
if (width <= 0)
|
|
|
|
width = pf->fbbw - pf->fbbx;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (isprefix(buf, "BBX ")) {
|
|
|
|
if (sscanf(buf, "BBX %d %d %d %d", &bbw, &bbh, &bbx, &bby) != 4) {
|
2009-03-07 22:09:00 +00:00
|
|
|
print_error("bad 'BBX'\n");
|
2002-09-18 15:38:49 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
2006-04-18 17:24:14 +00:00
|
|
|
if (strequal(buf, "BITMAP") || strequal(buf, "BITMAP ")) {
|
2009-03-04 21:42:26 +00:00
|
|
|
int overflow_asc, overflow_desc;
|
2009-03-05 21:27:55 +00:00
|
|
|
int bbh_orig, bby_orig, y;
|
2002-09-18 15:38:49 +00:00
|
|
|
|
|
|
|
if (encoding < 0)
|
|
|
|
continue;
|
|
|
|
|
2009-04-29 21:51:04 +00:00
|
|
|
if (width < 0 && pf->default_width > 0)
|
|
|
|
width = pf->default_width;
|
|
|
|
|
2010-05-17 20:55:55 +00:00
|
|
|
/* set bits offset in encode map */
|
2009-03-06 22:50:47 +00:00
|
|
|
if (pf->offset[encoding-pf->firstchar] != -1) {
|
2009-03-07 22:09:00 +00:00
|
|
|
print_error("duplicate encoding for character %d (0x%02x), ignoring duplicate\n",
|
2002-09-18 15:38:49 +00:00
|
|
|
encoding, encoding);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
pf->offset[encoding-pf->firstchar] = ofs;
|
2004-08-26 21:15:07 +00:00
|
|
|
pf->offrot[encoding-pf->firstchar] = ofr;
|
2002-09-18 15:38:49 +00:00
|
|
|
|
2009-03-06 22:50:47 +00:00
|
|
|
/* calc char width */
|
2009-03-08 16:23:14 +00:00
|
|
|
bdf_correct_bbx(&width, &bbx);
|
2002-09-18 15:38:49 +00:00
|
|
|
pf->width[encoding-pf->firstchar] = width;
|
|
|
|
|
2009-03-06 22:50:47 +00:00
|
|
|
ch_bitmap = pf->bits + ofs;
|
2002-09-20 08:07:51 +00:00
|
|
|
ch_words = BITMAP_WORDS(width);
|
2009-03-06 22:50:47 +00:00
|
|
|
memset(ch_bitmap, 0, BITMAP_BYTES(width) * pf->height); /* clear bitmap */
|
|
|
|
|
|
|
|
#define BM(row,col) (*(ch_bitmap + ((row)*ch_words) + (col)))
|
|
|
|
#define BITMAP_NIBBLES (BITMAP_BITSPERIMAGE/4)
|
2002-09-18 15:38:49 +00:00
|
|
|
|
2009-03-05 21:27:55 +00:00
|
|
|
bbh_orig = bbh;
|
|
|
|
bby_orig = bby;
|
|
|
|
|
2009-03-04 21:42:26 +00:00
|
|
|
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;
|
|
|
|
}
|
2009-03-05 21:27:55 +00:00
|
|
|
bbh = MAX(bbh - overflow_asc, 0); /* Clipped -> decrease the height */
|
2009-03-08 16:23:14 +00:00
|
|
|
print_warning(VL_CLIP_CHAR, "character %d goes %d pixel(s)"
|
2009-03-07 22:09:00 +00:00
|
|
|
" beyond the font's ascent, it will be clipped\n",
|
|
|
|
encoding, overflow_asc);
|
2009-03-04 21:42:26 +00:00
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
2009-03-05 21:27:55 +00:00
|
|
|
bby += overflow_desc;
|
|
|
|
bbh = MAX(bbh - overflow_desc, 0); /* Clipped -> decrease the height */
|
2009-03-08 16:23:14 +00:00
|
|
|
print_warning(VL_CLIP_CHAR, "character %d goes %d pixel(s)"
|
2009-03-07 22:09:00 +00:00
|
|
|
" beyond the font's descent, it will be clipped\n",
|
|
|
|
encoding, overflow_desc);
|
2009-03-04 21:42:26 +00:00
|
|
|
}
|
|
|
|
if (overflow_asc > 0 || overflow_desc > 0) {
|
|
|
|
pf->num_clipped++;
|
|
|
|
}
|
|
|
|
|
2009-03-05 21:27:55 +00:00
|
|
|
y = bby_orig + bbh_orig; /* 0-based y within the char */
|
2009-03-04 21:42:26 +00:00
|
|
|
|
2009-03-06 22:50:47 +00:00
|
|
|
/* read bitmaps */
|
2002-09-18 15:38:49 +00:00
|
|
|
for (i=0; ; ++i) {
|
|
|
|
int hexnibbles;
|
|
|
|
|
|
|
|
if (!bdf_getline(fp, buf, sizeof(buf))) {
|
2009-03-07 22:09:00 +00:00
|
|
|
print_error("EOF reading BITMAP data for character %d\n",
|
2009-03-06 22:50:47 +00:00
|
|
|
encoding);
|
2002-09-18 15:38:49 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (isprefix(buf, "ENDCHAR"))
|
|
|
|
break;
|
2009-03-04 21:42:26 +00:00
|
|
|
|
|
|
|
y--;
|
|
|
|
if ((y >= pf->ascent) || (y < -pf->descent)) {
|
|
|
|
/* We're beyond the area that Rockbox can render -> clip */
|
2009-03-05 21:27:55 +00:00
|
|
|
--i; /* This line doesn't count */
|
2009-03-04 21:42:26 +00:00
|
|
|
continue;
|
|
|
|
}
|
2002-09-18 15:38:49 +00:00
|
|
|
|
|
|
|
hexnibbles = strlen(buf);
|
|
|
|
for (k=0; k<ch_words; ++k) {
|
2002-09-20 08:07:51 +00:00
|
|
|
int ndx = k * BITMAP_NIBBLES;
|
2002-09-18 15:38:49 +00:00
|
|
|
int padnibbles = hexnibbles - ndx;
|
2002-09-20 08:07:51 +00:00
|
|
|
bitmap_t value;
|
2009-03-06 22:50:47 +00:00
|
|
|
|
2002-09-18 15:38:49 +00:00
|
|
|
if (padnibbles <= 0)
|
|
|
|
break;
|
2008-04-10 21:16:00 +00:00
|
|
|
if (padnibbles >= (int)BITMAP_NIBBLES)
|
2002-09-18 15:38:49 +00:00
|
|
|
padnibbles = 0;
|
|
|
|
|
|
|
|
value = bdf_hexval((unsigned char *)buf,
|
2002-09-20 08:07:51 +00:00
|
|
|
ndx, ndx+BITMAP_NIBBLES-1-padnibbles);
|
|
|
|
value <<= padnibbles * BITMAP_NIBBLES;
|
2002-09-18 15:38:49 +00:00
|
|
|
|
|
|
|
BM(pf->height - pf->descent - bby - bbh + i, k) |=
|
|
|
|
value >> bbx;
|
2009-03-06 22:50:47 +00:00
|
|
|
/* handle overflow into next image word */
|
2002-09-18 15:38:49 +00:00
|
|
|
if (bbx) {
|
|
|
|
BM(pf->height - pf->descent - bby - bbh + i, k+1) =
|
2002-09-20 08:07:51 +00:00
|
|
|
value << (BITMAP_BITSPERIMAGE - bbx);
|
2002-09-18 15:38:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-09-20 08:07:51 +00:00
|
|
|
ofs += BITMAP_WORDS(width) * pf->height;
|
2004-08-26 21:15:07 +00:00
|
|
|
ofr += pf->width[encoding-pf->firstchar] * ((pf->height+7)/8);
|
2002-09-18 15:38:49 +00:00
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (strequal(buf, "ENDFONT"))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-03-06 22:50:47 +00:00
|
|
|
/* change unused width values to default char values */
|
2002-09-18 15:38:49 +00:00
|
|
|
for (i=0; i<pf->size; ++i) {
|
|
|
|
int defchar = pf->defaultchar - pf->firstchar;
|
|
|
|
|
2009-03-06 22:50:47 +00:00
|
|
|
if (pf->offset[i] == -1)
|
2002-09-18 15:38:49 +00:00
|
|
|
pf->width[i] = pf->width[defchar];
|
|
|
|
}
|
|
|
|
|
2009-03-06 22:50:47 +00:00
|
|
|
/* determine whether font doesn't require encode table */
|
2004-08-27 00:34:15 +00:00
|
|
|
#ifdef ROTATE
|
2010-05-17 20:55:55 +00:00
|
|
|
offset = 0;
|
2004-08-27 00:34:15 +00:00
|
|
|
for (i=0; i<pf->size; ++i) {
|
2010-05-17 20:55:55 +00:00
|
|
|
if ((int)pf->offrot[i] != offset) {
|
2004-08-27 00:34:15 +00:00
|
|
|
encodetable = 1;
|
|
|
|
break;
|
|
|
|
}
|
2010-05-17 20:55:55 +00:00
|
|
|
offset += pf->maxwidth * ((pf->height + 7) / 8);
|
2004-08-27 00:34:15 +00:00
|
|
|
}
|
|
|
|
#else
|
2010-05-17 20:55:55 +00:00
|
|
|
offset = 0;
|
2002-09-18 15:38:49 +00:00
|
|
|
for (i=0; i<pf->size; ++i) {
|
2010-05-17 20:55:55 +00:00
|
|
|
if (pf->offset[i] != offset) {
|
2002-09-18 15:38:49 +00:00
|
|
|
encodetable = 1;
|
|
|
|
break;
|
|
|
|
}
|
2010-05-17 20:55:55 +00:00
|
|
|
offset += BITMAP_WORDS(pf->width[i]) * pf->height;
|
2002-09-18 15:38:49 +00:00
|
|
|
}
|
2004-08-27 00:34:15 +00:00
|
|
|
#endif
|
2002-09-18 15:38:49 +00:00
|
|
|
if (!encodetable) {
|
|
|
|
free(pf->offset);
|
|
|
|
pf->offset = NULL;
|
|
|
|
}
|
|
|
|
|
2009-03-06 22:50:47 +00:00
|
|
|
/* determine whether font is fixed-width */
|
2002-09-18 15:38:49 +00:00
|
|
|
for (i=0; i<pf->size; ++i) {
|
2009-03-06 22:50:47 +00:00
|
|
|
if (pf->width[i] != pf->maxwidth) {
|
2002-09-18 15:38:49 +00:00
|
|
|
proportional = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!proportional) {
|
|
|
|
free(pf->width);
|
|
|
|
pf->width = NULL;
|
|
|
|
}
|
|
|
|
|
2009-03-06 22:50:47 +00:00
|
|
|
/* reallocate bits array to actual bits used */
|
2002-09-18 15:38:49 +00:00
|
|
|
if (ofs < pf->bits_size) {
|
2002-09-20 08:07:51 +00:00
|
|
|
pf->bits = realloc(pf->bits, ofs * sizeof(bitmap_t));
|
2002-09-18 15:38:49 +00:00
|
|
|
pf->bits_size = ofs;
|
2002-09-20 08:07:51 +00:00
|
|
|
}
|
2002-09-18 15:38:49 +00:00
|
|
|
|
2004-08-26 21:15:07 +00:00
|
|
|
#ifdef ROTATE
|
|
|
|
pf->bits_size = ofr; /* always update, rotated is smaller */
|
|
|
|
#endif
|
|
|
|
|
2002-09-18 15:38:49 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2009-03-06 22:50:47 +00:00
|
|
|
/* read the next non-comment line, returns buf or NULL if EOF */
|
2002-09-20 08:07:51 +00:00
|
|
|
char *bdf_getline(FILE *fp, char *buf, int len)
|
2002-09-18 15:38:49 +00:00
|
|
|
{
|
|
|
|
int c;
|
|
|
|
char *b;
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
b = buf;
|
|
|
|
while ((c = getc(fp)) != EOF) {
|
|
|
|
if (c == '\r')
|
|
|
|
continue;
|
|
|
|
if (c == '\n')
|
|
|
|
break;
|
|
|
|
if (b - buf >= (len - 1))
|
|
|
|
break;
|
|
|
|
*b++ = c;
|
|
|
|
}
|
|
|
|
*b = '\0';
|
2002-09-20 10:20:13 +00:00
|
|
|
if (c == EOF && b == buf)
|
2002-09-18 15:38:49 +00:00
|
|
|
return NULL;
|
|
|
|
if (b != buf && !isprefix(buf, "COMMENT"))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return buf;
|
|
|
|
}
|
2009-03-08 16:23:14 +00:00
|
|
|
|
|
|
|
void bdf_correct_bbx(int *width, int *bbx) {
|
|
|
|
if (*bbx < 0) {
|
|
|
|
/* Rockbox can't render overlapping glyphs */
|
|
|
|
*width -= *bbx;
|
|
|
|
*bbx = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int bdf_analyze_font(FILE *fp, struct font* pf) {
|
|
|
|
char buf[256];
|
|
|
|
int encoding;
|
2009-03-12 19:55:07 +00:00
|
|
|
int width, bbw, bbh, bbx, bby, ascent, overflow;
|
2009-03-08 16:23:14 +00:00
|
|
|
int read_enc = 0, read_width = 0, read_bbx = 0, read_endchar = 1;
|
|
|
|
int ignore_char = 0;
|
|
|
|
|
|
|
|
/* reset file pointer */
|
|
|
|
fseek(fp, 0L, SEEK_SET);
|
|
|
|
|
|
|
|
pf->maxwidth = 0;
|
|
|
|
pf->nchars = 0;
|
2009-03-12 19:55:07 +00:00
|
|
|
pf->max_char_ascent = pf->max_char_descent = 0;
|
2009-03-08 16:23:14 +00:00
|
|
|
pf->max_over_ascent = pf->max_over_descent = 0;
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
|
|
|
|
if (!bdf_getline(fp, buf, sizeof(buf))) {
|
|
|
|
print_error("EOF on file\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (isprefix(buf, "ENDFONT")) {
|
|
|
|
if (!read_endchar) {
|
|
|
|
print_error("No terminating ENDCHAR for character %d\n", encoding);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (isprefix(buf, "STARTCHAR")) {
|
|
|
|
print_trace("Read STARTCHAR, nchars=%d, read_endchar=%d\n", pf->nchars, read_endchar);
|
|
|
|
if (!read_endchar) {
|
|
|
|
print_error("No terminating ENDCHAR for character %d\n", encoding);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
read_enc = read_width = read_bbx = read_endchar = 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (isprefix(buf, "ENDCHAR")) {
|
|
|
|
if (!read_enc) {
|
|
|
|
print_error("ENCODING is not specified\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
ignore_char = (encoding < start_char || encoding > limit_char);
|
|
|
|
if (!ignore_char) {
|
2009-04-29 21:51:04 +00:00
|
|
|
if (!read_width && pf->default_width > 0)
|
|
|
|
{
|
|
|
|
width = pf->default_width;
|
|
|
|
read_width = 1;
|
|
|
|
}
|
2009-03-08 16:23:14 +00:00
|
|
|
if (!read_width || !read_bbx) {
|
|
|
|
print_error("WIDTH or BBX is not specified for character %d\n",
|
|
|
|
encoding);
|
|
|
|
}
|
|
|
|
bdf_correct_bbx(&width, &bbx);
|
|
|
|
if (width > pf->maxwidth) {
|
|
|
|
pf->maxwidth = width;
|
|
|
|
}
|
2009-03-12 19:55:07 +00:00
|
|
|
|
|
|
|
ascent = bby + bbh;
|
|
|
|
pf->max_char_ascent = MAX(pf->max_char_ascent, ascent);
|
|
|
|
overflow = ascent - pf->ascent;
|
|
|
|
pf->max_over_ascent = MAX(pf->max_over_ascent, overflow);
|
|
|
|
|
|
|
|
ascent = -bby;
|
|
|
|
pf->max_char_descent = MAX(pf->max_char_descent, ascent);
|
|
|
|
overflow = ascent - pf->descent;
|
|
|
|
pf->max_over_descent = MAX(pf->max_over_descent, overflow);
|
2009-03-08 16:23:14 +00:00
|
|
|
}
|
|
|
|
pf->nchars++;
|
|
|
|
read_endchar = 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (isprefix(buf, "ENCODING ")) {
|
|
|
|
if (sscanf(buf, "ENCODING %d", &encoding) != 1) {
|
|
|
|
print_error("bad 'ENCODING': '%s'\n", buf);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
read_enc = 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (isprefix(buf, "DWIDTH ")) {
|
|
|
|
if (sscanf(buf, "DWIDTH %d", &width) != 1) {
|
|
|
|
print_error("bad 'DWIDTH': '%s'\n", buf);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* use font boundingbox width if DWIDTH <= 0 */
|
|
|
|
if (width < 0) {
|
|
|
|
print_error("Negative char width: %d\n", width);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
read_width = 1;
|
|
|
|
}
|
|
|
|
if (isprefix(buf, "BBX ")) {
|
|
|
|
if (sscanf(buf, "BBX %d %d %d %d", &bbw, &bbh, &bbx, &bby) != 4) {
|
|
|
|
print_error("bad 'BBX': '%s'\n", buf);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
read_bbx = 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int adjust_ascent(int ascent, int overflow, struct stretch *stretch) {
|
|
|
|
int result;
|
|
|
|
int px = stretch->value;
|
|
|
|
if (stretch->percent) {
|
|
|
|
px = ascent * px / 100;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stretch->force) {
|
|
|
|
result = ascent + px;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
result = ascent + MIN(overflow, px);
|
|
|
|
}
|
|
|
|
result = MAX(result, 0);
|
|
|
|
return result;
|
2009-03-06 22:50:47 +00:00
|
|
|
}
|
|
|
|
|
2002-09-18 15:38:49 +00:00
|
|
|
|
2010-05-17 20:55:55 +00:00
|
|
|
/* return hex value of portion of buffer */
|
2002-09-20 08:07:51 +00:00
|
|
|
bitmap_t bdf_hexval(unsigned char *buf, int ndx1, int ndx2)
|
2002-09-18 15:38:49 +00:00
|
|
|
{
|
2002-09-20 08:07:51 +00:00
|
|
|
bitmap_t val = 0;
|
2002-09-18 15:38:49 +00:00
|
|
|
int i, c;
|
|
|
|
|
|
|
|
for (i=ndx1; i<=ndx2; ++i) {
|
|
|
|
c = buf[i];
|
|
|
|
if (c >= '0' && c <= '9')
|
|
|
|
c -= '0';
|
2002-09-20 08:07:51 +00:00
|
|
|
else
|
|
|
|
if (c >= 'A' && c <= 'F')
|
|
|
|
c = c - 'A' + 10;
|
|
|
|
else
|
|
|
|
if (c >= 'a' && c <= 'f')
|
|
|
|
c = c - 'a' + 10;
|
|
|
|
else
|
|
|
|
c = 0;
|
2002-09-18 15:38:49 +00:00
|
|
|
val = (val << 4) | c;
|
|
|
|
}
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2009-03-13 18:56:55 +00:00
|
|
|
|
|
|
|
#ifdef ROTATE
|
|
|
|
|
2004-08-26 21:15:07 +00:00
|
|
|
/*
|
|
|
|
* Take an bitmap_t bitmap and convert to Rockbox format.
|
|
|
|
* Used for converting font glyphs for the time being.
|
|
|
|
* Can use for standard X11 and Win32 images as well.
|
|
|
|
* See format description in lcd-recorder.c
|
|
|
|
*
|
|
|
|
* Doing it this way keeps fonts in standard formats,
|
|
|
|
* as well as keeping Rockbox hw bitmap format.
|
2009-03-13 18:56:55 +00:00
|
|
|
*
|
|
|
|
* Returns the size of the rotated glyph (in bytes) or a
|
|
|
|
* negative value if the glyph could not be rotated.
|
2004-08-26 21:15:07 +00:00
|
|
|
*/
|
2007-07-31 09:42:50 +00:00
|
|
|
int rotleft(unsigned char *dst, /* output buffer */
|
|
|
|
size_t dstlen, /* buffer size */
|
2009-03-13 18:56:55 +00:00
|
|
|
bitmap_t *src, unsigned int width, unsigned int height,
|
|
|
|
int char_code)
|
2004-08-26 21:15:07 +00:00
|
|
|
{
|
|
|
|
unsigned int i,j;
|
2009-03-06 22:50:47 +00:00
|
|
|
unsigned int src_words; /* # words of input image */
|
2004-08-26 21:15:07 +00:00
|
|
|
unsigned int dst_mask; /* bit mask for destination */
|
|
|
|
bitmap_t src_mask; /* bit mask for source */
|
2009-03-13 18:56:55 +00:00
|
|
|
|
|
|
|
/* How large the buffer should be to hold the rotated bitmap
|
|
|
|
of a glyph of size (width x height) */
|
|
|
|
unsigned int needed_size = ((height + 7) / 8) * width;
|
|
|
|
|
|
|
|
if (needed_size > dstlen) {
|
|
|
|
print_error("Character %d: Glyph of size %d x %d can't be rotated "
|
|
|
|
"(buffer size is %lu, needs %u)\n",
|
|
|
|
char_code, width, height, (unsigned long)dstlen, needed_size);
|
|
|
|
return -1;
|
|
|
|
}
|
2004-08-26 21:15:07 +00:00
|
|
|
|
2010-05-17 20:55:55 +00:00
|
|
|
/* calc words of input image */
|
2004-08-26 21:15:07 +00:00
|
|
|
src_words = BITMAP_WORDS(width) * height;
|
2007-07-31 09:42:50 +00:00
|
|
|
|
2010-05-17 20:55:55 +00:00
|
|
|
/* clear background */
|
2009-03-13 18:56:55 +00:00
|
|
|
memset(dst, 0, needed_size);
|
2004-08-26 21:15:07 +00:00
|
|
|
|
|
|
|
dst_mask = 1;
|
|
|
|
|
|
|
|
for (i=0; i < src_words; i++) {
|
|
|
|
|
2010-05-17 20:55:55 +00:00
|
|
|
/* calc src input bit */
|
2004-08-26 21:15:07 +00:00
|
|
|
src_mask = 1 << (sizeof (bitmap_t) * 8 - 1);
|
|
|
|
|
2010-05-17 20:55:55 +00:00
|
|
|
/* for each input column... */
|
2004-08-26 21:15:07 +00:00
|
|
|
for(j=0; j < width; j++) {
|
|
|
|
|
2005-11-14 19:52:04 +00:00
|
|
|
if (src_mask == 0) /* input word done? */
|
|
|
|
{
|
|
|
|
src_mask = 1 << (sizeof (bitmap_t) * 8 - 1);
|
|
|
|
i++; /* next input word */
|
|
|
|
}
|
|
|
|
|
2004-08-26 21:15:07 +00:00
|
|
|
/* if set in input, set in rotated output */
|
|
|
|
if (src[i] & src_mask)
|
|
|
|
dst[j] |= dst_mask;
|
|
|
|
|
|
|
|
src_mask >>= 1; /* next input bit */
|
|
|
|
}
|
|
|
|
|
|
|
|
dst_mask <<= 1; /* next output bit (row) */
|
|
|
|
if (dst_mask > (1 << 7)) /* output bit > 7? */
|
|
|
|
{
|
|
|
|
dst_mask = 1;
|
|
|
|
dst += width; /* next output byte row */
|
|
|
|
}
|
|
|
|
}
|
2009-03-13 18:56:55 +00:00
|
|
|
return needed_size; /* return result size in bytes */
|
2004-08-26 21:15:07 +00:00
|
|
|
}
|
|
|
|
|
2009-03-13 18:56:55 +00:00
|
|
|
#endif /* ROTATE */
|
|
|
|
|
2004-08-26 21:15:07 +00:00
|
|
|
|
2010-05-17 20:55:55 +00:00
|
|
|
/* generate C source from in-core font */
|
2002-09-20 08:07:51 +00:00
|
|
|
int gen_c_source(struct font* pf, char *path)
|
2002-09-18 15:38:49 +00:00
|
|
|
{
|
|
|
|
FILE *ofp;
|
2009-03-13 18:56:55 +00:00
|
|
|
int i;
|
2002-09-18 15:38:49 +00:00
|
|
|
time_t t = time(0);
|
2009-03-13 18:56:55 +00:00
|
|
|
#ifdef ROTATE
|
|
|
|
int ofr = 0;
|
|
|
|
#else
|
2008-04-10 21:16:00 +00:00
|
|
|
int did_syncmsg = 0;
|
2002-09-20 08:07:51 +00:00
|
|
|
bitmap_t *ofs = pf->bits;
|
2008-04-10 21:16:00 +00:00
|
|
|
#endif
|
2002-09-18 15:38:49 +00:00
|
|
|
char buf[256];
|
|
|
|
char obuf[256];
|
|
|
|
char hdr1[] = {
|
|
|
|
"/* Generated by convbdf on %s. */\n"
|
|
|
|
"#include \"font.h\"\n"
|
2004-09-22 08:58:50 +00:00
|
|
|
"#ifdef HAVE_LCD_BITMAP\n"
|
2002-09-18 15:38:49 +00:00
|
|
|
"\n"
|
|
|
|
"/* Font information:\n"
|
|
|
|
" name: %s\n"
|
|
|
|
" facename: %s\n"
|
|
|
|
" w x h: %dx%d\n"
|
|
|
|
" size: %d\n"
|
|
|
|
" ascent: %d\n"
|
|
|
|
" descent: %d\n"
|
2011-03-05 18:36:51 +00:00
|
|
|
" depth: %d\n"
|
2002-09-18 15:38:49 +00:00
|
|
|
" first char: %d (0x%02x)\n"
|
|
|
|
" last char: %d (0x%02x)\n"
|
|
|
|
" default char: %d (0x%02x)\n"
|
|
|
|
" proportional: %s\n"
|
|
|
|
" %s\n"
|
|
|
|
"*/\n"
|
|
|
|
"\n"
|
|
|
|
"/* Font character bitmap data. */\n"
|
2004-08-26 21:15:07 +00:00
|
|
|
"static const unsigned char _font_bits[] = {\n"
|
2002-09-18 15:38:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
ofp = fopen(path, "w");
|
|
|
|
if (!ofp) {
|
2009-03-07 22:09:00 +00:00
|
|
|
print_error("Can't create %s\n", path);
|
2002-09-18 15:38:49 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
strcpy(buf, ctime(&t));
|
|
|
|
buf[strlen(buf)-1] = 0;
|
|
|
|
|
|
|
|
fprintf(ofp, hdr1, buf,
|
|
|
|
pf->name,
|
|
|
|
pf->facename? pf->facename: "",
|
|
|
|
pf->maxwidth, pf->height,
|
|
|
|
pf->size,
|
2011-03-05 18:36:51 +00:00
|
|
|
pf->ascent, pf->descent, pf->depth,
|
2002-09-18 15:38:49 +00:00
|
|
|
pf->firstchar, pf->firstchar,
|
|
|
|
pf->firstchar+pf->size-1, pf->firstchar+pf->size-1,
|
|
|
|
pf->defaultchar, pf->defaultchar,
|
|
|
|
pf->width? "yes": "no",
|
2002-09-20 08:07:51 +00:00
|
|
|
pf->copyright? pf->copyright: "");
|
2002-09-18 15:38:49 +00:00
|
|
|
|
2010-05-17 20:55:55 +00:00
|
|
|
/* generate bitmaps */
|
2002-09-18 15:38:49 +00:00
|
|
|
for (i=0; i<pf->size; ++i) {
|
|
|
|
int x;
|
|
|
|
int bitcount = 0;
|
|
|
|
int width = pf->width ? pf->width[i] : pf->maxwidth;
|
|
|
|
int height = pf->height;
|
2009-03-13 18:56:55 +00:00
|
|
|
int char_code = pf->firstchar + i;
|
2006-04-18 17:24:14 +00:00
|
|
|
bitmap_t *bits;
|
2008-04-10 21:16:00 +00:00
|
|
|
bitmap_t bitvalue=0;
|
2002-09-18 15:38:49 +00:00
|
|
|
|
2006-04-18 17:24:14 +00:00
|
|
|
/* Skip missing glyphs */
|
2009-03-06 22:50:47 +00:00
|
|
|
if (pf->offset && (pf->offset[i] == -1))
|
2006-04-18 17:24:14 +00:00
|
|
|
continue;
|
|
|
|
|
2008-04-10 21:16:00 +00:00
|
|
|
bits = pf->bits + (pf->offset? (int)pf->offset[i]: (pf->height * i));
|
2002-09-18 15:38:49 +00:00
|
|
|
|
|
|
|
fprintf(ofp, "\n/* Character %d (0x%02x):\n width %d",
|
2009-03-13 18:56:55 +00:00
|
|
|
char_code, char_code, width);
|
2002-09-18 15:38:49 +00:00
|
|
|
|
|
|
|
if (gen_map) {
|
|
|
|
fprintf(ofp, "\n +");
|
|
|
|
for (x=0; x<width; ++x) fprintf(ofp, "-");
|
|
|
|
fprintf(ofp, "+\n");
|
|
|
|
|
|
|
|
x = 0;
|
|
|
|
while (height > 0) {
|
|
|
|
if (x == 0) fprintf(ofp, " |");
|
|
|
|
|
|
|
|
if (bitcount <= 0) {
|
2002-09-20 08:07:51 +00:00
|
|
|
bitcount = BITMAP_BITSPERIMAGE;
|
2002-09-18 15:38:49 +00:00
|
|
|
bitvalue = *bits++;
|
|
|
|
}
|
|
|
|
|
2002-09-20 08:07:51 +00:00
|
|
|
fprintf(ofp, BITMAP_TESTBIT(bitvalue)? "*": " ");
|
2002-09-18 15:38:49 +00:00
|
|
|
|
2002-09-20 08:07:51 +00:00
|
|
|
bitvalue = BITMAP_SHIFTBIT(bitvalue);
|
2002-09-18 15:38:49 +00:00
|
|
|
--bitcount;
|
|
|
|
if (++x == width) {
|
|
|
|
fprintf(ofp, "|\n");
|
|
|
|
--height;
|
|
|
|
x = 0;
|
|
|
|
bitcount = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fprintf(ofp, " +");
|
2002-09-20 08:07:51 +00:00
|
|
|
for (x=0; x<width; ++x)
|
|
|
|
fprintf(ofp, "-");
|
2002-09-18 15:38:49 +00:00
|
|
|
fprintf(ofp, "+ */\n");
|
2002-09-20 08:07:51 +00:00
|
|
|
}
|
|
|
|
else
|
2002-09-18 15:38:49 +00:00
|
|
|
fprintf(ofp, " */\n");
|
|
|
|
|
2008-04-10 21:16:00 +00:00
|
|
|
bits = pf->bits + (pf->offset? (int)pf->offset[i]: (pf->height * i));
|
2004-08-26 21:15:07 +00:00
|
|
|
#ifdef ROTATE /* pre-rotated into Rockbox bitmap format */
|
|
|
|
{
|
2009-03-13 18:56:55 +00:00
|
|
|
unsigned char bytemap[ROTATION_BUF_SIZE];
|
2004-08-26 21:15:07 +00:00
|
|
|
int y8, ix=0;
|
|
|
|
|
2007-07-31 09:42:50 +00:00
|
|
|
int size = rotleft(bytemap, sizeof(bytemap), bits, width,
|
2009-03-13 18:56:55 +00:00
|
|
|
pf->height, char_code);
|
|
|
|
if (size < 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2004-08-26 21:15:07 +00:00
|
|
|
for (y8=0; y8<pf->height; y8+=8) /* column rows */
|
|
|
|
{
|
|
|
|
for (x=0; x<width; x++) {
|
|
|
|
fprintf(ofp, "0x%02x, ", bytemap[ix]);
|
|
|
|
ix++;
|
2006-04-18 17:24:14 +00:00
|
|
|
}
|
2004-08-26 21:15:07 +00:00
|
|
|
fprintf(ofp, "\n");
|
|
|
|
}
|
2005-08-23 21:38:26 +00:00
|
|
|
|
2010-05-17 20:37:45 +00:00
|
|
|
/* update offrot since bits are now in sorted order */
|
|
|
|
pf->offrot[i] = ofr;
|
|
|
|
ofr += size;
|
2004-08-26 21:15:07 +00:00
|
|
|
}
|
|
|
|
#else
|
2002-09-20 08:07:51 +00:00
|
|
|
for (x=BITMAP_WORDS(width)*pf->height; x>0; --x) {
|
2002-09-18 15:38:49 +00:00
|
|
|
fprintf(ofp, "0x%04x,\n", *bits);
|
|
|
|
if (!did_syncmsg && *bits++ != *ofs++) {
|
2009-03-07 22:09:00 +00:00
|
|
|
print_warning(VL_MISC, "found encoding values in non-sorted order (not an error).\n");
|
2002-09-18 15:38:49 +00:00
|
|
|
did_syncmsg = 1;
|
|
|
|
}
|
2006-04-18 17:24:14 +00:00
|
|
|
}
|
2004-08-26 21:15:07 +00:00
|
|
|
#endif
|
2002-09-18 15:38:49 +00:00
|
|
|
}
|
2002-09-20 08:07:51 +00:00
|
|
|
fprintf(ofp, "};\n\n");
|
2002-09-18 15:38:49 +00:00
|
|
|
|
|
|
|
if (pf->offset) {
|
2010-05-17 20:55:55 +00:00
|
|
|
/* output offset table */
|
2002-09-18 15:38:49 +00:00
|
|
|
fprintf(ofp, "/* Character->glyph mapping. */\n"
|
2004-08-26 21:15:07 +00:00
|
|
|
"static const unsigned short _sysfont_offset[] = {\n");
|
2002-09-18 15:38:49 +00:00
|
|
|
|
2006-04-18 17:24:14 +00:00
|
|
|
for (i=0; i<pf->size; ++i) {
|
2010-05-17 20:37:45 +00:00
|
|
|
int offset = pf->offset[i];
|
|
|
|
int offrot = pf->offrot[i];
|
|
|
|
if (offset == -1) {
|
|
|
|
offset = pf->offset[pf->defaultchar - pf->firstchar];
|
|
|
|
offrot = pf->offrot[pf->defaultchar - pf->firstchar];
|
2006-04-18 17:24:14 +00:00
|
|
|
}
|
2008-04-10 21:16:00 +00:00
|
|
|
fprintf(ofp, " %d,\t/* (0x%02x) */\n",
|
2004-08-26 21:15:07 +00:00
|
|
|
#ifdef ROTATE
|
2010-05-17 20:37:45 +00:00
|
|
|
offrot, i+pf->firstchar);
|
2004-08-26 21:15:07 +00:00
|
|
|
#else
|
2010-05-17 20:37:45 +00:00
|
|
|
offset, i+pf->firstchar);
|
2004-08-26 21:15:07 +00:00
|
|
|
#endif
|
2006-04-18 17:24:14 +00:00
|
|
|
}
|
2002-09-18 15:38:49 +00:00
|
|
|
fprintf(ofp, "};\n\n");
|
|
|
|
}
|
|
|
|
|
2010-05-17 20:55:55 +00:00
|
|
|
/* output width table for proportional fonts */
|
2002-09-18 15:38:49 +00:00
|
|
|
if (pf->width) {
|
2002-09-20 08:07:51 +00:00
|
|
|
fprintf(ofp, "/* Character width data. */\n"
|
2004-08-26 21:15:07 +00:00
|
|
|
"static const unsigned char _sysfont_width[] = {\n");
|
2002-09-18 15:38:49 +00:00
|
|
|
|
|
|
|
for (i=0; i<pf->size; ++i)
|
2002-09-20 08:07:51 +00:00
|
|
|
fprintf(ofp, " %d,\t/* (0x%02x) */\n",
|
|
|
|
pf->width[i], i+pf->firstchar);
|
2002-09-18 15:38:49 +00:00
|
|
|
fprintf(ofp, "};\n\n");
|
|
|
|
}
|
|
|
|
|
2010-05-17 20:55:55 +00:00
|
|
|
/* output struct font struct */
|
2002-09-18 15:38:49 +00:00
|
|
|
if (pf->offset)
|
2002-09-20 08:07:51 +00:00
|
|
|
sprintf(obuf, "_sysfont_offset,");
|
|
|
|
else
|
2004-08-26 21:15:07 +00:00
|
|
|
sprintf(obuf, "0, /* no encode table */");
|
2002-09-20 08:07:51 +00:00
|
|
|
|
2002-09-18 15:38:49 +00:00
|
|
|
if (pf->width)
|
2004-08-26 21:15:07 +00:00
|
|
|
sprintf(buf, "_sysfont_width, /* width */");
|
2002-09-20 08:07:51 +00:00
|
|
|
else
|
2004-08-26 21:15:07 +00:00
|
|
|
sprintf(buf, "0, /* fixed width */");
|
2002-09-20 08:07:51 +00:00
|
|
|
|
2011-03-05 18:56:47 +00:00
|
|
|
fprintf(ofp, "/* Exported structure definition. */\n"
|
2004-08-26 21:15:07 +00:00
|
|
|
"const struct font sysfont = {\n"
|
|
|
|
" %d, /* maxwidth */\n"
|
|
|
|
" %d, /* height */\n"
|
|
|
|
" %d, /* ascent */\n"
|
|
|
|
" %d, /* firstchar */\n"
|
|
|
|
" %d, /* size */\n"
|
2011-03-05 18:36:51 +00:00
|
|
|
" %d, /* depth */\n"
|
2004-08-26 21:15:07 +00:00
|
|
|
" _font_bits, /* bits */\n"
|
|
|
|
" %s /* offset */\n"
|
2004-04-13 11:17:42 +00:00
|
|
|
" %s\n"
|
2004-08-26 21:15:07 +00:00
|
|
|
" %d, /* defaultchar */\n"
|
2011-10-17 13:29:16 +00:00
|
|
|
" %d, /* bits_size */\n",
|
|
|
|
pf->maxwidth, pf->height,
|
|
|
|
pf->ascent,
|
|
|
|
pf->firstchar,
|
|
|
|
pf->size, 0,
|
|
|
|
obuf,
|
|
|
|
buf,
|
|
|
|
pf->defaultchar,
|
|
|
|
pf->bits_size
|
|
|
|
);
|
|
|
|
|
|
|
|
fprintf(ofp, " -1, /* font fd */\n"
|
2011-10-17 13:17:04 +00:00
|
|
|
" -1, /* font fd width */\n"
|
|
|
|
" -1, /* font fd offset */\n"
|
2011-11-19 23:34:26 +00:00
|
|
|
" -1, /* font handle */\n"
|
2011-03-05 18:56:47 +00:00
|
|
|
" 0, /* buffer start */\n"
|
|
|
|
" 0, /* ^ position */\n"
|
|
|
|
" 0, /* ^ end */\n"
|
|
|
|
" 0, /* ^ size */\n"
|
2011-10-16 20:29:57 +00:00
|
|
|
" {{0,0,0,0,0},0,0,0,0,0}, /* cache */\n"
|
2011-03-05 18:56:47 +00:00
|
|
|
" 0, /* */\n"
|
|
|
|
" 0, /* */\n"
|
|
|
|
" 0, /* */\n"
|
2004-09-22 08:58:50 +00:00
|
|
|
"};\n"
|
2011-10-17 13:29:16 +00:00
|
|
|
"#endif /* HAVE_LCD_BITMAP */\n"
|
|
|
|
);
|
2002-09-18 15:38:49 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-05-17 20:55:55 +00:00
|
|
|
/* generate C header from in-core font */
|
Make the build system create a sysfont.h which includes font information for the system font. Available #defines are: SYSFONT_NAME, SYSFONT_FACENAME, SYSFONT_WIDTH, SYSFONT_HEIGHT, SYSFONT_SIZE, SYSFONT_ASCENT, SYSFONT_DESCENT, SYSFONT_FIRST_CHAR, SYSFONT_LAST_CHAR, SYSFONT_DEFAULT_CHAR, SYSFONT_PROPORTIONAL, SYSFONT_COPYRIGHT, SYSFONT_BITS_SIZE.
Also fix a small bug in the iPod bootloader printf() code and use printf() for PortalPlayer bootloaders too.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@12041 a1c6a512-1295-4272-9138-f99709370657
2007-01-17 12:20:38 +00:00
|
|
|
int gen_h_header(struct font* pf, char *path)
|
|
|
|
{
|
|
|
|
FILE *ofp;
|
|
|
|
time_t t = time(0);
|
|
|
|
char buf[256];
|
2008-04-10 21:16:00 +00:00
|
|
|
char *hdr1 =
|
Make the build system create a sysfont.h which includes font information for the system font. Available #defines are: SYSFONT_NAME, SYSFONT_FACENAME, SYSFONT_WIDTH, SYSFONT_HEIGHT, SYSFONT_SIZE, SYSFONT_ASCENT, SYSFONT_DESCENT, SYSFONT_FIRST_CHAR, SYSFONT_LAST_CHAR, SYSFONT_DEFAULT_CHAR, SYSFONT_PROPORTIONAL, SYSFONT_COPYRIGHT, SYSFONT_BITS_SIZE.
Also fix a small bug in the iPod bootloader printf() code and use printf() for PortalPlayer bootloaders too.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@12041 a1c6a512-1295-4272-9138-f99709370657
2007-01-17 12:20:38 +00:00
|
|
|
"/* Generated by convbdf on %s. */\n"
|
|
|
|
"#ifdef HAVE_LCD_BITMAP\n"
|
|
|
|
"\n"
|
2010-05-17 20:55:55 +00:00
|
|
|
"/* Font information */\n"
|
Make the build system create a sysfont.h which includes font information for the system font. Available #defines are: SYSFONT_NAME, SYSFONT_FACENAME, SYSFONT_WIDTH, SYSFONT_HEIGHT, SYSFONT_SIZE, SYSFONT_ASCENT, SYSFONT_DESCENT, SYSFONT_FIRST_CHAR, SYSFONT_LAST_CHAR, SYSFONT_DEFAULT_CHAR, SYSFONT_PROPORTIONAL, SYSFONT_COPYRIGHT, SYSFONT_BITS_SIZE.
Also fix a small bug in the iPod bootloader printf() code and use printf() for PortalPlayer bootloaders too.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@12041 a1c6a512-1295-4272-9138-f99709370657
2007-01-17 12:20:38 +00:00
|
|
|
"#define SYSFONT_NAME %s\n"
|
|
|
|
"#define SYSFONT_FACENAME %s\n"
|
|
|
|
"#define SYSFONT_WIDTH %d\n"
|
|
|
|
"#define SYSFONT_HEIGHT %d\n"
|
|
|
|
"#define SYSFONT_SIZE %d\n"
|
2011-03-05 18:36:51 +00:00
|
|
|
"#define SYSFONT_ASCENT %d\n"
|
|
|
|
"#define SYSFONT_DEPTH %d\n";
|
2008-04-10 21:16:00 +00:00
|
|
|
char *hdr2 =
|
Make the build system create a sysfont.h which includes font information for the system font. Available #defines are: SYSFONT_NAME, SYSFONT_FACENAME, SYSFONT_WIDTH, SYSFONT_HEIGHT, SYSFONT_SIZE, SYSFONT_ASCENT, SYSFONT_DESCENT, SYSFONT_FIRST_CHAR, SYSFONT_LAST_CHAR, SYSFONT_DEFAULT_CHAR, SYSFONT_PROPORTIONAL, SYSFONT_COPYRIGHT, SYSFONT_BITS_SIZE.
Also fix a small bug in the iPod bootloader printf() code and use printf() for PortalPlayer bootloaders too.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@12041 a1c6a512-1295-4272-9138-f99709370657
2007-01-17 12:20:38 +00:00
|
|
|
"#define SYSFONT_DESCENT %d\n"
|
|
|
|
"#define SYSFONT_FIRST_CHAR %d\n"
|
|
|
|
"#define SYSFONT_LAST_CHAR %d\n"
|
|
|
|
"#define SYSFONT_DEFAULT_CHAR %d\n"
|
2007-01-17 12:53:23 +00:00
|
|
|
"#define SYSFONT_PROPORTIONAL %d\n"
|
Make the build system create a sysfont.h which includes font information for the system font. Available #defines are: SYSFONT_NAME, SYSFONT_FACENAME, SYSFONT_WIDTH, SYSFONT_HEIGHT, SYSFONT_SIZE, SYSFONT_ASCENT, SYSFONT_DESCENT, SYSFONT_FIRST_CHAR, SYSFONT_LAST_CHAR, SYSFONT_DEFAULT_CHAR, SYSFONT_PROPORTIONAL, SYSFONT_COPYRIGHT, SYSFONT_BITS_SIZE.
Also fix a small bug in the iPod bootloader printf() code and use printf() for PortalPlayer bootloaders too.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@12041 a1c6a512-1295-4272-9138-f99709370657
2007-01-17 12:20:38 +00:00
|
|
|
"#define SYSFONT_COPYRIGHT %s\n"
|
|
|
|
"#define SYSFONT_BITS_SIZE %d\n"
|
|
|
|
"\n"
|
2008-04-10 21:16:00 +00:00
|
|
|
"#endif\n";
|
Make the build system create a sysfont.h which includes font information for the system font. Available #defines are: SYSFONT_NAME, SYSFONT_FACENAME, SYSFONT_WIDTH, SYSFONT_HEIGHT, SYSFONT_SIZE, SYSFONT_ASCENT, SYSFONT_DESCENT, SYSFONT_FIRST_CHAR, SYSFONT_LAST_CHAR, SYSFONT_DEFAULT_CHAR, SYSFONT_PROPORTIONAL, SYSFONT_COPYRIGHT, SYSFONT_BITS_SIZE.
Also fix a small bug in the iPod bootloader printf() code and use printf() for PortalPlayer bootloaders too.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@12041 a1c6a512-1295-4272-9138-f99709370657
2007-01-17 12:20:38 +00:00
|
|
|
|
|
|
|
ofp = fopen(path, "w");
|
|
|
|
if (!ofp) {
|
2009-03-07 22:09:00 +00:00
|
|
|
print_error("Can't create %s\n", path);
|
Make the build system create a sysfont.h which includes font information for the system font. Available #defines are: SYSFONT_NAME, SYSFONT_FACENAME, SYSFONT_WIDTH, SYSFONT_HEIGHT, SYSFONT_SIZE, SYSFONT_ASCENT, SYSFONT_DESCENT, SYSFONT_FIRST_CHAR, SYSFONT_LAST_CHAR, SYSFONT_DEFAULT_CHAR, SYSFONT_PROPORTIONAL, SYSFONT_COPYRIGHT, SYSFONT_BITS_SIZE.
Also fix a small bug in the iPod bootloader printf() code and use printf() for PortalPlayer bootloaders too.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@12041 a1c6a512-1295-4272-9138-f99709370657
2007-01-17 12:20:38 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
strcpy(buf, ctime(&t));
|
|
|
|
buf[strlen(buf)-1] = 0;
|
|
|
|
|
2008-04-10 21:25:54 +00:00
|
|
|
fprintf(ofp, hdr1, buf,
|
Make the build system create a sysfont.h which includes font information for the system font. Available #defines are: SYSFONT_NAME, SYSFONT_FACENAME, SYSFONT_WIDTH, SYSFONT_HEIGHT, SYSFONT_SIZE, SYSFONT_ASCENT, SYSFONT_DESCENT, SYSFONT_FIRST_CHAR, SYSFONT_LAST_CHAR, SYSFONT_DEFAULT_CHAR, SYSFONT_PROPORTIONAL, SYSFONT_COPYRIGHT, SYSFONT_BITS_SIZE.
Also fix a small bug in the iPod bootloader printf() code and use printf() for PortalPlayer bootloaders too.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@12041 a1c6a512-1295-4272-9138-f99709370657
2007-01-17 12:20:38 +00:00
|
|
|
pf->name,
|
|
|
|
pf->facename? pf->facename: "",
|
2007-01-17 12:53:23 +00:00
|
|
|
pf->maxwidth,
|
|
|
|
pf->height,
|
Make the build system create a sysfont.h which includes font information for the system font. Available #defines are: SYSFONT_NAME, SYSFONT_FACENAME, SYSFONT_WIDTH, SYSFONT_HEIGHT, SYSFONT_SIZE, SYSFONT_ASCENT, SYSFONT_DESCENT, SYSFONT_FIRST_CHAR, SYSFONT_LAST_CHAR, SYSFONT_DEFAULT_CHAR, SYSFONT_PROPORTIONAL, SYSFONT_COPYRIGHT, SYSFONT_BITS_SIZE.
Also fix a small bug in the iPod bootloader printf() code and use printf() for PortalPlayer bootloaders too.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@12041 a1c6a512-1295-4272-9138-f99709370657
2007-01-17 12:20:38 +00:00
|
|
|
pf->size,
|
2011-03-05 18:36:51 +00:00
|
|
|
pf->ascent,
|
|
|
|
pf->depth);
|
2008-04-10 21:16:00 +00:00
|
|
|
|
2008-04-10 21:25:54 +00:00
|
|
|
fprintf(ofp, hdr2,
|
2007-01-17 12:53:23 +00:00
|
|
|
pf->descent,
|
Make the build system create a sysfont.h which includes font information for the system font. Available #defines are: SYSFONT_NAME, SYSFONT_FACENAME, SYSFONT_WIDTH, SYSFONT_HEIGHT, SYSFONT_SIZE, SYSFONT_ASCENT, SYSFONT_DESCENT, SYSFONT_FIRST_CHAR, SYSFONT_LAST_CHAR, SYSFONT_DEFAULT_CHAR, SYSFONT_PROPORTIONAL, SYSFONT_COPYRIGHT, SYSFONT_BITS_SIZE.
Also fix a small bug in the iPod bootloader printf() code and use printf() for PortalPlayer bootloaders too.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@12041 a1c6a512-1295-4272-9138-f99709370657
2007-01-17 12:20:38 +00:00
|
|
|
pf->firstchar,
|
|
|
|
pf->firstchar+pf->size-1,
|
|
|
|
pf->defaultchar,
|
|
|
|
pf->width? 1: 0,
|
2007-01-17 12:53:23 +00:00
|
|
|
pf->copyright? pf->copyright: "",
|
|
|
|
pf->bits_size);
|
Make the build system create a sysfont.h which includes font information for the system font. Available #defines are: SYSFONT_NAME, SYSFONT_FACENAME, SYSFONT_WIDTH, SYSFONT_HEIGHT, SYSFONT_SIZE, SYSFONT_ASCENT, SYSFONT_DESCENT, SYSFONT_FIRST_CHAR, SYSFONT_LAST_CHAR, SYSFONT_DEFAULT_CHAR, SYSFONT_PROPORTIONAL, SYSFONT_COPYRIGHT, SYSFONT_BITS_SIZE.
Also fix a small bug in the iPod bootloader printf() code and use printf() for PortalPlayer bootloaders too.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@12041 a1c6a512-1295-4272-9138-f99709370657
2007-01-17 12:20:38 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-09-20 08:07:51 +00:00
|
|
|
static int writebyte(FILE *fp, unsigned char c)
|
2002-09-18 15:38:49 +00:00
|
|
|
{
|
|
|
|
return putc(c, fp) != EOF;
|
|
|
|
}
|
|
|
|
|
2002-09-20 08:07:51 +00:00
|
|
|
static int writeshort(FILE *fp, unsigned short s)
|
2002-09-18 15:38:49 +00:00
|
|
|
{
|
|
|
|
putc(s, fp);
|
|
|
|
return putc(s>>8, fp) != EOF;
|
|
|
|
}
|
|
|
|
|
2006-02-08 13:05:37 +00:00
|
|
|
static int writeint(FILE *fp, unsigned int l)
|
2002-09-18 15:38:49 +00:00
|
|
|
{
|
|
|
|
putc(l, fp);
|
|
|
|
putc(l>>8, fp);
|
|
|
|
putc(l>>16, fp);
|
|
|
|
return putc(l>>24, fp) != EOF;
|
|
|
|
}
|
|
|
|
|
2002-09-20 08:07:51 +00:00
|
|
|
static int writestr(FILE *fp, char *str, int count)
|
2002-09-18 15:38:49 +00:00
|
|
|
{
|
2008-04-10 21:16:00 +00:00
|
|
|
return (int)fwrite(str, 1, count, fp) == count;
|
2002-09-18 15:38:49 +00:00
|
|
|
}
|
|
|
|
|
2008-04-10 21:16:00 +00:00
|
|
|
#ifndef ROTATE
|
2002-09-20 08:07:51 +00:00
|
|
|
static int writestrpad(FILE *fp, char *str, int totlen)
|
2002-09-18 15:38:49 +00:00
|
|
|
{
|
2009-03-13 18:56:55 +00:00
|
|
|
int ret = EOF;
|
2006-04-18 17:24:14 +00:00
|
|
|
|
2002-09-20 08:07:51 +00:00
|
|
|
while (str && *str && totlen > 0) {
|
2002-09-18 15:38:49 +00:00
|
|
|
if (*str) {
|
|
|
|
ret = putc(*str++, fp);
|
|
|
|
--totlen;
|
|
|
|
}
|
2002-09-20 08:07:51 +00:00
|
|
|
}
|
2002-09-18 15:38:49 +00:00
|
|
|
while (--totlen >= 0)
|
|
|
|
ret = putc(' ', fp);
|
|
|
|
return ret;
|
|
|
|
}
|
2008-04-10 21:16:00 +00:00
|
|
|
#endif
|
2002-09-18 15:38:49 +00:00
|
|
|
|
2010-05-17 20:55:55 +00:00
|
|
|
/* generate .fnt format file from in-core font */
|
2002-09-20 08:07:51 +00:00
|
|
|
int gen_fnt_file(struct font* pf, char *path)
|
2002-09-18 15:38:49 +00:00
|
|
|
{
|
|
|
|
FILE *ofp;
|
|
|
|
int i;
|
2005-08-31 17:26:22 +00:00
|
|
|
#ifdef ROTATE
|
|
|
|
int ofr = 0;
|
|
|
|
#endif
|
2002-09-18 15:38:49 +00:00
|
|
|
|
|
|
|
ofp = fopen(path, "wb");
|
|
|
|
if (!ofp) {
|
2009-03-07 22:09:00 +00:00
|
|
|
print_error("Can't create %s\n", path);
|
2002-09-18 15:38:49 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2010-05-17 20:55:55 +00:00
|
|
|
/* write magic and version number */
|
2002-09-20 08:07:51 +00:00
|
|
|
writestr(ofp, VERSION, 4);
|
2004-08-26 21:15:07 +00:00
|
|
|
#ifndef ROTATE
|
2010-05-17 20:55:55 +00:00
|
|
|
/* internal font name */
|
2002-09-20 08:07:51 +00:00
|
|
|
writestrpad(ofp, pf->name, 64);
|
2002-09-18 15:38:49 +00:00
|
|
|
|
2010-05-17 20:55:55 +00:00
|
|
|
/* copyright */
|
2002-09-20 08:07:51 +00:00
|
|
|
writestrpad(ofp, pf->copyright, 256);
|
2004-08-26 21:15:07 +00:00
|
|
|
#endif
|
2010-05-17 20:55:55 +00:00
|
|
|
/* font info */
|
2002-09-20 08:07:51 +00:00
|
|
|
writeshort(ofp, pf->maxwidth);
|
|
|
|
writeshort(ofp, pf->height);
|
|
|
|
writeshort(ofp, pf->ascent);
|
2011-03-05 18:36:51 +00:00
|
|
|
writeshort(ofp, 0); /* depth = 0 for bdffonts */
|
2006-02-08 13:05:37 +00:00
|
|
|
writeint(ofp, pf->firstchar);
|
|
|
|
writeint(ofp, pf->defaultchar);
|
|
|
|
writeint(ofp, pf->size);
|
2002-09-18 15:38:49 +00:00
|
|
|
|
2010-05-17 20:55:55 +00:00
|
|
|
/* variable font data sizes */
|
|
|
|
writeint(ofp, pf->bits_size); /* # words of bitmap_t */
|
|
|
|
writeint(ofp, pf->offset? pf->size: 0); /* # ints of offset */
|
|
|
|
writeint(ofp, pf->width? pf->size: 0); /* # bytes of width */
|
|
|
|
/* variable font data */
|
2004-08-26 21:15:07 +00:00
|
|
|
#ifdef ROTATE
|
|
|
|
for (i=0; i<pf->size; ++i)
|
|
|
|
{
|
2006-04-18 17:24:14 +00:00
|
|
|
bitmap_t* bits;
|
2004-08-26 21:15:07 +00:00
|
|
|
int width = pf->width ? pf->width[i] : pf->maxwidth;
|
2009-03-13 18:56:55 +00:00
|
|
|
int size;
|
|
|
|
int char_code = pf->firstchar + i;
|
|
|
|
unsigned char bytemap[ROTATION_BUF_SIZE];
|
2006-04-18 17:24:14 +00:00
|
|
|
|
|
|
|
/* Skip missing glyphs */
|
2009-03-06 22:50:47 +00:00
|
|
|
if (pf->offset && (pf->offset[i] == -1))
|
2006-04-18 17:24:14 +00:00
|
|
|
continue;
|
|
|
|
|
2008-04-10 21:16:00 +00:00
|
|
|
bits = pf->bits + (pf->offset? (int)pf->offset[i]: (pf->height * i));
|
2004-08-26 21:15:07 +00:00
|
|
|
|
2009-03-13 18:56:55 +00:00
|
|
|
size = rotleft(bytemap, sizeof(bytemap), bits, width, pf->height, char_code);
|
|
|
|
if (size < 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
2005-08-23 21:38:26 +00:00
|
|
|
writestr(ofp, (char *)bytemap, size);
|
|
|
|
|
|
|
|
/* update offrot since bits are now in sorted order */
|
|
|
|
pf->offrot[i] = ofr;
|
|
|
|
ofr += size;
|
2004-08-26 21:15:07 +00:00
|
|
|
}
|
|
|
|
|
2005-12-06 13:27:15 +00:00
|
|
|
if ( pf->bits_size < 0xFFDB )
|
|
|
|
{
|
|
|
|
/* bitmap offset is small enough, use unsigned short for offset */
|
|
|
|
if (ftell(ofp) & 1)
|
2010-05-17 20:55:55 +00:00
|
|
|
writebyte(ofp, 0); /* pad to 16-bit boundary */
|
2005-12-06 13:27:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-02-08 13:05:37 +00:00
|
|
|
/* bitmap offset is large then 64K, use unsigned int for offset */
|
2005-12-06 13:27:15 +00:00
|
|
|
while (ftell(ofp) & 3)
|
2010-05-17 20:55:55 +00:00
|
|
|
writebyte(ofp, 0); /* pad to 32-bit boundary */
|
2005-12-06 13:27:15 +00:00
|
|
|
}
|
2004-08-26 21:15:07 +00:00
|
|
|
|
|
|
|
if (pf->offset)
|
2005-12-06 13:27:15 +00:00
|
|
|
{
|
2004-08-26 21:15:07 +00:00
|
|
|
for (i=0; i<pf->size; ++i)
|
2005-12-06 13:27:15 +00:00
|
|
|
{
|
2010-05-17 20:37:45 +00:00
|
|
|
int offrot = pf->offrot[i];
|
2009-03-06 22:50:47 +00:00
|
|
|
if (pf->offset[i] == -1) {
|
2010-05-17 20:37:45 +00:00
|
|
|
offrot = pf->offrot[pf->defaultchar - pf->firstchar];
|
2006-04-18 17:24:14 +00:00
|
|
|
}
|
2005-12-06 13:27:15 +00:00
|
|
|
if ( pf->bits_size < 0xFFDB )
|
2010-05-17 20:37:45 +00:00
|
|
|
writeshort(ofp, offrot);
|
2005-12-06 13:27:15 +00:00
|
|
|
else
|
2010-05-17 20:37:45 +00:00
|
|
|
writeint(ofp, offrot);
|
2005-12-06 13:27:15 +00:00
|
|
|
}
|
|
|
|
}
|
2004-08-26 21:15:07 +00:00
|
|
|
|
|
|
|
if (pf->width)
|
|
|
|
for (i=0; i<pf->size; ++i)
|
|
|
|
writebyte(ofp, pf->width[i]);
|
|
|
|
#else
|
2002-09-18 15:38:49 +00:00
|
|
|
for (i=0; i<pf->bits_size; ++i)
|
2002-09-20 08:07:51 +00:00
|
|
|
writeshort(ofp, pf->bits[i]);
|
2002-09-18 15:38:49 +00:00
|
|
|
if (ftell(ofp) & 2)
|
2010-05-17 20:55:55 +00:00
|
|
|
writeshort(ofp, 0); /* pad to 32-bit boundary */
|
2002-09-18 15:38:49 +00:00
|
|
|
|
|
|
|
if (pf->offset)
|
2006-04-18 17:24:14 +00:00
|
|
|
for (i=0; i<pf->size; ++i) {
|
2010-05-17 20:37:45 +00:00
|
|
|
int offset = pf->offset[i];
|
|
|
|
if (offset == -1) {
|
|
|
|
offset = pf->offset[pf->defaultchar - pf->firstchar];
|
2006-04-18 17:24:14 +00:00
|
|
|
}
|
2010-05-17 20:37:45 +00:00
|
|
|
writeint(ofp, offset);
|
2006-04-18 17:24:14 +00:00
|
|
|
}
|
2002-09-18 15:38:49 +00:00
|
|
|
|
|
|
|
if (pf->width)
|
|
|
|
for (i=0; i<pf->size; ++i)
|
2002-09-20 08:07:51 +00:00
|
|
|
writebyte(ofp, pf->width[i]);
|
2004-08-26 21:15:07 +00:00
|
|
|
#endif
|
2002-09-18 15:38:49 +00:00
|
|
|
fclose(ofp);
|
|
|
|
return 0;
|
|
|
|
}
|