From 93b231c69366563ba441dc4907bfb036fe3b4c55 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 12 Sep 2002 13:33:59 +0000 Subject: Greg Haerr's new loadable font. No more #ifdef font-style, removed old propfont and loadable font code. New font file format. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@2269 a1c6a512-1295-4272-9138-f99709370657 --- firmware/drivers/fat.c | 29 ----- firmware/drivers/lcd.c | 315 +++---------------------------------------------- firmware/drivers/lcd.h | 17 +-- 3 files changed, 20 insertions(+), 341 deletions(-) (limited to 'firmware/drivers') diff --git a/firmware/drivers/fat.c b/firmware/drivers/fat.c index c43807b25f..f0a2089367 100644 --- a/firmware/drivers/fat.c +++ b/firmware/drivers/fat.c @@ -1049,10 +1049,6 @@ int fat_getnext(struct fat_dir *dir, struct fat_direntry *entry) for (j=longs-1; j>=0; j--) { unsigned char* ptr = dir->cached_buf; int index = longarray[j]; -#ifdef LOADABLE_FONTS - int offset_idx = 0; - unsigned char uni_char[2]; -#endif /* current or cached sector? */ if ( sectoridx >= SECTOR_SIZE ) { if ( sectoridx >= SECTOR_SIZE*2 ) { @@ -1070,30 +1066,6 @@ int fat_getnext(struct fat_dir *dir, struct fat_direntry *entry) index &= SECTOR_SIZE-1; } - /* piece together the name subcomponents. */ -#ifdef LOADABLE_FONTS - for (k=0; k<5; k++) - { - offset_idx = index + k*2 + 1; - uni_char[0] = ptr[offset_idx+1]; - uni_char[1] = ptr[offset_idx]; - entry->name[l++] = from_unicode(uni_char); - } - for (k=0; k<6; k++) - { - offset_idx = index + k*2 + 14; - uni_char[0] = ptr[offset_idx+1]; - uni_char[1] = ptr[offset_idx]; - entry->name[l++] = from_unicode(uni_char); - } - for (k=0; k<2; k++) - { - offset_idx = index + k*2 + 28; - uni_char[0] = ptr[offset_idx+1]; - uni_char[1] = ptr[offset_idx]; - entry->name[l++] = from_unicode(uni_char); - } -#else /* names are stored in unicode, but we only grab the low byte (iso8859-1). */ for (k=0; k<5; k++) @@ -1102,7 +1074,6 @@ int fat_getnext(struct fat_dir *dir, struct fat_direntry *entry) entry->name[l++] = ptr[index + k*2 + 14]; for (k=0; k<2; k++) entry->name[l++] = ptr[index + k*2 + 28]; -#endif } entry->name[l]=0; } diff --git a/firmware/drivers/lcd.c b/firmware/drivers/lcd.c index e3248878da..5240dfda42 100644 --- a/firmware/drivers/lcd.c +++ b/firmware/drivers/lcd.c @@ -26,17 +26,12 @@ #include "file.h" #include "debug.h" #include "system.h" - -#ifdef LOADABLE_FONTS -#include "ajf.h" -#include "panic.h" -#endif +#include "font.h" #if defined(SIMULATOR) #include "sim_icons.h" #endif - /*** definitions ***/ #define LCDR (PBDR_ADDR+1) @@ -513,9 +508,6 @@ void lcd_init (void) { create_thread(scroll_thread, scroll_stack, sizeof(scroll_stack), scroll_name); -#if defined(LOADABLE_FONTS) && defined(SIMULATOR) - lcd_init_fonts(); -#endif } #endif @@ -568,17 +560,11 @@ static int ymargin=0; #define ASCII_MIN 0x20 /* First char in table */ #define ASCII_MAX 0x7f /* Last char in table */ -extern unsigned char char_gen_6x8[][5]; -extern unsigned char char_gen_8x12[][14]; -extern unsigned char char_gen_12x16[][22]; - /* All zeros and ones bitmaps for area filling */ static unsigned char zeros[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; static unsigned char ones[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; -static char fonts[] = { 6,8,12 }; -static char fontheight[] = { 8,12,16 }; #ifndef SIMULATOR @@ -696,175 +682,14 @@ int lcd_getymargin(void) return ymargin; } - - -#ifdef LOADABLE_FONTS - -static unsigned char* _font = NULL; - -int lcd_init_fonts(void) -{ - if (!_font) - _font = ajf_read_font("/system.ajf"); - - if (!_font) - { - lcd_putsxy(0,0,"No font", 0); - return -1; - } - - return 0; -} - -void lcd_setldfont(unsigned char* f) -{ - _font = f; -} - -unsigned char* lcd_getcurrentldfont() -{ - if (!_font) - panicf("No font loaded!"); - return _font; -} - -/* - * Return width and height of a string with a given font. - */ -int lcd_getstringsize(unsigned char *str, unsigned char* font, int *w, int *h) -{ - int width=0; - int height=0; - unsigned char ch; - - if (!font) - panicf("No font specified"); - - while((ch = *str++)) - { - int dw,dh; - ajf_get_charsize(ch, font, &dw, &dh); - if (dh>height) - height = dh; - width+=dw; - } - *w = width; - *h = height; - - return width; -} - -/* - * Put a string at specified bit position - */ - -void lcd_putsldfxy(int x, int y, unsigned char *str) -{ - unsigned char ch; - int nx; - int ny=8; - int lcd_x = x; - int lcd_y = y; - if (!_font) - { - lcd_putsxy(0,0,"No font", 0); - return; - } - ny = (int)_font[2]; - while (((ch = *str++) != '\0')) - { - unsigned char *char_buf = ajf_get_charbuf(ch, _font, &nx, &ny); - if (!char_buf) - { - char_buf = ajf_get_charbuf('?', _font, &nx, &ny); - if (!char_buf) - panicf("Bad font"); - } - if(lcd_x + nx > LCD_WIDTH) - break; - - lcd_bitmap (&char_buf[0], lcd_x, lcd_y, nx, ny, true); - lcd_x += nx; - } -} -#endif - - -#ifdef LCD_PROPFONTS - -extern unsigned char char_dw_8x8_prop[][9]; - -/* - * Return width and height of a given font. - */ -int lcd_getstringsize(unsigned char *str, unsigned int font, int *w, int *h) -{ - int width=0; - unsigned char ch, byte; - (void)font; - - while((ch = *str++)) { - /* Limit to char generation table */ - if (ch < ASCII_MIN) - /* replace unsupported letters with question marks */ - ch = ' '-ASCII_MIN; - else - ch -= ASCII_MIN; - - byte = char_dw_8x8_prop[ch][8]; - width += (byte>>4) + 1; - } - *w = width; - *h = 8; - - return width; -} - -/* - * Put a string at specified bit position - */ - -void lcd_putspropxy(int x, int y, unsigned char *str, int thisfont) -{ - unsigned int ch; - int nx; - int ny=8; - unsigned char *src; - int lcd_x = x; - int lcd_y = y; - - (void)thisfont; - - while (((ch = *str++) != '\0')) - { - /* Limit to char generation table */ - if (ch < ASCII_MIN) - /* replace unsupported letters with question marks */ - ch = ' '-ASCII_MIN; - else - ch -= ASCII_MIN; - - nx = char_dw_8x8_prop[ch][8] >> 4; - - if(lcd_x + nx > LCD_WIDTH) - break; - - src = char_dw_8x8_prop[ch]; - lcd_clearrect (lcd_x+nx, lcd_y, 1, ny ); - lcd_bitmap (src, lcd_x, lcd_y, nx, ny, true); - - lcd_x += nx+1; - } -} - -#endif - /* * 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; + #if defined(SIMULATOR) && defined(HAVE_LCD_CHARCELLS) /* We make the simulator truncate the string if it reaches the right edge, as otherwise it'll wrap. The real target doesn't wrap. */ @@ -882,23 +707,10 @@ void lcd_puts(int x, int y, unsigned char *str) if(!str || !str[0]) return; -#ifdef LCD_PROPFONTS lcd_getstringsize(str, font, &w, &h); - xpos = xmargin + x * fonts[font]; - ypos = ymargin + y * fontheight[font]; - lcd_putspropxy(xpos, ypos, str, font); -#elif LOADABLE_FONTS - lcd_getstringsize(str,_font,&w,&h); - xpos = xmargin + x * w / strlen(str); - ypos = ymargin + y * h; - lcd_putsldfxy(xpos, ypos, str); -#else - xpos = xmargin + x * fonts[font]; - ypos = ymargin + y * fontheight[font]; - lcd_putsxy(xpos, ypos, str, font); - w = strlen(str) * fonts[font]; - h = fontheight[font]; -#endif + xpos = xmargin + x*w / strlen(str); //FIXME why strlen? + ypos = ymargin + y*h; + lcd_putsxy( xpos, ypos, str, font); 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 @@ -907,58 +719,6 @@ void lcd_puts(int x, int y, unsigned char *str) #endif } - -/* - * Put a string at specified bit position - */ -void lcd_putsxy(int x, int y, unsigned char *str, int thisfont) -{ -#ifdef LCD_PROPFONTS - lcd_putspropxy(x,y,str,thisfont); -#else - - int nx = fonts[thisfont]; - int ny = fontheight[thisfont]; - int ch; - unsigned char *src; - int lcd_x = x; - int lcd_y = y; - -#ifdef LOADABLE_FONTS - if ( _font ) { - lcd_putsldfxy(x,y,str); - return; - } -#endif - - while (((ch = *str++) != '\0') && (lcd_x + nx <= LCD_WIDTH)) - { - if (lcd_y + ny > LCD_HEIGHT) - return; - - /* Limit to char generation table */ - if ((ch < ASCII_MIN) || (ch > ASCII_MAX)) - /* replace unsupported letters with question marks */ - ch = '?' - ASCII_MIN; - else - ch -= ASCII_MIN; - - if (thisfont == 2) - src = char_gen_12x16[ch]; - else if (thisfont == 1) - src = char_gen_8x12[ch]; - else - src = char_gen_6x8[ch]; - - lcd_bitmap (src, lcd_x, lcd_y, nx-1, ny, true); - lcd_bitmap (zeros, lcd_x+nx-1, lcd_y, 1, ny, true); - - lcd_x += nx; - - } -#endif -} - /* * Display a bitmap at (x, y), size (nx, ny) * clear is true to clear destination area first @@ -1265,17 +1025,6 @@ void lcd_invertpixel(int x, int y) INVERT_PIXEL(x,y); } -/* - * Return width and height of a given font. - */ -void lcd_getfontsize(unsigned int font, int *width, int *height) -{ - if(font < sizeof(fonts)) { - *width = fonts[font]; - *height = fontheight[font]; - } -} - #else /* no LCD defined, no code to use */ #endif @@ -1286,47 +1035,31 @@ void lcd_puts_scroll(int x, int y, unsigned char* string ) #ifdef HAVE_LCD_CHARCELLS s->space = 11 - x; #else - -#if defined(LCD_PROPFONTS) || defined(LOADABLE_FONTS) unsigned char ch[2]; int w, h; -#endif int width, height; lcd_getfontsize(font, &width, &height); -#if defined(LCD_PROPFONTS) || defined(LOADABLE_FONTS) + ch[1] = 0; /* zero terminate */ ch[0] = string[0]; width = 0; s->space = 0; while ( ch[0] && -#ifdef LCD_PROPFONTS (width + lcd_getstringsize(ch, 0, &w, &h) < (LCD_WIDTH - x*8))) { -#else - (width + lcd_getstringsize(ch, _font, &w, &h) < - (LCD_WIDTH - x*8))) { -#endif width += w; s->space++; ch[0]=string[s->space]; } -#else - s->space = (LCD_WIDTH - xmargin - x*width) / width; -#endif #endif lcd_puts(x,y,string); s->textlen = strlen(string); - -#if defined(LCD_PROPFONTS) +#ifdef HAVE_LCD_BITMAP s->space += 2; lcd_getstringsize(string,0,&w,&h); if ( w > LCD_WIDTH - xmargin ) { -#elif defined(LOADABLE_FONTS) - s->space += 2; - lcd_getstringsize(string,_font,&w,&h); - if ( w > LCD_WIDTH - xmargin ) { #else if ( s->textlen > s->space ) { #endif @@ -1344,32 +1077,24 @@ void lcd_puts_scroll(int x, int y, unsigned char* string ) } } + void lcd_stop_scroll(void) { if ( scroll_count ) { struct scrollinfo* s = &scroll; scroll_count = 0; - -#ifdef LCD_PROPFONTS - lcd_clearrect(xmargin + s->startx*fonts[font], - ymargin + s->starty*fontheight[font], - LCD_WIDTH - xmargin, - fontheight[font]); - -#elif defined(LOADABLE_FONTS) +#ifdef HAVE_LCD_BITMAP { int w,h; - lcd_getstringsize( s->text, _font, &w, &h); + /* FIXME no font index */ + lcd_getstringsize( s->text, FONT_UI, &w, &h); lcd_clearrect(xmargin + s->startx*w/s->textlen, ymargin + s->starty*h, LCD_WIDTH - xmargin, h); - } #endif - - /* restore scrolled row */ lcd_puts(s->startx,s->starty,s->text); lcd_update(); @@ -1420,20 +1145,16 @@ static void scroll_thread(void) s->offset = 0; } -#ifdef LCD_PROPFONTS - lcd_clearrect(xmargin + s->startx*fonts[font], - ymargin + s->starty*fontheight[font], - LCD_WIDTH - xmargin, - fontheight[font]); -#elif defined(LOADABLE_FONTS) - { - int w,h; - lcd_getstringsize( s->text, _font, &w, &h); +#ifdef HAVE_LCD_BITMAP + { + /* FIXME no font index */ + int w, h; + lcd_getstringsize( s->text, FONT_UI, &w, &h); lcd_clearrect(xmargin + s->startx*w/s->textlen, ymargin + s->starty*h, LCD_WIDTH - xmargin, h); - } + } #endif lcd_puts(s->startx,s->starty,s->line); lcd_update(); diff --git a/firmware/drivers/lcd.h b/firmware/drivers/lcd.h index 552de9a74f..23b3d75e76 100644 --- a/firmware/drivers/lcd.h +++ b/firmware/drivers/lcd.h @@ -101,7 +101,7 @@ 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(unsigned int font, int *width, int *height); +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); @@ -119,19 +119,6 @@ extern void lcd_invertpixel(int x, int y); #endif /* CHARCELLS / BITMAP */ -#ifdef LOADABLE_FONTS -extern int lcd_init_fonts(void); -extern void lcd_putsldfxy(int x, int y, unsigned char *str); -extern int lcd_getstringsize(unsigned char *str, - unsigned char* font, - int *w, int *h); -extern void lcd_setldfont(unsigned char* f); - -extern unsigned char* lcd_getcurrentldfont(void); -#endif - -#ifdef LCD_PROPFONTS -extern int lcd_getstringsize(unsigned char *str, unsigned int font, int *w, int *h); -#endif +extern int lcd_getstringsize(unsigned char *str, int font, int *w, int *h); #endif /* __LCD_H__ */ -- cgit v1.2.3