From 0a1c22128f6bca490c1b39a07ac30419f83b41ce Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 13 Sep 2002 06:37:49 +0000 Subject: Greg Haerr's font patch 3: Rotates the font bitmaps only once at font_init() time, with some source cleanup to rockbox standards. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@2284 a1c6a512-1295-4272-9138-f99709370657 --- firmware/font.c | 116 +++++++++++++++++++++++++++++++++++++------------------- firmware/font.h | 2 +- 2 files changed, 77 insertions(+), 41 deletions(-) (limited to 'firmware') diff --git a/firmware/font.c b/firmware/font.c index 5bde2ff1bc..5237f7d2aa 100644 --- a/firmware/font.c +++ b/firmware/font.c @@ -49,6 +49,10 @@ struct corefont sysfonts[MAXFONTS] = { { 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) { @@ -62,6 +66,10 @@ font_init(void) DEBUGF("Font load failed: %s\n", cfp->diskname); #endif } + + /* one-time rotate font bits to rockbox format*/ + if (cfp->pf && cfp->pf->height) + rotate_font_bits(cfp->pf); } } @@ -107,7 +115,6 @@ lcd_getstringsize(unsigned char *str, int font, int *w, int *h) int width = 0; while((ch = *str++)) { - /* check input range*/ if (ch < pf->firstchar || ch >= pf->firstchar+pf->size) ch = pf->defaultchar; @@ -122,6 +129,70 @@ lcd_getstringsize(unsigned char *str, int font, int *w, int *h) 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; + 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) +{ + int i; + int defaultchar = pf->defaultchar - pf->firstchar; + int did_defaultchar = 0; + unsigned char buf[256]; + + for (i=0; isize; ++i) { + MWIMAGEBITS *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; + + /* + * 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 (did_defaultchar) + continue; + did_defaultchar = 1; + } + + /* rotate left for lcd_bitmap function input*/ + rotleft(buf, bits, width, pf->height); + + /* copy back into original location*/ + memcpy(bits, buf, src_bytes); + } +} + /* * Take an MWIMAGEBITS bitmap and convert to Rockbox format. * Used for converting font glyphs for the time being. @@ -147,7 +218,7 @@ rotleft(unsigned char *dst, MWIMAGEBITS *src, unsigned int width, src_words = MWIMAGE_WORDS(width) * height; /* clear background*/ - memset(dst, 0, dst_linelen*height); + memset(dst, 0, dst_linelen*width); for (i=0; i < src_words; i++) { MWIMAGEBITS srcmap; /* current src input bit*/ @@ -178,45 +249,9 @@ rotleft(unsigned char *dst, MWIMAGEBITS *src, unsigned int width, /* input column j becomes output row*/ dst[j*dst_linelen + dst_col] |= dstmap; } - //printf((bit & src[i])? "*": "."); + /*debugf((bit & src[i])? "*": ".");*/ } - //printf("\n"); - } -} - -/* - * 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; - unsigned char *src; - PMWCFONT pf = getfont(font); - - while (((ch = *str++) != '\0')) { - MWIMAGEBITS *bits; - int width; - unsigned char outbuf[256]; - - /* 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; - bits = pf->bits + (pf->offset? pf->offset[ch]: (pf->height * ch)); - - /* rotate left for lcd_bitmap function input*/ - rotleft(outbuf, bits, width, pf->height); - src = outbuf; - - lcd_bitmap (src, x, y, width, pf->height, true); - x += width; + /*debugf("\n");*/ } } #endif /* HAVE_LCD_BITMAP */ @@ -224,5 +259,6 @@ lcd_putsxy(int x, int y, unsigned char *str, int font) /* ----------------------------------------------------------------- * local variables: * eval: (load-file "rockbox-mode.el") + * vim: et sw=4 ts=4 sts=4 tw=78 * end: */ diff --git a/firmware/font.h b/firmware/font.h index 13d60e560b..8535ab216b 100644 --- a/firmware/font.h +++ b/firmware/font.h @@ -70,7 +70,7 @@ /* MWIMAGEBITS helper macros*/ #define MWIMAGE_WORDS(x) (((x)+15)/16) /* image size in words*/ -#define MWIMAGE_BYTES(x) (((x)+7)/8) /* image size in bytes*/ +#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)) -- cgit v1.2.3