New full ISO-8859-1 system font.
Added font loading from dir browser. Changed default font location to /.rockbox/default.fnt. Code-policed font code. Removed old font tools. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@2347 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
eb5cc653db
commit
bed3d3f7e0
|
@ -68,6 +68,7 @@ void init(void)
|
|||
show_logo();
|
||||
settings_reset();
|
||||
settings_load();
|
||||
font_load(ROCKBOX_DIR "/default.fon");
|
||||
sleep(HZ/2);
|
||||
}
|
||||
|
||||
|
@ -89,10 +90,7 @@ void init(void)
|
|||
|
||||
lcd_init();
|
||||
|
||||
// FIXME should call font_init before this,
|
||||
// because may use loadable font in show_logo().
|
||||
// I didn't call font_init here, since
|
||||
// disk system isn't up yet.
|
||||
font_init();
|
||||
show_logo();
|
||||
|
||||
#ifdef DEBUG
|
||||
|
@ -148,6 +146,7 @@ void init(void)
|
|||
}
|
||||
|
||||
settings_load();
|
||||
font_load(ROCKBOX_DIR "/default.fon");
|
||||
|
||||
mpeg_init( global_settings.volume,
|
||||
global_settings.bass,
|
||||
|
@ -160,7 +159,6 @@ void init(void)
|
|||
status_init();
|
||||
usb_start_monitoring();
|
||||
power_init();
|
||||
font_init();
|
||||
}
|
||||
|
||||
int main(void)
|
||||
|
|
|
@ -93,14 +93,19 @@ void put_cursorxy(int x, int y, bool on)
|
|||
{
|
||||
#ifdef HAVE_LCD_BITMAP
|
||||
int fh, fw;
|
||||
int xpos, ypos;
|
||||
lcd_getfontsize(FONT_UI, &fw, &fh);
|
||||
xpos = x*6;
|
||||
ypos = y*fh + lcd_getymargin();
|
||||
if ( fh > 8 )
|
||||
ypos += (fh - 8) / 2;
|
||||
#endif
|
||||
|
||||
/* place the cursor */
|
||||
if(on) {
|
||||
#ifdef HAVE_LCD_BITMAP
|
||||
lcd_bitmap ( bitmap_icons_6x8[Cursor],
|
||||
x*6, y*fh + lcd_getymargin(), 4, 8, true);
|
||||
xpos, ypos, 4, 8, true);
|
||||
#elif defined(SIMULATOR)
|
||||
/* player simulator */
|
||||
unsigned char cursor[] = { 0x7f, 0x3e, 0x1c, 0x08 };
|
||||
|
@ -112,7 +117,7 @@ void put_cursorxy(int x, int y, bool on)
|
|||
else {
|
||||
#if defined(HAVE_LCD_BITMAP)
|
||||
/* I use xy here since it needs to disregard the margins */
|
||||
lcd_clearrect (x*6, y*fh + lcd_getymargin(), 4, 8);
|
||||
lcd_clearrect (xpos, ypos, 4, 8);
|
||||
#elif defined(SIMULATOR)
|
||||
/* player simulator in action */
|
||||
lcd_clearrect (x*6, 12+y*16, 4, 8);
|
||||
|
|
|
@ -69,6 +69,8 @@ unsigned char bitmap_icons_6x8[LastIcon][6] =
|
|||
{ 0x58, 0x5f, 0x42, 0x50, 0x55, 0x00 },
|
||||
/* Mod or ajz file */
|
||||
{ 0x63, 0x7f, 0x3a, 0x7f, 0x63, 0x00 },
|
||||
/* Font file */
|
||||
{ 0x60, 0x70, 0x38, 0x2c, 0x7e, 0x7e },
|
||||
};
|
||||
|
||||
unsigned char bitmap_icons_7x8[][7] =
|
||||
|
@ -234,10 +236,10 @@ void statusbar_icon_volume(int percent)
|
|||
/* display volume lever numerical? */
|
||||
if (TIME_BEFORE(current_tick,switch_tick)) {
|
||||
snprintf(buffer, sizeof(buffer), "%2d", percent);
|
||||
lcd_getstringsize(buffer, FONT_UI, &width, &height);
|
||||
lcd_getstringsize(buffer, FONT_SYSFIXED, &width, &height);
|
||||
if (height <= STATUSBAR_HEIGHT)
|
||||
lcd_putsxy(ICON_VOLUME_X_POS + ICON_VOLUME_WIDTH / 2 -
|
||||
width/2, STATUSBAR_Y_POS, buffer, 0);
|
||||
width/2, STATUSBAR_Y_POS, buffer, FONT_SYSFIXED);
|
||||
}
|
||||
else { /* display volume bar */
|
||||
volume = volume * 14 / 100;
|
||||
|
@ -309,8 +311,8 @@ void statusbar_time(int hour, int minute)
|
|||
strncpy(buffer, "--:--", sizeof buffer);
|
||||
}
|
||||
|
||||
lcd_getstringsize(buffer, FONT_UI, &width, &height);
|
||||
lcd_getstringsize(buffer, FONT_SYSFIXED, &width, &height);
|
||||
if (height <= STATUSBAR_HEIGHT)
|
||||
lcd_putsxy(TIME_X_END - width, STATUSBAR_Y_POS, buffer, 0);
|
||||
lcd_putsxy(TIME_X_END - width, STATUSBAR_Y_POS, buffer, FONT_SYSFIXED);
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -28,6 +28,7 @@ enum icons_6x8 {
|
|||
Box_Filled, Box_Empty, Slider_Horizontal, File,
|
||||
Folder, Directory, Playlist, Repeat,
|
||||
Selected, Cursor, Wps, Mod_Ajz,
|
||||
Font,
|
||||
LastIcon
|
||||
};
|
||||
|
||||
|
|
36
apps/tree.c
36
apps/tree.c
|
@ -137,7 +137,8 @@ extern unsigned char bitmap_icons_6x8[LastIcon][6];
|
|||
#define TREE_ATTR_M3U 0x80 /* playlist */
|
||||
#define TREE_ATTR_WPS 0x100 /* wps config file */
|
||||
#define TREE_ATTR_MOD 0x200 /* firmware file */
|
||||
#define TREE_ATTR_EQ 0x300 /* EQ config file */
|
||||
#define TREE_ATTR_EQ 0x400 /* EQ config file */
|
||||
#define TREE_ATTR_FONT 0x800 /* font file */
|
||||
#define TREE_ATTR_MASK 0xffd0 /* which bits tree.c uses (above + DIR) */
|
||||
|
||||
static int build_playlist(int start_index)
|
||||
|
@ -182,14 +183,12 @@ static int compare(const void* p1, const void* p2)
|
|||
static int showdir(char *path, int start)
|
||||
{
|
||||
int icon_type = 0;
|
||||
#ifdef HAVE_LCD_BITMAP
|
||||
int line_height = LINE_HEIGTH;
|
||||
#endif
|
||||
int i;
|
||||
int tree_max_on_screen;
|
||||
bool dir_buffer_full;
|
||||
|
||||
#ifdef HAVE_LCD_BITMAP
|
||||
int line_height = LINE_HEIGTH;
|
||||
int fw, fh;
|
||||
lcd_getfontsize(FONT_UI, &fw, &fh);
|
||||
tree_max_on_screen = (LCD_HEIGHT - MARGIN_Y) / fh;
|
||||
|
@ -255,6 +254,8 @@ static int showdir(char *path, int start)
|
|||
else if (!strcasecmp(&entry->d_name[len-4], ".wps"))
|
||||
dptr->attr |= TREE_ATTR_WPS;
|
||||
#ifdef HAVE_RECORDER_KEYPAD
|
||||
else if (!strcasecmp(&entry->d_name[len-4], ".fnt"))
|
||||
dptr->attr |= TREE_ATTR_FONT;
|
||||
else if (!strcasecmp(&entry->d_name[len-4], ".ajz"))
|
||||
#else
|
||||
else if (!strcasecmp(&entry->d_name[len-4], ".mod"))
|
||||
|
@ -372,15 +373,24 @@ static int showdir(char *path, int start)
|
|||
icon_type = Mod_Ajz;
|
||||
break;
|
||||
|
||||
#ifdef HAVE_LCD_BITMAP
|
||||
case TREE_ATTR_FONT:
|
||||
icon_type = Font;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
icon_type = 0;
|
||||
}
|
||||
|
||||
if (icon_type) {
|
||||
#ifdef HAVE_LCD_BITMAP
|
||||
int offset=0;
|
||||
if ( line_height > 8 )
|
||||
offset = (line_height - 8) / 2;
|
||||
lcd_bitmap(bitmap_icons_6x8[icon_type],
|
||||
CURSOR_X * 6 + CURSOR_WIDTH,
|
||||
MARGIN_Y+(i-start)*line_height, 6, 8, true);
|
||||
MARGIN_Y+(i-start)*line_height + offset,
|
||||
6, 8, true);
|
||||
#else
|
||||
lcd_define_pattern((i-start)*8,tree_icons_5x7[icon_type],8);
|
||||
lcd_putc(LINE_X-1, i-start, i-start);
|
||||
|
@ -712,6 +722,22 @@ bool dirbrowse(char *root)
|
|||
restore = true;
|
||||
break;
|
||||
|
||||
#ifdef HAVE_LCD_BITMAP
|
||||
case TREE_ATTR_FONT:
|
||||
snprintf(buf, sizeof buf, "%s/%s",
|
||||
currdir, file->name);
|
||||
font_load(buf);
|
||||
lcd_getfontsize(FONT_UI, &fw, &fh);
|
||||
tree_max_on_screen = (LCD_HEIGHT - MARGIN_Y) / fh;
|
||||
/* make sure cursor is on screen */
|
||||
while ( dircursor > tree_max_on_screen ) {
|
||||
dircursor--;
|
||||
dirstart++;
|
||||
}
|
||||
restore = true;
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifndef SIMULATOR
|
||||
/* firmware file */
|
||||
case TREE_ATTR_MOD:
|
||||
|
|
|
@ -19,6 +19,7 @@ SYSTEM_FONT = fonts/alt6x10.bdf
|
|||
|
||||
# store output files in this directory:
|
||||
OBJDIR = .
|
||||
TOOLSDIR = ../tools
|
||||
|
||||
CFLAGS = -W -Wall -O -m1 -nostdlib -ffreestanding -Wstrict-prototypes $(INCLUDES) $(TARGET) $(EXTRA_DEFINES)
|
||||
|
||||
|
@ -38,9 +39,8 @@ DIRS = $(subst $(DEPS),".",$(DEPDIRS))
|
|||
|
||||
OUTPUT = $(OBJDIR)/librockbox.a
|
||||
|
||||
|
||||
ifeq (LOADABLE_FONTS,$(findstring LOADABLE_FONTS, $(CFLAGS)))
|
||||
EXTRA_TARGETS = $(OBJDIR)/system.ajf
|
||||
ifeq (RECORDER,$(findstring RECORDER, $(CFLAGS)))
|
||||
OBJS += $(OBJDIR)/sysfont.o
|
||||
endif
|
||||
|
||||
all: $(OUTPUT) $(EXTRA_TARGETS)
|
||||
|
@ -70,6 +70,10 @@ clean:
|
|||
$(OBJDIR)/thread.o: thread.c thread.h
|
||||
$(CC) -c -O -fomit-frame-pointer $(CFLAGS) $< -o $@
|
||||
|
||||
$(OBJDIR)/sysfont.o: fonts/clR6x8.bdf
|
||||
$(TOOLSDIR)/convbdf -c -o $(OBJDIR)/sysfont.c $<
|
||||
$(CC) $(CFLAGS) -c $(OBJDIR)/sysfont.c -o $@
|
||||
|
||||
$(OBJDIR)/$(DEPS)/%.d: %.c
|
||||
@$(SHELL) -c 'for d in $(DEPDIRS); do { if [ ! -d $(OBJDIR)/$$d ]; then mkdir $(OBJDIR)/$$d; fi; }; done'
|
||||
@echo "Updating dependencies for $<"
|
||||
|
|
1967
firmware/X5x8.bdf
1967
firmware/X5x8.bdf
File diff suppressed because it is too large
Load Diff
2853
firmware/X5x8.c
2853
firmware/X5x8.c
File diff suppressed because it is too large
Load Diff
|
@ -547,7 +547,6 @@ void lcd_set_contrast(int val)
|
|||
*/
|
||||
unsigned char lcd_framebuffer[LCD_WIDTH][LCD_HEIGHT/8];
|
||||
|
||||
static int font=0;
|
||||
static int xmargin=0;
|
||||
static int ymargin=0;
|
||||
|
||||
|
@ -661,11 +660,6 @@ void lcd_clear_display (void)
|
|||
#endif
|
||||
}
|
||||
|
||||
void lcd_setfont(int newfont)
|
||||
{
|
||||
font = newfont;
|
||||
}
|
||||
|
||||
void lcd_setmargins(int x, int y)
|
||||
{
|
||||
xmargin = x;
|
||||
|
@ -682,10 +676,11 @@ int lcd_getymargin(void)
|
|||
return ymargin;
|
||||
}
|
||||
|
||||
static int curfont = FONT_SYSFIXED;
|
||||
|
||||
/*
|
||||
* Put a string at specified character position
|
||||
*/
|
||||
//FIXME require font parameter
|
||||
void lcd_puts(int x, int y, unsigned char *str)
|
||||
{
|
||||
int xpos,ypos,w,h;
|
||||
|
@ -707,10 +702,10 @@ void lcd_puts(int x, int y, unsigned char *str)
|
|||
if(!str || !str[0])
|
||||
return;
|
||||
|
||||
lcd_getstringsize(str, font, &w, &h);
|
||||
xpos = xmargin + x*w / strlen(str); //FIXME why strlen?
|
||||
lcd_getstringsize(str, curfont, &w, &h);
|
||||
xpos = xmargin + x*w / strlen(str);
|
||||
ypos = ymargin + y*h;
|
||||
lcd_putsxy( xpos, ypos, str, font);
|
||||
lcd_putsxy( xpos, ypos, str, curfont);
|
||||
lcd_clearrect(xpos + w, ypos, LCD_WIDTH - (xpos + w), h);
|
||||
#if defined(SIMULATOR) && defined(HAVE_LCD_CHARCELLS)
|
||||
/* this function is being used when simulating a charcell LCD and
|
||||
|
@ -719,6 +714,80 @@ void lcd_puts(int x, int y, unsigned char *str)
|
|||
#endif
|
||||
}
|
||||
|
||||
/* set current font*/
|
||||
void lcd_setfont(int newfont)
|
||||
{
|
||||
curfont = newfont;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return width and height of a given font.
|
||||
*/
|
||||
void lcd_getfontsize(int font, int *width, int *height)
|
||||
{
|
||||
struct font* pf = font_get(font);
|
||||
|
||||
*width = pf->maxwidth;
|
||||
*height = pf->height;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Return width and height of a given font.
|
||||
*/
|
||||
int lcd_getstringsize(unsigned char *str, int font, int *w, int *h)
|
||||
{
|
||||
struct font* pf = font_get(font);
|
||||
int ch;
|
||||
int width = 0;
|
||||
|
||||
while((ch = *str++)) {
|
||||
/* check input range*/
|
||||
if (ch < pf->firstchar || ch >= pf->firstchar+pf->size)
|
||||
ch = pf->defaultchar;
|
||||
ch -= pf->firstchar;
|
||||
|
||||
/* get proportional width and glyph bits*/
|
||||
width += pf->width? pf->width[ch]: pf->maxwidth;
|
||||
}
|
||||
*w = width;
|
||||
*h = pf->height;
|
||||
|
||||
return width;
|
||||
}
|
||||
|
||||
/*
|
||||
* Put a string at specified bit position
|
||||
*/
|
||||
void lcd_putsxy(int x, int y, unsigned char *str, int font)
|
||||
{
|
||||
int ch;
|
||||
struct font* pf = font_get(font);
|
||||
|
||||
while (((ch = *str++) != '\0')) {
|
||||
bitmap_t *bits;
|
||||
int width;
|
||||
|
||||
/* check input range*/
|
||||
if (ch < pf->firstchar || ch >= pf->firstchar+pf->size)
|
||||
ch = pf->defaultchar;
|
||||
ch -= pf->firstchar;
|
||||
|
||||
/* get proportional width and glyph bits*/
|
||||
width = pf->width ? pf->width[ch] : pf->maxwidth;
|
||||
if (x + width > LCD_WIDTH)
|
||||
break;
|
||||
|
||||
/* no partial-height drawing for now...*/
|
||||
if (y + pf->height > LCD_HEIGHT)
|
||||
break;
|
||||
bits = pf->bits + (pf->offset ? pf->offset[ch] : (pf->height * ch));
|
||||
|
||||
lcd_bitmap((unsigned char *)bits, x, y, width, pf->height, true);
|
||||
x += width;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Display a bitmap at (x, y), size (nx, ny)
|
||||
* clear is true to clear destination area first
|
||||
|
@ -1038,14 +1107,14 @@ void lcd_puts_scroll(int x, int y, unsigned char* string )
|
|||
unsigned char ch[2];
|
||||
int w, h;
|
||||
int width, height;
|
||||
lcd_getfontsize(font, &width, &height);
|
||||
lcd_getfontsize(curfont, &width, &height);
|
||||
|
||||
ch[1] = 0; /* zero terminate */
|
||||
ch[0] = string[0];
|
||||
width = 0;
|
||||
s->space = 0;
|
||||
while ( ch[0] &&
|
||||
(width + lcd_getstringsize(ch, 0, &w, &h) <
|
||||
(width + lcd_getstringsize(ch, curfont, &w, &h) <
|
||||
(LCD_WIDTH - x*8))) {
|
||||
width += w;
|
||||
s->space++;
|
||||
|
@ -1058,7 +1127,7 @@ void lcd_puts_scroll(int x, int y, unsigned char* string )
|
|||
|
||||
#ifdef HAVE_LCD_BITMAP
|
||||
s->space += 2;
|
||||
lcd_getstringsize(string,0,&w,&h);
|
||||
lcd_getstringsize(string,curfont,&w,&h);
|
||||
if ( w > LCD_WIDTH - xmargin ) {
|
||||
#else
|
||||
if ( s->textlen > s->space ) {
|
||||
|
|
|
@ -99,9 +99,6 @@ extern void lcd_double_height (bool on);
|
|||
*/
|
||||
extern unsigned char lcd_framebuffer[LCD_WIDTH][LCD_HEIGHT/8];
|
||||
|
||||
extern void lcd_putsxy(int x, int y, unsigned char *string, int font);
|
||||
extern void lcd_setfont(int font);
|
||||
extern void lcd_getfontsize(int font, int *width, int *height);
|
||||
extern void lcd_setmargins(int xmargin, int ymargin);
|
||||
extern int lcd_getxmargin(void);
|
||||
extern int lcd_getymargin(void);
|
||||
|
@ -118,6 +115,10 @@ extern void lcd_clearpixel(int x, int y);
|
|||
extern void lcd_invertpixel(int x, int y);
|
||||
extern void lcd_roll(int pixels);
|
||||
|
||||
extern void lcd_setfont(int font);
|
||||
extern void lcd_getfontsize(int font, int *width, int *height);
|
||||
extern void lcd_putsxy(int x, int y, unsigned char *string, int font);
|
||||
|
||||
#endif /* CHARCELLS / BITMAP */
|
||||
|
||||
extern int lcd_getstringsize(unsigned char *str, int font, int *w, int *h);
|
||||
|
|
349
firmware/font.c
349
firmware/font.c
|
@ -30,47 +30,210 @@
|
|||
#include <string.h>
|
||||
#include "lcd.h"
|
||||
#include "font.h"
|
||||
#include "file.h"
|
||||
#include "debug.h"
|
||||
#include "panic.h"
|
||||
|
||||
/* available compiled-in fonts*/
|
||||
extern MWCFONT font_X5x8;
|
||||
/*extern MWCFONT font_X6x9; */
|
||||
/*extern MWCFONT font_courB08; */
|
||||
/*extern MWCFONT font_timR08; */
|
||||
|
||||
/* structure filled in by rbf_load_font*/
|
||||
static MWCFONT font_UI;
|
||||
|
||||
/* system font table, in order of FONT_xxx definition*/
|
||||
struct corefont sysfonts[MAXFONTS] = {
|
||||
{ &font_X5x8, NULL }, /* compiled-in FONT_SYSFIXED*/
|
||||
{ &font_UI, "/system.fnt" }, /* loaded FONT_UI*/
|
||||
{ NULL, NULL }, /* no FONT_MP3*/
|
||||
};
|
||||
|
||||
static void rotate_font_bits(PMWCFONT pf);
|
||||
static void rotleft(unsigned char *dst, MWIMAGEBITS *src, unsigned int width,
|
||||
unsigned int height);
|
||||
|
||||
void
|
||||
font_init(void)
|
||||
{
|
||||
struct corefont *cfp;
|
||||
|
||||
for (cfp=sysfonts; cfp < &sysfonts[MAXFONTS]; ++cfp) {
|
||||
if (cfp->pf && cfp->diskname) {
|
||||
cfp->pf = rbf_load_font(cfp->diskname, cfp->pf);
|
||||
#if defined(DEBUG) || defined(SIMULATOR)
|
||||
if (!cfp->pf)
|
||||
DEBUGF("Font load failed: %s\n", cfp->diskname);
|
||||
#ifndef O_BINARY
|
||||
#define O_BINARY 0
|
||||
#endif
|
||||
}
|
||||
|
||||
/* one-time rotate font bits to rockbox format*/
|
||||
if (cfp->pf && cfp->pf->height)
|
||||
rotate_font_bits(cfp->pf);
|
||||
/* compiled-in font */
|
||||
extern struct font sysfont;
|
||||
|
||||
/* structure filled in by font_load */
|
||||
static struct font font_ui;
|
||||
|
||||
/* system font table, in order of FONT_xxx definition */
|
||||
static struct font* sysfonts[MAXFONTS] = { &sysfont, &font_ui };
|
||||
|
||||
/* static buffer allocation structures */
|
||||
static unsigned char mbuf[MAX_FONT_SIZE];
|
||||
static unsigned char *freeptr = mbuf;
|
||||
static unsigned char *fileptr;
|
||||
static unsigned char *eofptr;
|
||||
|
||||
static void rotate_font_bits(struct font* pf);
|
||||
static void rotleft(unsigned char *dst,
|
||||
bitmap_t *src,
|
||||
unsigned int width,
|
||||
unsigned int height);
|
||||
|
||||
void font_init(void)
|
||||
{
|
||||
rotate_font_bits(&sysfont);
|
||||
memset(&font_ui, 0, sizeof(struct font));
|
||||
}
|
||||
|
||||
static int readshort(unsigned short *sp)
|
||||
{
|
||||
unsigned short s;
|
||||
|
||||
s = *fileptr++ & 0xff;
|
||||
*sp = (*fileptr++ << 8) | s;
|
||||
return (fileptr <= eofptr);
|
||||
}
|
||||
|
||||
static int readlong(unsigned long *lp)
|
||||
{
|
||||
unsigned long l;
|
||||
|
||||
l = *fileptr++ & 0xff;
|
||||
l |= *fileptr++ << 8;
|
||||
l |= *fileptr++ << 16;
|
||||
*lp = (*fileptr++ << 24) | l;
|
||||
return (fileptr <= eofptr);
|
||||
}
|
||||
|
||||
/* read count bytes*/
|
||||
static int readstr(char *buf, int count)
|
||||
{
|
||||
int n = count;
|
||||
|
||||
while (--n >= 0)
|
||||
*buf++ = *fileptr++;
|
||||
return (fileptr <= eofptr)? count: 0;
|
||||
}
|
||||
|
||||
/* read totlen bytes, return NUL terminated string*/
|
||||
/* may write 1 past buf[totlen]; removes blank pad*/
|
||||
static int readstrpad(char *buf, int totlen)
|
||||
{
|
||||
char *p = buf;
|
||||
int n = totlen;
|
||||
|
||||
while (--n >= 0)
|
||||
*p++ = *fileptr++;
|
||||
if (fileptr > eofptr)
|
||||
return 0;
|
||||
|
||||
p = &buf[totlen];
|
||||
*p-- = 0;
|
||||
while (*p == ' ' && p >= buf)
|
||||
*p-- = '\0';
|
||||
return totlen;
|
||||
}
|
||||
|
||||
/* read and load font into incore font structure*/
|
||||
struct font* font_load(char *path)
|
||||
{
|
||||
int fd, filesize;
|
||||
unsigned short maxwidth, height, ascent, pad;
|
||||
unsigned long firstchar, defaultchar, size;
|
||||
unsigned long i, nbits, noffset, nwidth;
|
||||
char version[4+1];
|
||||
char copyright[256+1];
|
||||
struct font* pf = &font_ui;
|
||||
|
||||
memset(pf, 0, sizeof(struct font));
|
||||
|
||||
/* open and read entire font file*/
|
||||
fd = open(path, O_RDONLY|O_BINARY);
|
||||
if (fd < 0) {
|
||||
DEBUGF("Can't open font: %s\n", path);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* currently, font loading replaces earlier font allocation*/
|
||||
freeptr = (unsigned char *)(((int)mbuf + 3) & ~3);
|
||||
|
||||
fileptr = freeptr;
|
||||
filesize = read(fd, fileptr, MAX_FONT_SIZE);
|
||||
eofptr = fileptr + filesize;
|
||||
|
||||
/* no need for multiple font loads currently*/
|
||||
/*freeptr += filesize;*/
|
||||
/*freeptr = (unsigned char *)(freeptr + 3) & ~3;*/ /* pad freeptr*/
|
||||
|
||||
close(fd);
|
||||
if (filesize == MAX_FONT_SIZE) {
|
||||
DEBUGF("Font %s too large: %d\n", path, filesize);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* read magic and version #*/
|
||||
memset(version, 0, sizeof(version));
|
||||
if (readstr(version, 4) != 4)
|
||||
return NULL;
|
||||
if (strcmp(version, VERSION) != 0)
|
||||
return NULL;
|
||||
|
||||
/* internal font name*/
|
||||
pf->name = fileptr;
|
||||
if (readstrpad(pf->name, 64) != 64)
|
||||
return NULL;
|
||||
|
||||
/* copyright, not currently stored*/
|
||||
if (readstrpad(copyright, 256) != 256)
|
||||
return NULL;
|
||||
|
||||
/* font info*/
|
||||
if (!readshort(&maxwidth))
|
||||
return NULL;
|
||||
pf->maxwidth = maxwidth;
|
||||
if (!readshort(&height))
|
||||
return NULL;
|
||||
pf->height = height;
|
||||
if (!readshort(&ascent))
|
||||
return NULL;
|
||||
pf->ascent = ascent;
|
||||
if (!readshort(&pad))
|
||||
return NULL;
|
||||
if (!readlong(&firstchar))
|
||||
return NULL;
|
||||
pf->firstchar = firstchar;
|
||||
if (!readlong(&defaultchar))
|
||||
return NULL;
|
||||
pf->defaultchar = defaultchar;
|
||||
if (!readlong(&size))
|
||||
return NULL;
|
||||
pf->size = size;
|
||||
|
||||
/* get variable font data sizes*/
|
||||
/* # words of bitmap_t*/
|
||||
if (!readlong(&nbits))
|
||||
return NULL;
|
||||
pf->bits_size = nbits;
|
||||
|
||||
/* # longs of offset*/
|
||||
if (!readlong(&noffset))
|
||||
return NULL;
|
||||
|
||||
/* # bytes of width*/
|
||||
if (!readlong(&nwidth))
|
||||
return NULL;
|
||||
|
||||
/* variable font data*/
|
||||
pf->bits = (bitmap_t *)fileptr;
|
||||
for (i=0; i<nbits; ++i)
|
||||
if (!readshort(&pf->bits[i]))
|
||||
return NULL;
|
||||
/* pad to longword boundary*/
|
||||
fileptr = (unsigned char *)(((int)fileptr + 3) & ~3);
|
||||
|
||||
if (noffset) {
|
||||
pf->offset = (unsigned long *)fileptr;
|
||||
for (i=0; i<noffset; ++i)
|
||||
if (!readlong(&pf->offset[i]))
|
||||
return NULL;
|
||||
}
|
||||
else
|
||||
pf->offset = NULL;
|
||||
|
||||
if (nwidth) {
|
||||
pf->width = (unsigned char *)fileptr;
|
||||
fileptr += nwidth*sizeof(unsigned char);
|
||||
}
|
||||
else
|
||||
pf->width = NULL;
|
||||
|
||||
if (fileptr > eofptr)
|
||||
return NULL;
|
||||
|
||||
/* one-time rotate font bits to rockbox format*/
|
||||
rotate_font_bits(pf);
|
||||
|
||||
return pf; /* success!*/
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -78,15 +241,15 @@ font_init(void)
|
|||
* If the requested font isn't loaded/compiled-in,
|
||||
* decrement the font number and try again.
|
||||
*/
|
||||
PMWCFONT
|
||||
getfont(int font)
|
||||
struct font* font_get(int font)
|
||||
{
|
||||
PMWCFONT pf;
|
||||
struct font* pf;
|
||||
|
||||
if (font >= MAXFONTS)
|
||||
font = 0;
|
||||
|
||||
while (1) {
|
||||
pf = sysfonts[font].pf;
|
||||
pf = sysfonts[font];
|
||||
if (pf && pf->height)
|
||||
return pf;
|
||||
if (--font < 0)
|
||||
|
@ -94,101 +257,30 @@ getfont(int font)
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Return width and height of a given font.
|
||||
*/
|
||||
void lcd_getfontsize(int font, int *width, int *height)
|
||||
{
|
||||
PMWCFONT pf = getfont(font);
|
||||
|
||||
*width = pf->maxwidth;
|
||||
*height = pf->height;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return width and height of a given font.
|
||||
*/
|
||||
//FIXME rename to font_gettextsize, add baseline
|
||||
int
|
||||
lcd_getstringsize(unsigned char *str, int font, int *w, int *h)
|
||||
{
|
||||
PMWCFONT pf = getfont(font);
|
||||
int ch;
|
||||
int width = 0;
|
||||
|
||||
while((ch = *str++)) {
|
||||
/* check input range*/
|
||||
if (ch < pf->firstchar || ch >= pf->firstchar+pf->size)
|
||||
ch = pf->defaultchar;
|
||||
ch -= pf->firstchar;
|
||||
|
||||
/* get proportional width and glyph bits*/
|
||||
width += pf->width? pf->width[ch]: pf->maxwidth;
|
||||
}
|
||||
*w = width;
|
||||
*h = pf->height;
|
||||
|
||||
return width;
|
||||
}
|
||||
|
||||
/*
|
||||
* Put a string at specified bit position
|
||||
*/
|
||||
//FIXME rename font_putsxy?
|
||||
void
|
||||
lcd_putsxy(int x, int y, unsigned char *str, int font)
|
||||
{
|
||||
int ch;
|
||||
PMWCFONT pf = getfont(font);
|
||||
|
||||
while (((ch = *str++) != '\0')) {
|
||||
MWIMAGEBITS *bits;
|
||||
int width;
|
||||
|
||||
/* check input range*/
|
||||
if (ch < pf->firstchar || ch >= pf->firstchar+pf->size)
|
||||
ch = pf->defaultchar;
|
||||
ch -= pf->firstchar;
|
||||
|
||||
/* get proportional width and glyph bits*/
|
||||
width = pf->width? pf->width[ch]: pf->maxwidth;
|
||||
if (x + width > LCD_WIDTH)
|
||||
break;
|
||||
|
||||
/* no partial-height drawing for now...*/
|
||||
if (y + pf->height > LCD_HEIGHT)
|
||||
break;
|
||||
bits = pf->bits + (pf->offset? pf->offset[ch]: (pf->height * ch));
|
||||
|
||||
lcd_bitmap((unsigned char *)bits, x, y, width, pf->height, true);
|
||||
x += width;
|
||||
}
|
||||
}
|
||||
|
||||
/* convert font bitmap data inplace to rockbox format*/
|
||||
static void
|
||||
rotate_font_bits(PMWCFONT pf)
|
||||
static void rotate_font_bits(struct font* pf)
|
||||
{
|
||||
int i;
|
||||
int defaultchar = pf->defaultchar - pf->firstchar;
|
||||
int did_defaultchar = 0;
|
||||
unsigned long defaultchar = pf->defaultchar - pf->firstchar;
|
||||
bool did_defaultchar = false;
|
||||
unsigned char buf[256];
|
||||
|
||||
for (i=0; i<pf->size; ++i) {
|
||||
MWIMAGEBITS *bits = pf->bits +
|
||||
(pf->offset? pf->offset[i]: (pf->height * i));
|
||||
bitmap_t *bits = pf->bits +
|
||||
(pf->offset ? pf->offset[i] : (pf->height * i));
|
||||
int width = pf->width? pf->width[i]: pf->maxwidth;
|
||||
int src_bytes = MWIMAGE_BYTES(width) * pf->height;
|
||||
int src_bytes = BITMAP_BYTES(width) * pf->height;
|
||||
|
||||
/*
|
||||
* Due to the way the offset map works,
|
||||
* non-mapped characters are mapped to the default
|
||||
* character, and shouldn't be rotated twice.
|
||||
*/
|
||||
if (i == defaultchar) {
|
||||
|
||||
if (pf->offset && pf->offset[i] == defaultchar) {
|
||||
if (did_defaultchar)
|
||||
continue;
|
||||
did_defaultchar = 1;
|
||||
did_defaultchar = true;
|
||||
}
|
||||
|
||||
/* rotate left for lcd_bitmap function input*/
|
||||
|
@ -200,16 +292,15 @@ rotate_font_bits(PMWCFONT pf)
|
|||
}
|
||||
|
||||
/*
|
||||
* Take an MWIMAGEBITS bitmap and convert to Rockbox format.
|
||||
* 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.
|
||||
*
|
||||
* Doing it this way keeps fonts in standard formats,
|
||||
* as well as keeping Rockbox hw bitmap format.
|
||||
*/
|
||||
static void
|
||||
rotleft(unsigned char *dst, MWIMAGEBITS *src, unsigned int width,
|
||||
unsigned int height)
|
||||
static void rotleft(unsigned char *dst, bitmap_t *src, unsigned int width,
|
||||
unsigned int height)
|
||||
{
|
||||
unsigned int i,j;
|
||||
unsigned int dst_col = 0; /* destination column*/
|
||||
|
@ -221,17 +312,17 @@ rotleft(unsigned char *dst, MWIMAGEBITS *src, unsigned int width,
|
|||
dst_linelen = (height-1)/8+1;
|
||||
|
||||
/* calc words of input image*/
|
||||
src_words = MWIMAGE_WORDS(width) * height;
|
||||
src_words = BITMAP_WORDS(width) * height;
|
||||
|
||||
/* clear background*/
|
||||
memset(dst, 0, dst_linelen*width);
|
||||
|
||||
for (i=0; i < src_words; i++) {
|
||||
MWIMAGEBITS srcmap; /* current src input bit*/
|
||||
MWIMAGEBITS dstmap; /* current dst output bit*/
|
||||
bitmap_t srcmap; /* current src input bit*/
|
||||
bitmap_t dstmap; /* current dst output bit*/
|
||||
|
||||
/* calc src input bit*/
|
||||
srcmap = 1 << (sizeof(MWIMAGEBITS)*8-1);
|
||||
srcmap = 1 << (sizeof(bitmap_t)*8-1);
|
||||
|
||||
/* calc dst output bit*/
|
||||
if (i>0 && (i%8==0)) {
|
||||
|
@ -244,9 +335,9 @@ rotleft(unsigned char *dst, MWIMAGEBITS *src, unsigned int width,
|
|||
for(j=0; j < width; j++) {
|
||||
|
||||
/* calc input bitmask*/
|
||||
MWIMAGEBITS bit = srcmap >> j;
|
||||
bitmap_t bit = srcmap >> j;
|
||||
if (bit==0) {
|
||||
srcmap = 1 << (sizeof(MWIMAGEBITS)*8-1);
|
||||
srcmap = 1 << (sizeof(bitmap_t)*8-1);
|
||||
bit = srcmap >> (j % 16);
|
||||
}
|
||||
|
||||
|
|
|
@ -38,13 +38,14 @@
|
|||
* must be available at system startup.
|
||||
* Fonts are specified in firmware/font.c.
|
||||
*/
|
||||
#define FONT_SYSFIXED 0 /* system fixed pitch font*/
|
||||
#define FONT_UI 1 /* system porportional font*/
|
||||
#define FONT_MP3 2 /* font used for mp3 info*/
|
||||
#define MAXFONTS 3 /* max # fonts*/
|
||||
enum {
|
||||
FONT_SYSFIXED, /* system fixed pitch font*/
|
||||
FONT_UI, /* system porportional font*/
|
||||
MAXFONTS
|
||||
};
|
||||
|
||||
/*
|
||||
* .fnt (.rbf) loadable font file format definition
|
||||
* .fnt loadable font file format definition
|
||||
*
|
||||
* format len description
|
||||
* ------------------------- ---- ------------------------------
|
||||
|
@ -70,54 +71,42 @@
|
|||
/* loadable font magic and version #*/
|
||||
#define VERSION "RB11"
|
||||
|
||||
/* MWIMAGEBITS helper macros*/
|
||||
#define MWIMAGE_WORDS(x) (((x)+15)/16) /* image size in words*/
|
||||
#define MWIMAGE_BYTES(x) (MWIMAGE_WORDS(x)*sizeof(MWIMAGEBITS))
|
||||
#define MWIMAGE_BITSPERIMAGE (sizeof(MWIMAGEBITS) * 8)
|
||||
#define MWIMAGE_BITVALUE(n) ((MWIMAGEBITS) (((MWIMAGEBITS) 1) << (n)))
|
||||
#define MWIMAGE_FIRSTBIT (MWIMAGE_BITVALUE(MWIMAGE_BITSPERIMAGE - 1))
|
||||
#define MWIMAGE_TESTBIT(m) ((m) & MWIMAGE_FIRSTBIT)
|
||||
#define MWIMAGE_SHIFTBIT(m) ((MWIMAGEBITS) ((m) << 1))
|
||||
typedef unsigned short bitmap_t; /* bitmap image unit size*/
|
||||
|
||||
typedef unsigned short MWIMAGEBITS; /* bitmap image unit size*/
|
||||
/* bitmap_t helper macros*/
|
||||
#define BITMAP_WORDS(x) (((x)+15)/16) /* image size in words*/
|
||||
#define BITMAP_BYTES(x) (BITMAP_WORDS(x)*sizeof(bitmap_t))
|
||||
#define BITMAP_BITSPERIMAGE (sizeof(bitmap_t) * 8)
|
||||
#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))
|
||||
|
||||
/* builtin C-based proportional/fixed font structure */
|
||||
/* based on The Microwindows Project http://microwindows.org */
|
||||
typedef struct {
|
||||
struct font {
|
||||
char * name; /* font name*/
|
||||
int maxwidth; /* max width in pixels*/
|
||||
unsigned int height; /* height in pixels*/
|
||||
int ascent; /* ascent (baseline) height*/
|
||||
int firstchar; /* first character in bitmap*/
|
||||
int size; /* font size in glyphs*/
|
||||
MWIMAGEBITS *bits; /* 16-bit right-padded bitmap data*/
|
||||
bitmap_t *bits; /* 16-bit right-padded bitmap data*/
|
||||
unsigned long *offset; /* offsets into bitmap data*/
|
||||
unsigned char *width; /* character widths or NULL if fixed*/
|
||||
int defaultchar; /* default char (not glyph index)*/
|
||||
long bits_size; /* # words of MWIMAGEBITS bits*/
|
||||
#if 0
|
||||
char * facename; /* facename of font*/
|
||||
char * copyright; /* copyright info for loadable fonts*/
|
||||
#endif
|
||||
} MWCFONT, *PMWCFONT;
|
||||
|
||||
/* structure for rockbox startup font selection*/
|
||||
struct corefont {
|
||||
PMWCFONT pf; /* compiled-in or loaded font*/
|
||||
char *diskname; /* diskname if not compiled-in*/
|
||||
long bits_size; /* # words of bitmap_t bits*/
|
||||
};
|
||||
|
||||
extern struct corefont sysfonts[MAXFONTS];
|
||||
|
||||
/* font routines*/
|
||||
PMWCFONT getfont(int font);
|
||||
PMWCFONT rbf_load_font(char *path, PMWCFONT pf);
|
||||
|
||||
void font_init(void);
|
||||
struct font* font_load(char *path);
|
||||
struct font* font_get(int font);
|
||||
|
||||
#else /* HAVE_LCD_BITMAP */
|
||||
|
||||
#define font_init()
|
||||
#define font_load(x)
|
||||
|
||||
#endif
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,212 +0,0 @@
|
|||
/***************************************************************************
|
||||
* __________ __ ___.
|
||||
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
||||
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
||||
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
||||
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
||||
* \/ \/ \/ \/ \/
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (c) 2002 by Greg Haerr <greg@censoft.com>
|
||||
*
|
||||
* All files in this archive are subject to the GNU General Public License.
|
||||
* See the file COPYING in the source tree root for full license agreement.
|
||||
*
|
||||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
* KIND, either express or implied.
|
||||
*
|
||||
****************************************************************************/
|
||||
/*
|
||||
* Load an rbf font, store in incore format.
|
||||
*/
|
||||
#include "config.h"
|
||||
|
||||
#if defined(HAVE_LCD_BITMAP) || defined(SIMULATOR)
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "font.h"
|
||||
#include "file.h"
|
||||
|
||||
#ifndef DEBUGF
|
||||
#include "debug.h"
|
||||
#endif
|
||||
|
||||
#ifndef O_BINARY
|
||||
#define O_BINARY 0
|
||||
#endif
|
||||
|
||||
/* static buffer allocation structures*/
|
||||
static unsigned char mbuf[MAX_FONT_SIZE];
|
||||
static unsigned char *freeptr = mbuf;
|
||||
static unsigned char *fileptr;
|
||||
static unsigned char *eofptr;
|
||||
|
||||
static int
|
||||
READSHORT(unsigned short *sp)
|
||||
{
|
||||
unsigned short s;
|
||||
|
||||
s = *fileptr++ & 0xff;
|
||||
*sp = (*fileptr++ << 8) | s;
|
||||
return (fileptr <= eofptr);
|
||||
}
|
||||
|
||||
static int
|
||||
READLONG(unsigned long *lp)
|
||||
{
|
||||
unsigned long l;
|
||||
|
||||
l = *fileptr++ & 0xff;
|
||||
l |= *fileptr++ << 8;
|
||||
l |= *fileptr++ << 16;
|
||||
*lp = (*fileptr++ << 24) | l;
|
||||
return (fileptr <= eofptr);
|
||||
}
|
||||
|
||||
/* read count bytes*/
|
||||
static int
|
||||
READSTR(char *buf, int count)
|
||||
{
|
||||
int n = count;
|
||||
|
||||
while (--n >= 0)
|
||||
*buf++ = *fileptr++;
|
||||
return (fileptr <= eofptr)? count: 0;
|
||||
}
|
||||
|
||||
/* read totlen bytes, return NUL terminated string*/
|
||||
/* may write 1 past buf[totlen]; removes blank pad*/
|
||||
static int
|
||||
READSTRPAD(char *buf, int totlen)
|
||||
{
|
||||
char *p = buf;
|
||||
int n = totlen;
|
||||
|
||||
while (--n >= 0)
|
||||
*p++ = *fileptr++;
|
||||
if (fileptr > eofptr)
|
||||
return 0;
|
||||
|
||||
p = &buf[totlen];
|
||||
*p-- = 0;
|
||||
while (*p == ' ' && p >= buf)
|
||||
*p-- = '\0';
|
||||
return totlen;
|
||||
}
|
||||
|
||||
/* read and load font into incore font structure*/
|
||||
PMWCFONT
|
||||
rbf_load_font(char *path, PMWCFONT pf)
|
||||
{
|
||||
int fd, filesize;
|
||||
unsigned short maxwidth, height, ascent, pad;
|
||||
unsigned long firstchar, defaultchar, size;
|
||||
unsigned long i, nbits, noffset, nwidth;
|
||||
char version[4+1];
|
||||
char copyright[256+1];
|
||||
|
||||
memset(pf, 0, sizeof(MWCFONT));
|
||||
|
||||
/* open and read entire font file*/
|
||||
fd = open(path, O_RDONLY|O_BINARY);
|
||||
if (fd < 0) {
|
||||
DEBUGF("Can't open font: %s\n", path);
|
||||
return NULL;
|
||||
}
|
||||
freeptr = (unsigned char *)(((int)mbuf + 3) & ~3);
|
||||
fileptr = freeptr;
|
||||
filesize = read(fd, fileptr, MAX_FONT_SIZE);
|
||||
eofptr = fileptr + filesize;
|
||||
//freeptr += filesize;
|
||||
//freeptr = (unsigned char *)(freeptr + 3) & ~3; /* pad freeptr*/
|
||||
close(fd);
|
||||
if (filesize == MAX_FONT_SIZE) {
|
||||
DEBUGF("Font %s too large: %d\n", path, filesize);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* read magic and version #*/
|
||||
memset(version, 0, sizeof(version));
|
||||
if (READSTR(version, 4) != 4)
|
||||
return NULL;
|
||||
if (strcmp(version, VERSION) != 0)
|
||||
return NULL;
|
||||
|
||||
/* internal font name*/
|
||||
pf->name = fileptr;
|
||||
if (READSTRPAD(pf->name, 64) != 64)
|
||||
return NULL;
|
||||
|
||||
/* copyright, not currently stored*/
|
||||
if (READSTRPAD(copyright, 256) != 256)
|
||||
return NULL;
|
||||
|
||||
/* font info*/
|
||||
if (!READSHORT(&maxwidth))
|
||||
return NULL;
|
||||
pf->maxwidth = maxwidth;
|
||||
if (!READSHORT(&height))
|
||||
return NULL;
|
||||
pf->height = height;
|
||||
if (!READSHORT(&ascent))
|
||||
return NULL;
|
||||
pf->ascent = ascent;
|
||||
if (!READSHORT(&pad))
|
||||
return NULL;
|
||||
if (!READLONG(&firstchar))
|
||||
return NULL;
|
||||
pf->firstchar = firstchar;
|
||||
if (!READLONG(&defaultchar))
|
||||
return NULL;
|
||||
pf->defaultchar = defaultchar;
|
||||
if (!READLONG(&size))
|
||||
return NULL;
|
||||
pf->size = size;
|
||||
|
||||
/* get variable font data sizes*/
|
||||
/* # words of MWIMAGEBITS*/
|
||||
if (!READLONG(&nbits))
|
||||
return NULL;
|
||||
pf->bits_size = nbits;
|
||||
|
||||
/* # longs of offset*/
|
||||
if (!READLONG(&noffset))
|
||||
return NULL;
|
||||
|
||||
/* # bytes of width*/
|
||||
if (!READLONG(&nwidth))
|
||||
return NULL;
|
||||
|
||||
/* variable font data*/
|
||||
pf->bits = (MWIMAGEBITS *)fileptr;
|
||||
for (i=0; i<nbits; ++i)
|
||||
if (!READSHORT(&pf->bits[i]))
|
||||
return NULL;
|
||||
/* pad to longword boundary*/
|
||||
fileptr = (unsigned char *)(((int)fileptr + 3) & ~3);
|
||||
|
||||
if (noffset) {
|
||||
pf->offset = (unsigned long *)fileptr;
|
||||
for (i=0; i<noffset; ++i)
|
||||
if (!READLONG(&pf->offset[i]))
|
||||
return NULL;
|
||||
} else pf->offset = NULL;
|
||||
|
||||
if (nwidth) {
|
||||
pf->width = (unsigned char *)fileptr;
|
||||
fileptr += nwidth*sizeof(unsigned char);
|
||||
} else pf->width = NULL;
|
||||
|
||||
if (fileptr > eofptr)
|
||||
return NULL;
|
||||
return pf; /* success!*/
|
||||
}
|
||||
#endif /* HAVE_LCD_BITMAP */
|
||||
|
||||
/* -----------------------------------------------------------------
|
||||
* local variables:
|
||||
* eval: (load-file "rockbox-mode.el")
|
||||
* vim: et sw=4 ts=8 sts=4 tw=78
|
||||
* end:
|
||||
*/
|
217
tools/bdf2c
217
tools/bdf2c
|
@ -1,217 +0,0 @@
|
|||
#! /usr/bin/perl -w
|
||||
#
|
||||
# Convert BDF files to incore MWCFONT structure 'C' source
|
||||
# Copyright (c) 2002 by Greg Haerr <greg@censoft.com>
|
||||
#
|
||||
# from The Microwindows Project (http://microwindows.org)
|
||||
#
|
||||
# modified 09/13/02 correct output when no DEFAULT_CHAR, allow numeric font name
|
||||
# modified 09/12/02 added -limit <max_encode_hex_value> option
|
||||
# modified on 09/10/02 by G Haerr
|
||||
# - fixed DWIDTH 0 parsing
|
||||
# - don't limit font size to 0x7e characters
|
||||
# - changed offset data to unsigned long for large fonts
|
||||
# - don't generate width table if fixed-width
|
||||
# - added defaultchar to output
|
||||
# - added bits_size member for loadable fonts
|
||||
# modified on 3/26/00 by G Haerr added ascent field, fixed $IMAGE_BITS
|
||||
# modified on 2/10/00 by K Harris to accept any size input character
|
||||
# modified by G Haerr from bdftobogl for 16 bit MWIMAGEBITS
|
||||
# originally from BOGL - Ben's Own Graphics Library <pfaffben@debian.org>.
|
||||
|
||||
use POSIX;
|
||||
|
||||
$name = (reverse split /\//, $0)[0];
|
||||
$limit_char = 65535;
|
||||
|
||||
while (defined $ARGV[0]) {
|
||||
my $arg = shift;
|
||||
|
||||
if (($arg eq "-limit") && scalar(@ARGV) > 0) {
|
||||
$limit_char = hex shift;
|
||||
} elsif ($arg =~ "-.+") {
|
||||
print "$name: unknown option '$arg'\n";
|
||||
exit 1;
|
||||
} else {
|
||||
unshift(@ARGV, $arg);
|
||||
last;
|
||||
}
|
||||
}
|
||||
|
||||
if ($#ARGV < 0) {
|
||||
print "Usage: $name [-limit <max_encode_hex_value>] font.bdf > font.c\n";
|
||||
exit 1;
|
||||
}
|
||||
|
||||
$IMAGE_BITS = 16;
|
||||
$IMAGE_NIBBLES = $IMAGE_BITS/4;
|
||||
$IMAGE_MASK = 0xffff;
|
||||
|
||||
$file = $ARGV[0];
|
||||
|
||||
$font = $file;
|
||||
$font =~ s/\.bdf//;
|
||||
$font =~ tr/a-zA-Z0-9_/_/cs;
|
||||
|
||||
print "/* Generated by $name on ", substr(`date`, 0, -1), ". */\n";
|
||||
print "#include \"font.h\"\n\n";
|
||||
|
||||
open BDF, "<$file" || die;
|
||||
while (<BDF>) {
|
||||
chop;
|
||||
$pixel_size = $1 if /^PIXEL_SIZE (\d+)$/;
|
||||
$font_ascent = $1 if /^FONT_ASCENT (\d+)$/;
|
||||
$font_descent = $1 if /^FONT_DESCENT (\d+)$/;
|
||||
$font_name = $1 if /^FONT (.*)$/;
|
||||
$default_char = $1 if /^DEFAULT_CHAR (\d+)$/;
|
||||
($fbbw, $fbbh, $fbbx, $fbby) = ($1, $2, $3, $4) if /^FONTBOUNDINGBOX (-?\d+) (-?\d+) (-?\d+) (-?\d+)/;
|
||||
|
||||
last if /^CHARS /;
|
||||
}
|
||||
|
||||
$font_width = $fbbw - $fbbx;
|
||||
undef $fbbw, undef $fbbh, undef $fbbx, undef $fbby;
|
||||
|
||||
print "/* Font information:\n\n";
|
||||
print " name: $font_name\n";
|
||||
print " pixel size: $pixel_size\n" if defined $pixel_size;
|
||||
print " ascent: $font_ascent\n";
|
||||
print " descent: $font_descent\n";
|
||||
print "*/\n\n";
|
||||
|
||||
print "/* Font character bitmap data. */\n";
|
||||
print "static MWIMAGEBITS _${font}_bits[] = {\n";
|
||||
|
||||
$ch_height = $font_ascent + $font_descent;
|
||||
$ofs = 0;
|
||||
$maxwidth = 0;
|
||||
$firstchar = -1;
|
||||
$lastchar = -1;
|
||||
while (<BDF>) {
|
||||
chop;
|
||||
undef $encoding, undef $width, undef $bbx, undef $bby, undef $bbw, undef $bbh if /^STARTCHAR /;
|
||||
$encoding = $1 if /^ENCODING (\d+)/;
|
||||
last if defined $encoding && $encoding > $limit_char;
|
||||
$width = $1 if /^DWIDTH (-?\d+)/;
|
||||
$width = $font_width if defined $width && $width <= 0;
|
||||
($bbw, $bbh, $bbx, $bby) = ($1, $2, $3, $4) if /^BBX (-?\d+) (-?\d+) (-?\d+) (-?\d+)/;
|
||||
|
||||
if (/^BITMAP$/) {
|
||||
next if !defined $encoding;
|
||||
$firstchar = $encoding if $firstchar < 0;
|
||||
$lastchar = $encoding if $lastchar < $encoding;
|
||||
$encoding_tab[$encoding] = $ofs;
|
||||
$width -= $bbx, $bbx = 0 if $bbx < 0;
|
||||
$width[$encoding] = $width;
|
||||
$maxwidth = $width if $width > $maxwidth;
|
||||
$ch_words = int (($width+$IMAGE_BITS-1)/$IMAGE_BITS);
|
||||
$ch_bits = $ch_words*$IMAGE_BITS;
|
||||
for (my $i = 0; $i < $ch_height; $i++) {
|
||||
for (my $k = 0; $k < $ch_words; $k++) {
|
||||
$bm[$i][$k] = 0;
|
||||
}
|
||||
}
|
||||
for (my $i = 0; ; $i++) {
|
||||
$_ = <BDF>;
|
||||
chop;
|
||||
last if /^ENDCHAR$/;
|
||||
|
||||
@hexnibbles = split //,$_;
|
||||
for (my $k=0; $k<$ch_words; $k++) {
|
||||
$ndx = $k*$IMAGE_NIBBLES;
|
||||
$padnibbles = @hexnibbles - $ndx;
|
||||
last if $padnibbles <= 0; # if bbx pushes bits into next word
|
||||
# and no more bits from bdf file
|
||||
$padnibbles = 0 if $padnibbles >= $IMAGE_NIBBLES;
|
||||
$value = hex join '',@hexnibbles[$ndx..($ndx+$IMAGE_NIBBLES-1-$padnibbles)];
|
||||
$value = $value << ($padnibbles*$IMAGE_NIBBLES);
|
||||
$bm[$ch_height - $font_descent - $bby - $bbh + $i][$k] |=
|
||||
$value >> ($bbx);
|
||||
if ($bbx) { # handle overflow into next image_word
|
||||
$bm[$ch_height - $font_descent - $bby - $bbh + $i][$k+1] =
|
||||
($value << ($IMAGE_BITS - $bbx)) & $IMAGE_MASK;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
### printf "\n/* Character %c (0x%02x):\n", $encoding, $encoding;
|
||||
printf "\n/* Character (0x%02x):\n", $encoding;
|
||||
print " bbw=$bbw, bbh=$bbh, bbx=$bbx, bby=$bby, width=$width\n";
|
||||
print " +", ("-" x $ch_bits), "+\n";
|
||||
for (my $i = 0; $i < $ch_height; $i++) {
|
||||
print " |";
|
||||
for (my $k = 0; $k < $ch_words; $k++) {
|
||||
for (my $j = $IMAGE_BITS - 1; $j >= 0; $j--) {
|
||||
print $bm[$i][$k] & (1 << $j) ? "*" : " ";
|
||||
}
|
||||
}
|
||||
print "|\n";
|
||||
}
|
||||
print " +", ("-" x $ch_bits), "+ */\n";
|
||||
|
||||
for (my $i = 0; $i < $ch_height; $i++) {
|
||||
for ($k=0; $k<$ch_words; $k++) {
|
||||
$ofs++;
|
||||
printf "0x%04x, ", $bm[$i][$k];
|
||||
}
|
||||
printf "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
print "};\n\n";
|
||||
|
||||
##print STDERR "Maximum character width=$maxwidth\n";
|
||||
|
||||
$default_char = $firstchar if !defined $default_char;
|
||||
|
||||
print "/* Character->glyph mapping. */\n";
|
||||
print "static unsigned long _${font}_offset[] = {\n";
|
||||
for (my $i = $firstchar; $i <= $lastchar; $i++) {
|
||||
my $char = $i;
|
||||
my $ofs = $encoding_tab[$i];
|
||||
$ofs = $encoding_tab[$default_char], $char = $default_char if !defined $ofs;
|
||||
### printf " $ofs,\t/* %c (0x%02x) */\n", $char, $i;
|
||||
printf " $ofs,\t/* (0x%02x) */\n", $i;
|
||||
}
|
||||
print "};\n\n";
|
||||
|
||||
$gen_width_table = 0;
|
||||
for (my $i = $firstchar; $i <= $lastchar; $i++) {
|
||||
my $char = $i;
|
||||
my $width = $width[$i];
|
||||
$width = $width[$default_char] if !defined $encoding_tab[$i];
|
||||
$gen_width_table = 1 if $width != $maxwidth
|
||||
}
|
||||
|
||||
if ($gen_width_table) {
|
||||
print "/* Character width data. */\n";
|
||||
print "static unsigned char _${font}_width[] = {\n";
|
||||
for (my $i = $firstchar; $i <= $lastchar; $i++) {
|
||||
my $char = $i;
|
||||
my $width = $width[$i];
|
||||
$width = $width[$default_char], $char = $default_char if !defined $encoding_tab[$i];
|
||||
### printf " $width,\t/* %c (0x%02x) */\n", $char, $i;
|
||||
printf " $width,\t/* (0x%02x) */\n", $i;
|
||||
}
|
||||
print "};\n\n";
|
||||
}
|
||||
|
||||
$size = $lastchar - $firstchar + 1;
|
||||
|
||||
print "/* Exported structure definition. */\n";
|
||||
print "MWCFONT font_${font} = {\n";
|
||||
print " \"$font\",\n";
|
||||
print " $maxwidth,\n";
|
||||
print " $ch_height,\n";
|
||||
print " $font_ascent,\n";
|
||||
print " $firstchar,\n";
|
||||
print " $size,\n";
|
||||
print " _${font}_bits,\n";
|
||||
print " _${font}_offset,\n";
|
||||
if ($gen_width_table) {
|
||||
print " _${font}_width,\n";
|
||||
} else { print " 0, /* fixed width*/\n"; }
|
||||
print " $default_char,\n";
|
||||
print " sizeof(_${font}_bits)/sizeof(MWIMAGEBITS),\n";
|
||||
print "};\n";
|
|
@ -1,39 +0,0 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# bdf2fnt - shell script to convert a BDF file to RBF format
|
||||
#
|
||||
# usage: bdf2fnt bdffile (don't use .bdf extension!)
|
||||
#
|
||||
# Example: bdf2fnt courB08
|
||||
# creates ./courB08.fnt and /tmp/courB08.c
|
||||
# the .fnt file can be renamed /system.fnt for loading
|
||||
# the .c file can be moved to firmware dir to compile-in font
|
||||
#
|
||||
|
||||
# convert from bdf to C source
|
||||
./bdf2c $1.bdf > /tmp/$1.c
|
||||
|
||||
# compile writerbf with linked C source font
|
||||
gcc -DARCHOS_RECORDER -DFONT=font_$1 -I../firmware -I../firmware/common -o /tmp/writerbf writerbf.c /tmp/$1.c
|
||||
|
||||
# run writerbf, will write linked incore font to .rbf format
|
||||
/tmp/writerbf
|
||||
rm /tmp/writerbf
|
||||
|
||||
# load .rbf font and display it for test
|
||||
gcc -DARCHOS_RECORDER -DMAX_FONT_SIZE=500000 -I../firmware/common -o /tmp/loadrbf loadrbf.c
|
||||
/tmp/loadrbf $1.fnt > /tmp/$1.1
|
||||
rm /tmp/loadrbf
|
||||
|
||||
# link .c font and diff with .fnt load for test
|
||||
gcc -DARCHOS_RECORDER -DFONT=font_$1 -I../firmware -I../firmware/common -o /tmp/loadrbf loadrbf.c /tmp/$1.c
|
||||
/tmp/loadrbf > /tmp/$1.2
|
||||
rm /tmp/loadrbf
|
||||
|
||||
#
|
||||
# we diff the output to ensure correctness
|
||||
diff /tmp/$1.1 /tmp/$1.2
|
||||
|
||||
# clean up
|
||||
rm /tmp/$1.1 /tmp/$1.2
|
||||
#rm /tmp/$1.c
|
287
tools/convbdf.c
287
tools/convbdf.c
|
@ -16,31 +16,31 @@
|
|||
/* loadable font magic and version #*/
|
||||
#define VERSION "RB11"
|
||||
|
||||
/* MWIMAGEBITS helper macros*/
|
||||
#define MWIMAGE_WORDS(x) (((x)+15)/16) /* image size in words*/
|
||||
#define MWIMAGE_BYTES(x) (MWIMAGE_WORDS(x)*sizeof(MWIMAGEBITS))
|
||||
#define MWIMAGE_BITSPERIMAGE (sizeof(MWIMAGEBITS) * 8)
|
||||
#define MWIMAGE_BITVALUE(n) ((MWIMAGEBITS) (((MWIMAGEBITS) 1) << (n)))
|
||||
#define MWIMAGE_FIRSTBIT (MWIMAGE_BITVALUE(MWIMAGE_BITSPERIMAGE - 1))
|
||||
#define MWIMAGE_TESTBIT(m) ((m) & MWIMAGE_FIRSTBIT)
|
||||
#define MWIMAGE_SHIFTBIT(m) ((MWIMAGEBITS) ((m) << 1))
|
||||
/* bitmap_t helper macros*/
|
||||
#define BITMAP_WORDS(x) (((x)+15)/16) /* image size in words*/
|
||||
#define BITMAP_BYTES(x) (BITMAP_WORDS(x)*sizeof(bitmap_t))
|
||||
#define BITMAP_BITSPERIMAGE (sizeof(bitmap_t) * 8)
|
||||
#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))
|
||||
|
||||
typedef unsigned short MWIMAGEBITS; /* bitmap image unit size*/
|
||||
typedef unsigned short bitmap_t; /* bitmap image unit size*/
|
||||
|
||||
/* builtin C-based proportional/fixed font structure */
|
||||
/* based on The Microwindows Project http://microwindows.org */
|
||||
typedef struct {
|
||||
struct font {
|
||||
char * name; /* font name*/
|
||||
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*/
|
||||
MWIMAGEBITS * bits; /* 16-bit right-padded bitmap data*/
|
||||
unsigned long * offset; /* offsets into bitmap data*/
|
||||
unsigned char * width; /* character widths or NULL if fixed*/
|
||||
bitmap_t* bits; /* 16-bit right-padded bitmap data*/
|
||||
unsigned long* offset; /* offsets into bitmap data*/
|
||||
unsigned char* width; /* character widths or NULL if fixed*/
|
||||
int defaultchar; /* default char (not glyph index)*/
|
||||
long bits_size; /* # words of MWIMAGEBITS bits*/
|
||||
long bits_size; /* # words of bitmap_t bits*/
|
||||
|
||||
/* unused by runtime system, read in by convbdf*/
|
||||
char * facename; /* facename of font*/
|
||||
|
@ -48,7 +48,7 @@ typedef struct {
|
|||
int pixel_size;
|
||||
int descent;
|
||||
int fbbw, fbbh, fbbx, fbby;
|
||||
} MWCFONT, *PMWCFONT;
|
||||
};
|
||||
/* END font.h*/
|
||||
|
||||
#define isprefix(buf,str) (!strncmp(buf, str, strlen(str)))
|
||||
|
@ -64,19 +64,19 @@ int limit_char = 65535;
|
|||
int oflag = 0;
|
||||
char outfile[256];
|
||||
|
||||
void usage(void);
|
||||
void getopts(int *pac, char ***pav);
|
||||
int convbdf(char *path);
|
||||
void usage(void);
|
||||
void getopts(int *pac, char ***pav);
|
||||
int convbdf(char *path);
|
||||
|
||||
void free_font(PMWCFONT pf);
|
||||
PMWCFONT bdf_read_font(char *path);
|
||||
int bdf_read_header(FILE *fp, PMWCFONT pf);
|
||||
int bdf_read_bitmaps(FILE *fp, PMWCFONT pf);
|
||||
char * bdf_getline(FILE *fp, char *buf, int len);
|
||||
MWIMAGEBITS bdf_hexval(unsigned char *buf, int ndx1, int ndx2);
|
||||
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);
|
||||
char * bdf_getline(FILE *fp, char *buf, int len);
|
||||
bitmap_t bdf_hexval(unsigned char *buf, int ndx1, int ndx2);
|
||||
|
||||
int gen_c_source(PMWCFONT pf, char *path);
|
||||
int gen_fnt_file(PMWCFONT pf, char *path);
|
||||
int gen_c_source(struct font* pf, char *path);
|
||||
int gen_fnt_file(struct font* pf, char *path);
|
||||
|
||||
void
|
||||
usage(void)
|
||||
|
@ -96,8 +96,7 @@ usage(void)
|
|||
}
|
||||
|
||||
/* parse command line options*/
|
||||
void
|
||||
getopts(int *pac, char ***pav)
|
||||
void getopts(int *pac, char ***pav)
|
||||
{
|
||||
char *p;
|
||||
char **av;
|
||||
|
@ -171,8 +170,7 @@ getopts(int *pac, char ***pav)
|
|||
}
|
||||
|
||||
/* remove directory prefix and file suffix from full path*/
|
||||
char *
|
||||
basename(char *path)
|
||||
char *basename(char *path)
|
||||
{
|
||||
char *p, *b;
|
||||
static char base[256];
|
||||
|
@ -193,10 +191,9 @@ basename(char *path)
|
|||
return base;
|
||||
}
|
||||
|
||||
int
|
||||
convbdf(char *path)
|
||||
int convbdf(char *path)
|
||||
{
|
||||
PMWCFONT pf;
|
||||
struct font* pf;
|
||||
int ret = 0;
|
||||
|
||||
pf = bdf_read_font(path);
|
||||
|
@ -223,8 +220,7 @@ convbdf(char *path)
|
|||
return ret;
|
||||
}
|
||||
|
||||
int
|
||||
main(int ac, char **av)
|
||||
int main(int ac, char **av)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
|
@ -251,8 +247,7 @@ main(int ac, char **av)
|
|||
}
|
||||
|
||||
/* free font structure*/
|
||||
void
|
||||
free_font(PMWCFONT pf)
|
||||
void free_font(struct font* pf)
|
||||
{
|
||||
if (!pf)
|
||||
return;
|
||||
|
@ -270,11 +265,10 @@ free_font(PMWCFONT pf)
|
|||
}
|
||||
|
||||
/* build incore structure from .bdf file*/
|
||||
PMWCFONT
|
||||
bdf_read_font(char *path)
|
||||
struct font* bdf_read_font(char *path)
|
||||
{
|
||||
FILE *fp;
|
||||
PMWCFONT pf;
|
||||
struct font* pf;
|
||||
|
||||
fp = fopen(path, "rb");
|
||||
if (!fp) {
|
||||
|
@ -282,7 +276,7 @@ bdf_read_font(char *path)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
pf = (PMWCFONT)calloc(1, sizeof(MWCFONT));
|
||||
pf = (struct font*)calloc(1, sizeof(struct font));
|
||||
if (!pf)
|
||||
goto errout;
|
||||
|
||||
|
@ -308,8 +302,7 @@ bdf_read_font(char *path)
|
|||
}
|
||||
|
||||
/* read bdf font header information, return 0 on error*/
|
||||
int
|
||||
bdf_read_header(FILE *fp, PMWCFONT pf)
|
||||
int bdf_read_header(FILE *fp, struct font* pf)
|
||||
{
|
||||
int encoding;
|
||||
int nchars, maxwidth;
|
||||
|
@ -391,7 +384,10 @@ bdf_read_header(FILE *fp, PMWCFONT pf)
|
|||
fprintf(stderr, "Error: bad 'ENCODING'\n");
|
||||
return 0;
|
||||
}
|
||||
if (encoding >= 0 && encoding <= limit_char && encoding >= start_char) {
|
||||
if (encoding >= 0 &&
|
||||
encoding <= limit_char &&
|
||||
encoding >= start_char) {
|
||||
|
||||
if (firstchar > encoding)
|
||||
firstchar = encoding;
|
||||
if (lastchar < encoding)
|
||||
|
@ -411,7 +407,9 @@ bdf_read_header(FILE *fp, PMWCFONT pf)
|
|||
pf->height = pf->ascent + pf->descent;
|
||||
|
||||
/* calc default char*/
|
||||
if (pf->defaultchar < 0 || pf->defaultchar < firstchar)
|
||||
if (pf->defaultchar < 0 ||
|
||||
pf->defaultchar < firstchar ||
|
||||
pf->defaultchar > limit_char )
|
||||
pf->defaultchar = firstchar;
|
||||
|
||||
/* calc font size (offset/width entries)*/
|
||||
|
@ -423,10 +421,10 @@ bdf_read_header(FILE *fp, PMWCFONT pf)
|
|||
maxwidth = pf->fbbw;
|
||||
|
||||
/* initially use font maxwidth * height for bits allocation*/
|
||||
pf->bits_size = nchars * MWIMAGE_WORDS(maxwidth) * pf->height;
|
||||
pf->bits_size = nchars * BITMAP_WORDS(maxwidth) * pf->height;
|
||||
|
||||
/* allocate bits, offset, and width arrays*/
|
||||
pf->bits = (MWIMAGEBITS *)malloc(pf->bits_size * sizeof(MWIMAGEBITS) + EXTRA);
|
||||
pf->bits = (bitmap_t *)malloc(pf->bits_size * sizeof(bitmap_t) + EXTRA);
|
||||
pf->offset = (unsigned long *)malloc(pf->size * sizeof(unsigned long));
|
||||
pf->width = (unsigned char *)malloc(pf->size * sizeof(unsigned char));
|
||||
|
||||
|
@ -439,8 +437,7 @@ bdf_read_header(FILE *fp, PMWCFONT pf)
|
|||
}
|
||||
|
||||
/* read bdf font bitmaps, return 0 on error*/
|
||||
int
|
||||
bdf_read_bitmaps(FILE *fp, PMWCFONT pf)
|
||||
int bdf_read_bitmaps(FILE *fp, struct font* pf)
|
||||
{
|
||||
long ofs = 0;
|
||||
int maxwidth = 0;
|
||||
|
@ -494,7 +491,7 @@ bdf_read_bitmaps(FILE *fp, PMWCFONT pf)
|
|||
continue;
|
||||
}
|
||||
if (strequal(buf, "BITMAP")) {
|
||||
MWIMAGEBITS *ch_bitmap = pf->bits + ofs;
|
||||
bitmap_t *ch_bitmap = pf->bits + ofs;
|
||||
int ch_words;
|
||||
|
||||
if (encoding < 0)
|
||||
|
@ -520,11 +517,11 @@ bdf_read_bitmaps(FILE *fp, PMWCFONT pf)
|
|||
pf->width[encoding-pf->firstchar] = width;
|
||||
|
||||
/* clear bitmap*/
|
||||
memset(ch_bitmap, 0, MWIMAGE_BYTES(width) * pf->height);
|
||||
memset(ch_bitmap, 0, BITMAP_BYTES(width) * pf->height);
|
||||
|
||||
ch_words = MWIMAGE_WORDS(width);
|
||||
ch_words = BITMAP_WORDS(width);
|
||||
#define BM(row,col) (*(ch_bitmap + ((row)*ch_words) + (col)))
|
||||
#define MWIMAGE_NIBBLES (MWIMAGE_BITSPERIMAGE/4)
|
||||
#define BITMAP_NIBBLES (BITMAP_BITSPERIMAGE/4)
|
||||
|
||||
/* read bitmaps*/
|
||||
for (i=0; ; ++i) {
|
||||
|
@ -539,30 +536,30 @@ bdf_read_bitmaps(FILE *fp, PMWCFONT pf)
|
|||
|
||||
hexnibbles = strlen(buf);
|
||||
for (k=0; k<ch_words; ++k) {
|
||||
int ndx = k * MWIMAGE_NIBBLES;
|
||||
int ndx = k * BITMAP_NIBBLES;
|
||||
int padnibbles = hexnibbles - ndx;
|
||||
MWIMAGEBITS value;
|
||||
bitmap_t value;
|
||||
|
||||
if (padnibbles <= 0)
|
||||
break;
|
||||
if (padnibbles >= MWIMAGE_NIBBLES)
|
||||
if (padnibbles >= BITMAP_NIBBLES)
|
||||
padnibbles = 0;
|
||||
|
||||
value = bdf_hexval((unsigned char *)buf,
|
||||
ndx, ndx+MWIMAGE_NIBBLES-1-padnibbles);
|
||||
value <<= padnibbles * MWIMAGE_NIBBLES;
|
||||
ndx, ndx+BITMAP_NIBBLES-1-padnibbles);
|
||||
value <<= padnibbles * BITMAP_NIBBLES;
|
||||
|
||||
BM(pf->height - pf->descent - bby - bbh + i, k) |=
|
||||
value >> bbx;
|
||||
/* handle overflow into next image word*/
|
||||
if (bbx) {
|
||||
BM(pf->height - pf->descent - bby - bbh + i, k+1) =
|
||||
value << (MWIMAGE_BITSPERIMAGE - bbx);
|
||||
value << (BITMAP_BITSPERIMAGE - bbx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ofs += MWIMAGE_WORDS(width) * pf->height;
|
||||
ofs += BITMAP_WORDS(width) * pf->height;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
@ -590,7 +587,7 @@ bdf_read_bitmaps(FILE *fp, PMWCFONT pf)
|
|||
encodetable = 1;
|
||||
break;
|
||||
}
|
||||
l += MWIMAGE_WORDS(pf->width[i]) * pf->height;
|
||||
l += BITMAP_WORDS(pf->width[i]) * pf->height;
|
||||
}
|
||||
if (!encodetable) {
|
||||
free(pf->offset);
|
||||
|
@ -611,23 +608,25 @@ bdf_read_bitmaps(FILE *fp, PMWCFONT pf)
|
|||
|
||||
/* reallocate bits array to actual bits used*/
|
||||
if (ofs < pf->bits_size) {
|
||||
pf->bits = realloc(pf->bits, ofs * sizeof(MWIMAGEBITS));
|
||||
pf->bits = realloc(pf->bits, ofs * sizeof(bitmap_t));
|
||||
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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
pf->bits_size = ofs;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* 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;
|
||||
char *b;
|
||||
|
@ -653,36 +652,37 @@ bdf_getline(FILE *fp, char *buf, int len)
|
|||
}
|
||||
|
||||
/* return hex value of portion of buffer*/
|
||||
MWIMAGEBITS
|
||||
bdf_hexval(unsigned char *buf, int ndx1, int ndx2)
|
||||
bitmap_t bdf_hexval(unsigned char *buf, int ndx1, int ndx2)
|
||||
{
|
||||
MWIMAGEBITS val = 0;
|
||||
bitmap_t val = 0;
|
||||
int i, c;
|
||||
|
||||
for (i=ndx1; i<=ndx2; ++i) {
|
||||
c = buf[i];
|
||||
if (c >= '0' && c <= '9')
|
||||
c -= '0';
|
||||
else if (c >= 'A' && c <= 'F')
|
||||
c = c - 'A' + 10;
|
||||
else if (c >= 'a' && c <= 'f')
|
||||
c = c - 'a' + 10;
|
||||
else c = 0;
|
||||
else
|
||||
if (c >= 'A' && c <= 'F')
|
||||
c = c - 'A' + 10;
|
||||
else
|
||||
if (c >= 'a' && c <= 'f')
|
||||
c = c - 'a' + 10;
|
||||
else
|
||||
c = 0;
|
||||
val = (val << 4) | c;
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
/* generate C source from in-core font*/
|
||||
int
|
||||
gen_c_source(PMWCFONT pf, char *path)
|
||||
int gen_c_source(struct font* pf, char *path)
|
||||
{
|
||||
FILE *ofp;
|
||||
int i;
|
||||
int did_defaultchar = 0;
|
||||
int did_syncmsg = 0;
|
||||
time_t t = time(0);
|
||||
MWIMAGEBITS *ofs = pf->bits;
|
||||
bitmap_t *ofs = pf->bits;
|
||||
char buf[256];
|
||||
char obuf[256];
|
||||
char hdr1[] = {
|
||||
|
@ -704,7 +704,7 @@ gen_c_source(PMWCFONT pf, char *path)
|
|||
"*/\n"
|
||||
"\n"
|
||||
"/* Font character bitmap data. */\n"
|
||||
"static MWIMAGEBITS _%s_bits[] = {\n"
|
||||
"static bitmap_t _font_bits[] = {\n"
|
||||
};
|
||||
|
||||
ofp = fopen(path, "w");
|
||||
|
@ -712,7 +712,6 @@ gen_c_source(PMWCFONT pf, char *path)
|
|||
fprintf(stderr, "Can't create %s\n", path);
|
||||
return 1;
|
||||
}
|
||||
fprintf(stderr, "Generating %s\n", path);
|
||||
|
||||
strcpy(buf, ctime(&t));
|
||||
buf[strlen(buf)-1] = 0;
|
||||
|
@ -727,8 +726,7 @@ gen_c_source(PMWCFONT pf, char *path)
|
|||
pf->firstchar+pf->size-1, pf->firstchar+pf->size-1,
|
||||
pf->defaultchar, pf->defaultchar,
|
||||
pf->width? "yes": "no",
|
||||
pf->copyright? pf->copyright: "",
|
||||
pf->name);
|
||||
pf->copyright? pf->copyright: "");
|
||||
|
||||
/* generate bitmaps*/
|
||||
for (i=0; i<pf->size; ++i) {
|
||||
|
@ -736,15 +734,16 @@ gen_c_source(PMWCFONT pf, char *path)
|
|||
int bitcount = 0;
|
||||
int width = pf->width ? pf->width[i] : pf->maxwidth;
|
||||
int height = pf->height;
|
||||
MWIMAGEBITS *bits = pf->bits + (pf->offset? pf->offset[i]: (height * i));
|
||||
MWIMAGEBITS bitvalue;
|
||||
bitmap_t *bits = pf->bits + (pf->offset? pf->offset[i]: (height * i));
|
||||
bitmap_t bitvalue;
|
||||
|
||||
/*
|
||||
* Generate bitmap bits only if not this index isn't
|
||||
* the default character in encode map, or the default
|
||||
* character hasn't been generated yet.
|
||||
*/
|
||||
if (pf->offset && (pf->offset[i] == pf->offset[pf->defaultchar-pf->firstchar])) {
|
||||
if (pf->offset &&
|
||||
(pf->offset[i] == pf->offset[pf->defaultchar-pf->firstchar])) {
|
||||
if (did_defaultchar)
|
||||
continue;
|
||||
did_defaultchar = 1;
|
||||
|
@ -763,13 +762,13 @@ gen_c_source(PMWCFONT pf, char *path)
|
|||
if (x == 0) fprintf(ofp, " |");
|
||||
|
||||
if (bitcount <= 0) {
|
||||
bitcount = MWIMAGE_BITSPERIMAGE;
|
||||
bitcount = BITMAP_BITSPERIMAGE;
|
||||
bitvalue = *bits++;
|
||||
}
|
||||
|
||||
fprintf(ofp, MWIMAGE_TESTBIT(bitvalue)? "*": " ");
|
||||
fprintf(ofp, BITMAP_TESTBIT(bitvalue)? "*": " ");
|
||||
|
||||
bitvalue = MWIMAGE_SHIFTBIT(bitvalue);
|
||||
bitvalue = BITMAP_SHIFTBIT(bitvalue);
|
||||
--bitcount;
|
||||
if (++x == width) {
|
||||
fprintf(ofp, "|\n");
|
||||
|
@ -779,13 +778,15 @@ gen_c_source(PMWCFONT pf, char *path)
|
|||
}
|
||||
}
|
||||
fprintf(ofp, " +");
|
||||
for (x=0; x<width; ++x) fprintf(ofp, "-");
|
||||
for (x=0; x<width; ++x)
|
||||
fprintf(ofp, "-");
|
||||
fprintf(ofp, "+ */\n");
|
||||
} else
|
||||
}
|
||||
else
|
||||
fprintf(ofp, " */\n");
|
||||
|
||||
bits = pf->bits + (pf->offset? pf->offset[i]: (pf->height * i));
|
||||
for (x=MWIMAGE_WORDS(width)*pf->height; x>0; --x) {
|
||||
for (x=BITMAP_WORDS(width)*pf->height; x>0; --x) {
|
||||
fprintf(ofp, "0x%04x,\n", *bits);
|
||||
if (!did_syncmsg && *bits++ != *ofs++) {
|
||||
fprintf(stderr, "Warning: found encoding values in non-sorted order (not an error).\n");
|
||||
|
@ -793,80 +794,79 @@ gen_c_source(PMWCFONT pf, char *path)
|
|||
}
|
||||
}
|
||||
}
|
||||
fprintf(ofp, "};\n\n");
|
||||
fprintf(ofp, "};\n\n");
|
||||
|
||||
if (pf->offset) {
|
||||
/* output offset table*/
|
||||
fprintf(ofp, "/* Character->glyph mapping. */\n"
|
||||
"static unsigned long _%s_offset[] = {\n",
|
||||
pf->name);
|
||||
"static unsigned long _sysfont_offset[] = {\n");
|
||||
|
||||
for (i=0; i<pf->size; ++i)
|
||||
fprintf(ofp, " %ld,\t/* (0x%02x) */\n", pf->offset[i], i+pf->firstchar);
|
||||
fprintf(ofp, " %ld,\t/* (0x%02x) */\n",
|
||||
pf->offset[i], i+pf->firstchar);
|
||||
fprintf(ofp, "};\n\n");
|
||||
}
|
||||
|
||||
/* output width table for proportional fonts*/
|
||||
if (pf->width) {
|
||||
fprintf(ofp, "/* Character width data. */\n"
|
||||
"static unsigned char _%s_width[] = {\n",
|
||||
pf->name);
|
||||
fprintf(ofp, "/* Character width data. */\n"
|
||||
"static unsigned char _sysfont_width[] = {\n");
|
||||
|
||||
for (i=0; i<pf->size; ++i)
|
||||
fprintf(ofp, " %d,\t/* (0x%02x) */\n", pf->width[i], i+pf->firstchar);
|
||||
fprintf(ofp, " %d,\t/* (0x%02x) */\n",
|
||||
pf->width[i], i+pf->firstchar);
|
||||
fprintf(ofp, "};\n\n");
|
||||
}
|
||||
|
||||
/* output MWCFONT struct*/
|
||||
/* output struct font struct*/
|
||||
if (pf->offset)
|
||||
sprintf(obuf, "_%s_offset,", pf->name);
|
||||
else sprintf(obuf, "0, /* no encode table*/");
|
||||
sprintf(obuf, "_sysfont_offset,");
|
||||
else
|
||||
sprintf(obuf, "0, /* no encode table*/");
|
||||
|
||||
if (pf->width)
|
||||
sprintf(buf, "_%s_width,", pf->name);
|
||||
else sprintf(buf, "0, /* fixed width*/");
|
||||
sprintf(buf, "_sysfont_width,");
|
||||
else
|
||||
sprintf(buf, "0, /* fixed width*/");
|
||||
|
||||
fprintf(ofp, "/* Exported structure definition. */\n"
|
||||
"MWCFONT font_%s = {\n"
|
||||
"struct font sysfont = {\n"
|
||||
" \"%s\",\n"
|
||||
" %d,\n"
|
||||
" %d,\n"
|
||||
" %d,\n"
|
||||
" %d,\n"
|
||||
" %d,\n"
|
||||
" _%s_bits,\n"
|
||||
" _font_bits,\n"
|
||||
" %s\n"
|
||||
" %s\n"
|
||||
" %d,\n"
|
||||
" sizeof(_%s_bits)/sizeof(MWIMAGEBITS),\n"
|
||||
" sizeof(_font_bits)/sizeof(bitmap_t),\n"
|
||||
"};\n",
|
||||
pf->name, pf->name,
|
||||
pf->name,
|
||||
pf->maxwidth, pf->height,
|
||||
pf->ascent,
|
||||
pf->firstchar,
|
||||
pf->size,
|
||||
pf->name,
|
||||
obuf,
|
||||
buf,
|
||||
pf->defaultchar,
|
||||
pf->name);
|
||||
pf->defaultchar);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
WRITEBYTE(FILE *fp, unsigned char c)
|
||||
static int writebyte(FILE *fp, unsigned char c)
|
||||
{
|
||||
return putc(c, fp) != EOF;
|
||||
}
|
||||
|
||||
static int
|
||||
WRITESHORT(FILE *fp, unsigned short s)
|
||||
static int writeshort(FILE *fp, unsigned short s)
|
||||
{
|
||||
putc(s, fp);
|
||||
return putc(s>>8, fp) != EOF;
|
||||
}
|
||||
|
||||
static int
|
||||
WRITELONG(FILE *fp, unsigned long l)
|
||||
static int writelong(FILE *fp, unsigned long l)
|
||||
{
|
||||
putc(l, fp);
|
||||
putc(l>>8, fp);
|
||||
|
@ -874,30 +874,28 @@ WRITELONG(FILE *fp, unsigned long l)
|
|||
return putc(l>>24, fp) != EOF;
|
||||
}
|
||||
|
||||
static int
|
||||
WRITESTR(FILE *fp, char *str, int count)
|
||||
static int writestr(FILE *fp, char *str, int count)
|
||||
{
|
||||
return fwrite(str, 1, count, fp) == count;
|
||||
}
|
||||
|
||||
static int
|
||||
WRITESTRPAD(FILE *fp, char *str, int totlen)
|
||||
static int writestrpad(FILE *fp, char *str, int totlen)
|
||||
{
|
||||
int ret;
|
||||
|
||||
while (str && *str && totlen > 0)
|
||||
while (str && *str && totlen > 0) {
|
||||
if (*str) {
|
||||
ret = putc(*str++, fp);
|
||||
--totlen;
|
||||
}
|
||||
}
|
||||
while (--totlen >= 0)
|
||||
ret = putc(' ', fp);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* generate .fnt format file from in-core font*/
|
||||
int
|
||||
gen_fnt_file(PMWCFONT pf, char *path)
|
||||
int gen_fnt_file(struct font* pf, char *path)
|
||||
{
|
||||
FILE *ofp;
|
||||
int i;
|
||||
|
@ -907,44 +905,43 @@ gen_fnt_file(PMWCFONT pf, char *path)
|
|||
fprintf(stderr, "Can't create %s\n", path);
|
||||
return 1;
|
||||
}
|
||||
fprintf(stderr, "Generating %s\n", path);
|
||||
|
||||
/* write magic and version #*/
|
||||
WRITESTR(ofp, VERSION, 4);
|
||||
writestr(ofp, VERSION, 4);
|
||||
|
||||
/* internal font name*/
|
||||
WRITESTRPAD(ofp, pf->name, 64);
|
||||
writestrpad(ofp, pf->name, 64);
|
||||
|
||||
/* copyright*/
|
||||
WRITESTRPAD(ofp, pf->copyright, 256);
|
||||
writestrpad(ofp, pf->copyright, 256);
|
||||
|
||||
/* font info*/
|
||||
WRITESHORT(ofp, pf->maxwidth);
|
||||
WRITESHORT(ofp, pf->height);
|
||||
WRITESHORT(ofp, pf->ascent);
|
||||
WRITESHORT(ofp, 0);
|
||||
WRITELONG(ofp, pf->firstchar);
|
||||
WRITELONG(ofp, pf->defaultchar);
|
||||
WRITELONG(ofp, pf->size);
|
||||
writeshort(ofp, pf->maxwidth);
|
||||
writeshort(ofp, pf->height);
|
||||
writeshort(ofp, pf->ascent);
|
||||
writeshort(ofp, 0);
|
||||
writelong(ofp, pf->firstchar);
|
||||
writelong(ofp, pf->defaultchar);
|
||||
writelong(ofp, pf->size);
|
||||
|
||||
/* variable font data sizes*/
|
||||
WRITELONG(ofp, pf->bits_size); /* # words of MWIMAGEBITS*/
|
||||
WRITELONG(ofp, pf->offset? pf->size: 0); /* # longs of offset*/
|
||||
WRITELONG(ofp, pf->width? pf->size: 0); /* # bytes of width*/
|
||||
writelong(ofp, pf->bits_size); /* # words of bitmap_t*/
|
||||
writelong(ofp, pf->offset? pf->size: 0); /* # longs of offset*/
|
||||
writelong(ofp, pf->width? pf->size: 0); /* # bytes of width*/
|
||||
|
||||
/* variable font data*/
|
||||
for (i=0; i<pf->bits_size; ++i)
|
||||
WRITESHORT(ofp, pf->bits[i]);
|
||||
writeshort(ofp, pf->bits[i]);
|
||||
if (ftell(ofp) & 2)
|
||||
WRITESHORT(ofp, 0); /* pad to 32-bit boundary*/
|
||||
writeshort(ofp, 0); /* pad to 32-bit boundary*/
|
||||
|
||||
if (pf->offset)
|
||||
for (i=0; i<pf->size; ++i)
|
||||
WRITELONG(ofp, pf->offset[i]);
|
||||
writelong(ofp, pf->offset[i]);
|
||||
|
||||
if (pf->width)
|
||||
for (i=0; i<pf->size; ++i)
|
||||
WRITEBYTE(ofp, pf->width[i]);
|
||||
writebyte(ofp, pf->width[i]);
|
||||
|
||||
fclose(ofp);
|
||||
return 0;
|
||||
|
|
|
@ -1,95 +0,0 @@
|
|||
/*
|
||||
* Load an rbf font, store in incore format and display - or -
|
||||
* Read an incore font and display it.
|
||||
*
|
||||
* If FONT defined, just link in FONT and display it
|
||||
* otherwise, load av[1] and display it
|
||||
*
|
||||
* Copyright (c) 2002 by Greg Haerr <greg@censoft.com>
|
||||
*/
|
||||
#include <stdio.h>
|
||||
|
||||
/* this should go in a library...*/
|
||||
#define DEBUGF printf
|
||||
#include "../firmware/loadfont.c"
|
||||
|
||||
#ifdef FONT
|
||||
extern MWCFONT FONT;
|
||||
PMWCFONT pf = &FONT;
|
||||
#endif
|
||||
|
||||
/* printf display an incore font*/
|
||||
void
|
||||
dispfont(PMWCFONT pf)
|
||||
{
|
||||
int i;
|
||||
|
||||
printf("Font: '%s' %dx%d ", pf->name, pf->maxwidth, pf->height);
|
||||
printf("0x%02x-0x%02x (size %d)\n", pf->firstchar,
|
||||
pf->firstchar+pf->size, pf->size);
|
||||
printf("\tDefault char 0x%02x ", pf->defaultchar);
|
||||
printf("(%s width)\n", pf->width? "proportional": "fixed");
|
||||
|
||||
for (i=0; i<pf->size; ++i) {
|
||||
int width = pf->width ? pf->width[i] : pf->maxwidth;
|
||||
int height = pf->height;
|
||||
int x;
|
||||
int bitcount = 0;
|
||||
MWIMAGEBITS *bits = pf->bits + (pf->offset? pf->offset[i]: (height * i));
|
||||
MWIMAGEBITS bitvalue;
|
||||
|
||||
printf("\nCharacter 0x%02x (width %d)\n", i+pf->firstchar, width);
|
||||
printf("+");
|
||||
for (x=0; x<width; ++x) printf("-");
|
||||
printf("+\n");
|
||||
|
||||
x = 0;
|
||||
while (height > 0) {
|
||||
if (x == 0) printf("|");
|
||||
|
||||
if (bitcount <= 0) {
|
||||
bitcount = MWIMAGE_BITSPERIMAGE;
|
||||
bitvalue = *bits++;
|
||||
}
|
||||
|
||||
printf( MWIMAGE_TESTBIT(bitvalue)? "*": " ");
|
||||
|
||||
bitvalue = MWIMAGE_SHIFTBIT(bitvalue);
|
||||
--bitcount;
|
||||
if (++x == width) {
|
||||
printf("|\n");
|
||||
--height;
|
||||
x = 0;
|
||||
bitcount = 0;
|
||||
}
|
||||
}
|
||||
printf("+");
|
||||
for (x=0; x<width; ++x) printf("-");
|
||||
printf("+\n");
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int ac, char **av)
|
||||
{
|
||||
PMWCFONT pf;
|
||||
MWCFONT font;
|
||||
#ifdef FONT
|
||||
/* if FONT defined, just display linked-in font*/
|
||||
extern MWCFONT FONT;
|
||||
pf = &FONT;
|
||||
#else
|
||||
if (ac != 2) {
|
||||
printf("usage: loadrbf font.rbf\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
pf = rbf_load_font(av[1], &font);
|
||||
if (!pf) {
|
||||
printf("loadrbf: read error: %s\n", av[1]);
|
||||
exit(1);
|
||||
}
|
||||
#endif
|
||||
dispfont(pf);
|
||||
return 0;
|
||||
}
|
112
tools/writerbf.c
112
tools/writerbf.c
|
@ -1,112 +0,0 @@
|
|||
/*
|
||||
* writerbf - write an incore font in .rbf format.
|
||||
* Must be compiled with -DFONT=font_name and linked
|
||||
* with compiled in font.
|
||||
*
|
||||
* Copyright (c) 2002 by Greg Haerr <greg@censoft.com>
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include "../firmware/font.h"
|
||||
|
||||
extern MWCFONT FONT;
|
||||
PMWCFONT pf = &FONT;
|
||||
|
||||
static int
|
||||
WRITEBYTE(FILE *fp, unsigned char c)
|
||||
{
|
||||
return putc(c, fp) != EOF;
|
||||
}
|
||||
|
||||
static int
|
||||
WRITESHORT(FILE *fp, unsigned short s)
|
||||
{
|
||||
putc(s, fp);
|
||||
return putc(s>>8, fp) != EOF;
|
||||
}
|
||||
|
||||
static int
|
||||
WRITELONG(FILE *fp, unsigned long l)
|
||||
{
|
||||
putc(l, fp);
|
||||
putc(l>>8, fp);
|
||||
putc(l>>16, fp);
|
||||
return putc(l>>24, fp) != EOF;
|
||||
}
|
||||
|
||||
static int
|
||||
WRITESTR(FILE *fp, char *str, int count)
|
||||
{
|
||||
return fwrite(str, 1, count, fp) == count;
|
||||
}
|
||||
|
||||
static int
|
||||
WRITESTRPAD(FILE *fp, char *str, int totlen)
|
||||
{
|
||||
int ret;
|
||||
|
||||
while (*str && totlen > 0)
|
||||
if (*str) {
|
||||
ret = putc(*str++, fp);
|
||||
--totlen;
|
||||
}
|
||||
while (--totlen >= 0)
|
||||
ret = putc(' ', fp);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* write font, < 0 return is error*/
|
||||
int
|
||||
rbf_write_font(PMWCFONT pf)
|
||||
{
|
||||
FILE *ofp;
|
||||
int i;
|
||||
char name[256];
|
||||
|
||||
sprintf(name, "%s.fnt", pf->name);
|
||||
ofp = fopen(name, "wb");
|
||||
if (!ofp)
|
||||
return -1;
|
||||
|
||||
/* write magic and version #*/
|
||||
WRITESTR(ofp, VERSION, 4);
|
||||
|
||||
/* internal font name*/
|
||||
WRITESTRPAD(ofp, pf->name, 64);
|
||||
|
||||
/* copyright - FIXME not converted with bdf2c*/
|
||||
WRITESTRPAD(ofp, " ", 256);
|
||||
|
||||
/* font info*/
|
||||
WRITESHORT(ofp, pf->maxwidth);
|
||||
WRITESHORT(ofp, pf->height);
|
||||
WRITESHORT(ofp, pf->ascent);
|
||||
WRITESHORT(ofp, 0);
|
||||
WRITELONG(ofp, pf->firstchar);
|
||||
WRITELONG(ofp, pf->defaultchar);
|
||||
WRITELONG(ofp, pf->size);
|
||||
|
||||
/* variable font data sizes*/
|
||||
WRITELONG(ofp, pf->bits_size); /* # words of MWIMAGEBITS*/
|
||||
WRITELONG(ofp, pf->offset? pf->size: 0); /* # longs of offset*/
|
||||
WRITELONG(ofp, pf->width? pf->size: 0); /* # bytes of width*/
|
||||
|
||||
/* variable font data*/
|
||||
for (i=0; i<pf->bits_size; ++i)
|
||||
WRITESHORT(ofp, pf->bits[i]);
|
||||
if (ftell(ofp) & 2)
|
||||
WRITESHORT(ofp, 0); /* pad to 32-bit boundary*/
|
||||
|
||||
if (pf->offset)
|
||||
for (i=0; i<pf->size; ++i)
|
||||
WRITELONG(ofp, pf->offset[i]);
|
||||
|
||||
if (pf->width)
|
||||
for (i=0; i<pf->size; ++i)
|
||||
WRITEBYTE(ofp, pf->width[i]);
|
||||
}
|
||||
|
||||
int
|
||||
main(int ac, char **av)
|
||||
{
|
||||
rbf_write_font(pf);
|
||||
}
|
|
@ -63,7 +63,7 @@ CFLAGS = $(DEBUG) $(DEFINES) $(INCLUDES) -W -Wall -mwindows
|
|||
APPCFLAGS = $(DEBUG) $(DEFINES) $(APPINCLUDES) -W -Wall -mwindows
|
||||
|
||||
FIRMSRCS = lcd.c power.c sprintf.c id3.c usb.c \
|
||||
mpeg.c powermgmt.c font.c loadfont.c X5x8.c
|
||||
mpeg.c powermgmt.c font.c sysfont.c
|
||||
|
||||
APPS = main.c tree.c menu.c credits.c main_menu.c icons.c \
|
||||
playlist.c showtext.c wps.c wps-display.c settings.c status.c
|
||||
|
@ -187,11 +187,9 @@ $(OBJDIR)/id3.o: $(FIRMWAREDIR)/id3.c
|
|||
$(OBJDIR)/font.o: $(FIRMWAREDIR)/font.c
|
||||
$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
$(OBJDIR)/loadfont.o: $(FIRMWAREDIR)/loadfont.c
|
||||
$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
$(OBJDIR)/X5x8.o: $(FIRMWAREDIR)/X5x8.c
|
||||
$(CC) $(CFLAGS) -c $< -o $@
|
||||
$(OBJDIR)/sysfont.o: $(FIRMWAREDIR)/fonts/clR6x8.bdf
|
||||
$(TOOLSDIR)/convbdf -c -o $(OBJDIR)/sysfont.c $<
|
||||
$(CC) $(APPCFLAGS) -c $(OBJDIR)/sysfont.c -o $@
|
||||
|
||||
$(OBJDIR)/status.o: $(APPDIR)/status.c
|
||||
$(CC) $(APPCFLAGS) -c $< -o $@
|
||||
|
|
|
@ -78,7 +78,7 @@ CFLAGS = $(DEBUG) $(DEFINES) $(INCLUDES) -W -Wall
|
|||
APPCFLAGS = $(DEBUG) $(DEFINES) -DAPPSVERSION=\"$(VERSION)\" $(APPINCLUDES) -W -Wall
|
||||
|
||||
FIRMSRCS = lcd.c sprintf.c id3.c debug.c usb.c mpeg.c power.c\
|
||||
powermgmt.c font.c X5x8.c loadfont.c panic.c
|
||||
powermgmt.c font.c panic.c sysfont.c
|
||||
|
||||
APPS = main.c tree.c menu.c credits.c main_menu.c\
|
||||
playlist.c showtext.c wps.c wps-display.c settings.c status.c icons.c
|
||||
|
@ -221,24 +221,13 @@ $(OBJDIR)/lang.o: $(APPDIR)/lang/$(LANGUAGE).lang
|
|||
$(OBJDIR)/lcd.o: $(DRIVERS)/lcd.c
|
||||
$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
$(OBJDIR)/X5x8.o: $(FIRMWAREDIR)/X5x8.c
|
||||
$(CC) $(APPCFLAGS) -c $< -o $@
|
||||
|
||||
$(OBJDIR)/X6x9.o: $(FIRMWAREDIR)/X6x9.c
|
||||
$(CC) $(APPCFLAGS) -c $< -o $@
|
||||
|
||||
$(OBJDIR)/timR08.o: $(FIRMWAREDIR)/timR08.c
|
||||
$(CC) $(APPCFLAGS) -c $< -o $@
|
||||
|
||||
$(OBJDIR)/courB08.o: $(FIRMWAREDIR)/courB08.c
|
||||
$(CC) $(APPCFLAGS) -c $< -o $@
|
||||
$(OBJDIR)/sysfont.o: $(FIRMWAREDIR)/fonts/clR6x8.bdf
|
||||
$(TOOLSDIR)/convbdf -c -o $(OBJDIR)/sysfont.c $<
|
||||
$(CC) $(APPCFLAGS) -c $(OBJDIR)/sysfont.c -o $@
|
||||
|
||||
$(OBJDIR)/font.o: $(FIRMWAREDIR)/font.c
|
||||
$(CC) $(APPCFLAGS) -c $< -o $@
|
||||
|
||||
$(OBJDIR)/loadfont.o: $(FIRMWAREDIR)/loadfont.c
|
||||
$(CC) $(APPCFLAGS) -c $< -o $@
|
||||
|
||||
$(OBJDIR)/settings.o: $(APPDIR)/settings.c
|
||||
$(CC) $(APPCFLAGS) -c $< -o $@
|
||||
|
||||
|
|
Loading…
Reference in New Issue