diff -u -r rockbox_svn.orig/apps/filetree.c rockbox_svn/apps/filetree.c --- rockbox_svn.orig/apps/filetree.c 2008-01-08 17:00:41.000000000 -0600 +++ rockbox_svn/apps/filetree.c 2008-01-08 16:48:27.000000000 -0600 @@ -522,8 +522,34 @@ #ifdef HAVE_LCD_BITMAP case FILE_ATTR_FONT: gui_syncsplash(0, ID2P(LANG_WAIT)); - font_load(buf); - set_file(buf, (char *)global_settings.font_file, MAX_FILENAME); + /* If a font is chosen it overrides all theme settings */ + font_load(buf, FONT_BROWSER); + + /* set_file will change buf!!! + * so make a copy */ + char buf_copy[MAX_PATH]; + strcpy(buf_copy, buf); + set_file(buf_copy, (char *)global_settings.browserfont, MAX_FILENAME); + + font_load(buf, FONT_WPS); + strcpy(buf_copy, buf); + set_file(buf_copy, (char *)global_settings.wpsfont, MAX_FILENAME); + + font_load(buf, FONT_MENU); + strcpy(buf_copy, buf); + set_file(buf_copy, (char *)global_settings.menufont, MAX_FILENAME); + +#ifdef CONFIG_TUNER + font_load(buf, FONT_TUNER); + strcpy(buf_copy, buf); + set_file(buf_copy, (char *)global_settings.tunerfont, MAX_FILENAME); +#endif +#ifdef HAVE_RECORDING + font_load(buf, FONT_RECORD); + strcpy(buf_copy, buf); + set_file(buf_copy, (char *)global_settings.recordfont, MAX_FILENAME); +#endif + /* dont set userfonts because of the buffer problem */ break; case FILE_ATTR_KBD: diff -u -r rockbox_svn.orig/apps/gui/buttonbar.c rockbox_svn/apps/gui/buttonbar.c --- rockbox_svn.orig/apps/gui/buttonbar.c 2008-01-05 18:11:02.000000000 -0600 +++ rockbox_svn/apps/gui/buttonbar.c 2008-01-08 16:48:27.000000000 -0600 @@ -116,7 +116,8 @@ gui_buttonbar_draw_button(buttonbar, i); display->update_rect(0, display->height - BUTTONBAR_HEIGHT, display->width, BUTTONBAR_HEIGHT); - display->setfont(FONT_UI); + // MWE ? + display->setfont(FONT_BROWSER); } bool gui_buttonbar_isset(struct gui_buttonbar * buttonbar) diff -u -r rockbox_svn.orig/apps/gui/color_picker.c rockbox_svn/apps/gui/color_picker.c --- rockbox_svn.orig/apps/gui/color_picker.c 2008-01-05 18:11:02.000000000 -0600 +++ rockbox_svn/apps/gui/color_picker.c 2008-01-08 16:48:27.000000000 -0600 @@ -268,6 +268,7 @@ } /* end for */ /* Draw color value in system font */ + int oldFont=display->getfont(); display->setfont(FONT_SYSFIXED); /* Format RGB: #rrggbb */ @@ -320,7 +321,7 @@ } } - display->setfont(FONT_UI); + display->setfont(oldFont); display->update(); /* Be sure screen mode is reset */ diff -u -r rockbox_svn.orig/apps/gui/gwps-common.c rockbox_svn/apps/gui/gwps-common.c --- rockbox_svn.orig/apps/gui/gwps-common.c 2008-01-08 17:00:41.000000000 -0600 +++ rockbox_svn/apps/gui/gwps-common.c 2008-01-08 16:48:27.000000000 -0600 @@ -465,7 +465,7 @@ struct wps_data *data = gwps->data; struct screen *display = gwps->display; struct wps_state *state = gwps->state; - int h = font_get(FONT_UI)->height; + int h = font_get(FONT_WPS)->height; int sb_y; if (data->progress_top < 0) @@ -1890,6 +1890,7 @@ bool update_line, new_subline_refresh; #ifdef HAVE_LCD_BITMAP + display->setfont(FONT_WPS); gui_wps_statusbar_draw(gwps, true); /* to find out wether the peak meter is enabled we @@ -1977,7 +1978,7 @@ /* the peakmeter should be alone on its line */ update_line = false; - int h = font_get(FONT_UI)->height; + int h = font_get(FONT_WPS)->height; int peak_meter_y = display->getymargin() + line * h; /* The user might decide to have the peak meter in the last diff -u -r rockbox_svn.orig/apps/gui/gwps.c rockbox_svn/apps/gui/gwps.c --- rockbox_svn.orig/apps/gui/gwps.c 2008-01-05 18:11:02.000000000 -0600 +++ rockbox_svn/apps/gui/gwps.c 2008-01-08 16:48:27.000000000 -0600 @@ -92,6 +92,11 @@ } #endif +static void gui_wps_set_font(struct gui_wps *gwps) +{ + gwps->display->setfont(FONT_WPS); +} + long gui_wps_show(void) { long button = 0; @@ -105,6 +110,12 @@ wps_state_init(); + /* Set WPS display font */ + FOR_NB_SCREENS(i) + { + gui_wps_set_font(&gui_wps[i]); + } + #ifdef HAVE_LCD_CHARCELLS status_set_audio(true); status_set_param(false); diff -u -r rockbox_svn.orig/apps/gui/list.c rockbox_svn/apps/gui/list.c --- rockbox_svn.orig/apps/gui/list.c 2008-01-08 13:45:06.000000000 -0600 +++ rockbox_svn/apps/gui/list.c 2008-01-08 16:48:27.000000000 -0600 @@ -38,6 +38,8 @@ #include "misc.h" #include "talk.h" +#include "debug.h" + #ifdef HAVE_LCD_CHARCELLS #define SCROLL_LIMIT 1 #else @@ -50,6 +52,10 @@ #define FRAMEDROP_TRIGGER 6 #ifdef HAVE_LCD_BITMAP +/* gui_list can have two contexts, MENU and BROWSER. Contexts are used to determine display font. */ +short gui_list_context = -1; +#define GUI_LIST_CONTEXT_MENU 0 +#define GUI_LIST_CONTEXT_BRWSR 1 static int offset_step = 16; /* pixels per screen scroll step */ /* should lines scroll out of the screen */ static bool offset_out_of_view = false; @@ -169,9 +175,26 @@ bool partial_draw = false; #ifdef HAVE_LCD_BITMAP - display->setfont(FONT_UI); - gui_textarea_update_nblines(display); + switch (gui_list_context) /* Set appropriate font */ + { + case GUI_LIST_CONTEXT_MENU: + display->setfont(FONT_MENU); +#if (!defined(IRIVER_H100)) && (!defined(IRIVER_H120)) && (!defined(IRIVER_H300)) && (!defined(IAUDIO_X5)) && (!defined(IAUDIO_M5)) + lcd_set_foreground(global_settings.fg_color); #endif + break; + case GUI_LIST_CONTEXT_BRWSR: + display->setfont(FONT_BROWSER); +#if (!defined(IRIVER_H100)) && (!defined(IRIVER_H120)) && (!defined(IRIVER_H300)) && (!defined(IAUDIO_X5)) && (!defined(IAUDIO_M5)) + lcd_set_foreground(global_settings.fg_color); +#endif + break; + default: + debugf("gui_list_put_selection_in_screen(): unknown font context: %i\n", gui_list_context); + } +#endif + gui_textarea_update_nblines(display); + /* Speed up UI by drawing the changed contents only. */ if (gui_list == last_list_displayed && gui_list->last_displayed_start_item[display->screen_type] == gui_list->start_item[display->screen_type] @@ -255,7 +278,6 @@ /* Adjust the position of icon, cursor, text for the list */ #ifdef HAVE_LCD_BITMAP - gui_textarea_update_nblines(display); bool draw_scrollbar; draw_scrollbar = (global_settings.scrollbar && diff -u -r rockbox_svn.orig/apps/gui/list.h rockbox_svn/apps/gui/list.h --- rockbox_svn.orig/apps/gui/list.h 2008-01-05 18:11:02.000000000 -0600 +++ rockbox_svn/apps/gui/list.h 2008-01-08 16:48:27.000000000 -0600 @@ -134,6 +134,13 @@ #define gui_list_set_nb_items(gui_list, nb) \ (gui_list)->nb_items = nb +/* gui_list can have two contexts, LIST_MENU and LIST_BROWSER. Contexts are used to determine display font. */ +#ifdef HAVE_LCD_BITMAP +extern short gui_list_context; +#define GUI_LIST_CONTEXT_MENU 0 +#define GUI_LIST_CONTEXT_BRWSR 1 +#endif + /* * Returns the numbers of items currently in the list * - gui_list : the list structure diff -u -r rockbox_svn.orig/apps/gui/quickscreen.c rockbox_svn/apps/gui/quickscreen.c --- rockbox_svn.orig/apps/gui/quickscreen.c 2008-01-05 18:11:02.000000000 -0600 +++ rockbox_svn/apps/gui/quickscreen.c 2008-01-08 16:48:27.000000000 -0600 @@ -62,6 +62,10 @@ { display->setfont(FONT_SYSFIXED); } + else + display->setfont(FONT_MENU); + if(display->depth > 2) + display->set_foreground(global_settings.fg_color); display->getstringsize("A", NULL, &font_h); /* do these calculations once */ @@ -119,7 +123,6 @@ putsxy_bottom-font_h, 7, 8); gui_textarea_update(display); - display->setfont(FONT_UI); } /* diff -u -r rockbox_svn.orig/apps/gui/splash.c rockbox_svn/apps/gui/splash.c --- rockbox_svn.orig/apps/gui/splash.c 2008-01-05 18:11:02.000000000 -0600 +++ rockbox_svn/apps/gui/splash.c 2008-01-08 16:48:27.000000000 -0600 @@ -25,6 +25,7 @@ #include "lang.h" #include "settings.h" #include "talk.h" +#include "font.h" #ifndef MAX #define MAX(a, b) (((a)>(b))?(a):(b)) @@ -57,10 +58,12 @@ int space_w, w, h; #ifdef HAVE_LCD_BITMAP int maxw = 0; + int oldFont=screen->getfont(); #if LCD_DEPTH > 1 unsigned prevfg = 0; #endif + screen->setfont(FONT_MENU); screen->getstringsize(" ", &space_w, &h); #else /* HAVE_LCD_CHARCELLS */ @@ -75,8 +78,12 @@ /* break splash string into display lines, doing proper word wrap */ next = strtok_r(splash_buf, " ", &store); - if (!next) + if (!next){ +#ifdef HAVE_LCD_BITMAP + screen->setfont(oldFont); +#endif return; /* nothing to display */ + } lines[0] = next; while (true) @@ -127,6 +134,7 @@ screen->stop_scroll(); #ifdef HAVE_LCD_BITMAP + /* If we center the display, then just clear the box we need and put a nice little frame and put the text in there! */ y = (screen->height - y) / 2; /* height => y start position */ @@ -180,6 +188,7 @@ screen->set_foreground(prevfg); screen->set_drawmode(DRMODE_SOLID); } + screen->setfont(oldFont); #endif screen->update(); } diff -u -r rockbox_svn.orig/apps/gui/statusbar.c rockbox_svn/apps/gui/statusbar.c --- rockbox_svn.orig/apps/gui/statusbar.c 2008-01-05 18:11:02.000000000 -0600 +++ rockbox_svn/apps/gui/statusbar.c 2008-01-08 16:48:27.000000000 -0600 @@ -380,6 +380,7 @@ #if LCD_DEPTH > 1 unsigned int prevfg = 0; #endif + int oldfont; #if CONFIG_CHARGING if (batt_charge_step >= 0) @@ -405,15 +406,19 @@ if (global_settings.battery_display && (percent > -1)) { #endif /* Numeric display */ - display->setfont(FONT_SYSFIXED); snprintf(buffer, sizeof(buffer), "%3d", percent); + + /* remember to set back if font changed */ + oldfont=display->getfont(); + + display->setfont(FONT_SYSFIXED); display->getstringsize(buffer, &width, &height); if (height <= STATUSBAR_HEIGHT) display->putsxy(STATUSBAR_BATTERY_X_POS + STATUSBAR_BATTERY_WIDTH / 2 - width/2, STATUSBAR_Y_POS, buffer); - display->setfont(FONT_UI); - + /* set back previous font */ + display->setfont(oldfont); } else { /* draw battery */ @@ -439,10 +444,14 @@ } if (percent == -1) { + /* remember to set back if font changed */ + oldfont=display->getfont(); + display->setfont(FONT_SYSFIXED); display->putsxy(STATUSBAR_BATTERY_X_POS + STATUSBAR_BATTERY_WIDTH / 2 - 4, STATUSBAR_Y_POS, "?"); - display->setfont(FONT_UI); + /* set back previous font */ + display->setfont(oldfont); } } @@ -487,8 +496,11 @@ /* display volume level numerical? */ if (type) { - display->setfont(FONT_SYSFIXED); snprintf(buffer, sizeof(buffer), "%2d", volume); + /* remember to set back if font changed */ + int oldFont=display->getfont(); + + display->setfont(FONT_SYSFIXED); display->getstringsize(buffer, &width, &height); if (height <= STATUSBAR_HEIGHT) { @@ -496,7 +508,7 @@ + STATUSBAR_VOLUME_WIDTH / 2 - width/2, STATUSBAR_Y_POS, buffer); } - display->setfont(FONT_UI); + display->setfont(oldFont); } else { /* display volume bar */ vol = (volume - minvol) * 14 / (maxvol - minvol); @@ -600,13 +612,16 @@ else { strncpy(buffer, "--:--", sizeof buffer); } + /* remember to set back if font changed */ + int oldfont=display->getfont(); + display->setfont(FONT_SYSFIXED); display->getstringsize(buffer, &width, &height); if (height <= STATUSBAR_HEIGHT) { display->putsxy(STATUSBAR_TIME_X_END(display->width) - width, STATUSBAR_Y_POS, buffer); } - display->setfont(FONT_UI); + display->setfont(oldfont); } #endif @@ -709,6 +724,9 @@ static void gui_statusbar_icon_recording_info(struct screen * display) { + /* remember to set back if font changed */ + int oldfont=display->getfont(); + #if CONFIG_CODEC != SWCODEC char buffer[3]; int width, height; @@ -771,6 +789,7 @@ STATUSBAR_RECCHANNELS_X_POS, STATUSBAR_Y_POS, STATUSBAR_RECCHANNELS_WIDTH, STATUSBAR_HEIGHT); } + display->setfont(oldfont); } #endif /* HAVE_RECORDING */ diff -u -r rockbox_svn.orig/apps/gui/wps_parser.c rockbox_svn/apps/gui/wps_parser.c --- rockbox_svn.orig/apps/gui/wps_parser.c 2008-01-08 17:00:41.000000000 -0600 +++ rockbox_svn/apps/gui/wps_parser.c 2008-01-08 16:48:27.000000000 -0600 @@ -566,9 +566,38 @@ vp->height = tmp[3]; vp->font = tmp[4]; - /* Default to using the user font if the font was an invalid number */ - if ((vp->font != FONT_SYSFIXED) && (vp->font != FONT_UI)) - vp->font = FONT_UI; + switch (vp->font){ + case 0: + vp->font = FONT_SYSFIXED; + break; + case 1: + vp->font = FONT_WPS; + break; + case 2: + vp->font = FONT_USER1; + break; + case 3: + vp->font = FONT_USER2; + break; + case 4: + vp->font = FONT_USER3; + break; + case 5: + vp->font = FONT_USER4; + break; + case 6: + vp->font = FONT_USER5; + break; + case 7: + vp->font = FONT_USER6; + break; + case 8: + vp->font = FONT_USER7; + break; + default: + vp->font = FONT_WPS; + break; + } /* TODO - try and make the following code simpler... */ @@ -1448,7 +1477,7 @@ wps_data->viewports[0].vp.width = display->width; wps_data->viewports[0].vp.height = display->height; #ifdef HAVE_LCD_BITMAP - wps_data->viewports[0].vp.font = FONT_UI; + wps_data->viewports[0].vp.font = FONT_WPS; wps_data->viewports[0].vp.drawmode = DRMODE_SOLID; #endif wps_data->viewports[0].vp.xmargin = display->getxmargin(); diff -u -r rockbox_svn.orig/apps/gui/yesno.c rockbox_svn/apps/gui/yesno.c --- rockbox_svn.orig/apps/gui/yesno.c 2008-01-05 18:11:02.000000000 -0600 +++ rockbox_svn/apps/gui/yesno.c 2008-01-08 16:48:27.000000000 -0600 @@ -24,6 +24,7 @@ #include "lang.h" #include "action.h" #include "talk.h" +#include "font.h" /* * Initializes the yesno asker @@ -111,8 +112,13 @@ bool result_displayed; struct gui_yesno yn[NB_SCREENS]; long talked_tick = 0; + int old_font[NB_SCREENS]; FOR_NB_SCREENS(i) { +#ifdef HAVE_LCD_BITMAP + old_font[i]=screens[i].getfont(); + screens[i].setfont(FONT_MENU); +#endif gui_yesno_init(&(yn[i]), main_message, yes_message, no_message); gui_yesno_set_display(&(yn[i]), &(screens[i])); gui_yesno_draw(&(yn[i])); @@ -137,8 +143,15 @@ /* ignore some SYS events that can happen */ continue; default: - if(default_event_handler(button) == SYS_USB_CONNECTED) + if(default_event_handler(button) == SYS_USB_CONNECTED){ +#ifdef HAVE_LCD_BITMAP + FOR_NB_SCREENS(i) + { + screens[i].setfont(old_font[i]); + } +#endif return(YESNO_USB); + } result = YESNO_NO; } } @@ -154,5 +167,13 @@ } if(result_displayed) sleep(HZ); + +#ifdef HAVE_LCD_BITMAP + FOR_NB_SCREENS(i) + { + screens[i].setfont(old_font[i]); + } +#endif + return(result); } diff -u -r rockbox_svn.orig/apps/plugin.c rockbox_svn/apps/plugin.c --- rockbox_svn.orig/apps/plugin.c 2008-01-07 21:40:00.000000000 -0600 +++ rockbox_svn/apps/plugin.c 2008-01-08 16:48:27.000000000 -0600 @@ -94,6 +94,7 @@ lcd_set_drawmode, lcd_get_drawmode, lcd_setfont, + lcd_getfont, lcd_drawpixel, lcd_drawline, lcd_hline, @@ -148,6 +149,7 @@ lcd_remote_set_drawmode, lcd_remote_get_drawmode, lcd_remote_setfont, + lcd_remote_getfont, lcd_remote_getstringsize, lcd_remote_drawpixel, lcd_remote_drawline, diff -u -r rockbox_svn.orig/apps/plugin.h rockbox_svn/apps/plugin.h --- rockbox_svn.orig/apps/plugin.h 2008-01-07 21:40:00.000000000 -0600 +++ rockbox_svn/apps/plugin.h 2008-01-08 16:48:27.000000000 -0600 @@ -164,6 +164,7 @@ void (*lcd_set_drawmode)(int mode); int (*lcd_get_drawmode)(void); void (*lcd_setfont)(int font); + int (*lcd_getfont)(void); void (*lcd_drawpixel)(int x, int y); void (*lcd_drawline)(int x1, int y1, int x2, int y2); void (*lcd_hline)(int x1, int x2, int y); @@ -194,8 +195,8 @@ int width, int height); #endif unsigned short *(*bidi_l2v)( const unsigned char *str, int orientation ); - const unsigned char *(*font_get_bits)( struct font *pf, unsigned short char_code ); - struct font* (*font_load)(const char *path); + const unsigned char *(*font_get_bits)( struct font *pf, unsigned short char_code, int font ); + struct font* (*font_load)(const char *path, int font); void (*lcd_puts_style)(int x, int y, const unsigned char *str, int style); void (*lcd_puts_scroll_style)(int x, int y, const unsigned char* string, int style); @@ -210,7 +211,7 @@ struct font* (*font_get)(int font); int (*font_getstringsize)(const unsigned char *str, int *w, int *h, int fontnumber); - int (*font_get_width)(struct font* pf, unsigned short char_code); + int (*font_get_width)(struct font* pf, unsigned short char_code, int font); void (*screen_clear_area)(struct screen * display, int xstart, int ystart, int width, int height); #endif @@ -233,6 +234,7 @@ void (*lcd_remote_set_drawmode)(int mode); int (*lcd_remote_get_drawmode)(void); void (*lcd_remote_setfont)(int font); + int (*lcd_remote_getfont)(void); int (*lcd_remote_getstringsize)(const unsigned char *str, int *w, int *h); void (*lcd_remote_drawpixel)(int x, int y); void (*lcd_remote_drawline)(int x1, int y1, int x2, int y2); diff -u -r rockbox_svn.orig/apps/plugins/bounce.c rockbox_svn/apps/plugins/bounce.c --- rockbox_svn.orig/apps/plugins/bounce.c 2008-01-05 18:10:57.000000000 -0600 +++ rockbox_svn/apps/plugins/bounce.c 2008-01-08 16:48:27.000000000 -0600 @@ -538,7 +538,7 @@ } while(h > 0); rb->lcd_set_drawmode(DRMODE_SOLID); - rb->lcd_setfont(FONT_UI); + rb->lcd_setfont(FONT_PLUGIN); return (h == 0) ? PLUGIN_OK : PLUGIN_USB_CONNECTED; } diff -u -r rockbox_svn.orig/apps/plugins/brickmania.c rockbox_svn/apps/plugins/brickmania.c --- rockbox_svn.orig/apps/plugins/brickmania.c 2008-01-05 18:10:57.000000000 -0600 +++ rockbox_svn/apps/plugins/brickmania.c 2008-01-08 16:48:27.000000000 -0600 @@ -1972,7 +1972,7 @@ configfile_save(HIGH_SCORE,config,1,0); /* Restore user's original backlight setting */ - rb->lcd_setfont(FONT_UI); + rb->lcd_setfont(FONT_PLUGIN); /* Turn on backlight timeout (revert to settings) */ backlight_use_settings(rb); /* backlight control in lib/helper.c */ diff -u -r rockbox_svn.orig/apps/plugins/bubbles.c rockbox_svn/apps/plugins/bubbles.c --- rockbox_svn.orig/apps/plugins/bubbles.c 2008-01-05 18:10:57.000000000 -0600 +++ rockbox_svn/apps/plugins/bubbles.c 2008-01-08 16:48:27.000000000 -0600 @@ -2664,7 +2664,7 @@ break; case BB_USB: - rb->lcd_setfont(FONT_UI); + rb->lcd_setfont(FONT_PLUGIN); return PLUGIN_USB_CONNECTED; case BB_QUIT: @@ -2680,7 +2680,7 @@ } } - rb->lcd_setfont(FONT_UI); + rb->lcd_setfont(FONT_PLUGIN); return PLUGIN_OK; } diff -u -r rockbox_svn.orig/apps/plugins/credits.c rockbox_svn/apps/plugins/credits.c --- rockbox_svn.orig/apps/plugins/credits.c 2008-01-05 18:10:57.000000000 -0600 +++ rockbox_svn/apps/plugins/credits.c 2008-01-08 16:48:27.000000000 -0600 @@ -163,7 +163,7 @@ /* control if scrolling is automatic (with animation) or manual */ bool manual_scroll = false; - rb->lcd_setfont(FONT_UI); + rb->lcd_setfont(FONT_PLUGIN); rb->lcd_clear_display(); rb->lcd_update(); diff -u -r rockbox_svn.orig/apps/plugins/jewels.c rockbox_svn/apps/plugins/jewels.c --- rockbox_svn.orig/apps/plugins/jewels.c 2008-01-05 18:10:57.000000000 -0600 +++ rockbox_svn/apps/plugins/jewels.c 2008-01-08 16:48:27.000000000 -0600 @@ -1832,7 +1832,7 @@ break; case BJ_USB: - rb->lcd_setfont(FONT_UI); + rb->lcd_setfont(FONT_PLUGIN); return PLUGIN_USB_CONNECTED; case BJ_QUIT: @@ -1862,7 +1862,7 @@ } } - rb->lcd_setfont(FONT_UI); + rb->lcd_setfont(FONT_PLUGIN); return PLUGIN_OK; } diff -u -r rockbox_svn.orig/apps/plugins/jpeg.c rockbox_svn/apps/plugins/jpeg.c --- rockbox_svn.orig/apps/plugins/jpeg.c 2008-01-05 18:10:57.000000000 -0600 +++ rockbox_svn/apps/plugins/jpeg.c 2008-01-08 16:48:27.000000000 -0600 @@ -3064,7 +3064,7 @@ rb->lcd_puts(0,3,"Left/Right: Skip File."); rb->lcd_puts(0,4,"Off: Quit."); rb->lcd_update(); - rb->lcd_setfont(FONT_UI); + rb->lcd_setfont(FONT_PLUGIN); rb->button_clear_queue(); diff -u -r rockbox_svn.orig/apps/plugins/mp3_encoder.c rockbox_svn/apps/plugins/mp3_encoder.c --- rockbox_svn.orig/apps/plugins/mp3_encoder.c 2008-01-05 18:10:57.000000000 -0600 +++ rockbox_svn/apps/plugins/mp3_encoder.c 2008-01-08 16:48:27.000000000 -0600 @@ -2409,7 +2409,7 @@ rb->sleep(5*HZ); } - rb->lcd_setfont(FONT_UI); + rb->lcd_setfont(FONT_PLUGIN); #ifdef HAVE_ADJUSTABLE_CPU_FREQ rb->cpu_boost(false); #endif diff -u -r rockbox_svn.orig/apps/plugins/mpegplayer/mpegplayer.c rockbox_svn/apps/plugins/mpegplayer/mpegplayer.c --- rockbox_svn.orig/apps/plugins/mpegplayer/mpegplayer.c 2008-01-07 21:39:59.000000000 -0600 +++ rockbox_svn/apps/plugins/mpegplayer/mpegplayer.c 2008-01-08 16:54:17.000000000 -0600 @@ -458,14 +458,14 @@ const unsigned char *bits; /* get proportional width and glyph bits */ - width = rb->font_get_width(pf, ch); + width = rb->font_get_width(pf, ch, current_vp->font); if (ofs > width) { ofs -= width; continue; } - bits = rb->font_get_bits(pf, ch); + bits = rb->font_get_bits(pf, ch, current_vp->font); draw_oriented_mono_bitmap_part(bits, ofs, 0, width, x, y, width - ofs, pf->height); Only in rockbox_svn/apps/plugins/mpegplayer: mpegplayer.c~ diff -u -r rockbox_svn.orig/apps/plugins/robotfindskitten.c rockbox_svn/apps/plugins/robotfindskitten.c --- rockbox_svn.orig/apps/plugins/robotfindskitten.c 2008-01-05 18:10:57.000000000 -0600 +++ rockbox_svn/apps/plugins/robotfindskitten.c 2008-01-08 16:48:27.000000000 -0600 @@ -629,6 +629,6 @@ play_game(); - rb->lcd_setfont(FONT_UI); + rb->lcd_setfont(FONT_PLUGIN); return PLUGIN_OK; } diff -u -r rockbox_svn.orig/apps/plugins/rockblox.c rockbox_svn/apps/plugins/rockblox.c --- rockbox_svn.orig/apps/plugins/rockblox.c 2008-01-05 18:10:57.000000000 -0600 +++ rockbox_svn/apps/plugins/rockblox.c 2008-01-08 16:48:27.000000000 -0600 @@ -1112,7 +1112,7 @@ ret = rockblox_loop (); #ifdef HAVE_LCD_BITMAP - rb->lcd_setfont (FONT_UI); + rb->lcd_setfont (FONT_BROWSER); #else pgfx_release(); #endif diff -u -r rockbox_svn.orig/apps/plugins/rockpaint.c rockbox_svn/apps/plugins/rockpaint.c --- rockbox_svn.orig/apps/plugins/rockpaint.c 2008-01-05 18:10:57.000000000 -0600 +++ rockbox_svn/apps/plugins/rockpaint.c 2008-01-08 16:48:27.000000000 -0600 @@ -402,10 +402,13 @@ { unsigned short ch; unsigned short *ucs; + int curfont=FONT_PLUGIN; - struct font *pf = rb->font_get( FONT_UI ); - if( !pf ) pf = rb->font_get( FONT_SYSFIXED ); - + struct font *pf = rb->font_get( FONT_PLUGIN ); + if( !pf ) { + pf = rb->font_get( FONT_SYSFIXED ); + curfont=FONT_SYSFIXED; + } ucs = rb->bidi_l2v( str, 1 ); while( (ch = *ucs++) != 0 && x < buf_width ) @@ -414,7 +417,7 @@ const unsigned char *bits; /* get proportional width and glyph bits */ - width = rb->font_get_width( pf, ch ); + width = rb->font_get_width( pf, ch, curfont ); if( ofs > width ) { @@ -422,7 +425,7 @@ continue; } - bits = rb->font_get_bits( pf, ch ); + bits = rb->font_get_bits( pf, ch, curfont ); buffer_mono_bitmap_part( buf, buf_width, buf_height, bits, ofs, 0, width, x, y, width - ofs, pf->height); @@ -843,7 +846,7 @@ rb->snprintf( old_font, MAX_PATH, FONT_DIR "/%s.fnt", - rb->global_settings->font_file ); + rb->global_settings->browserfont ); while( 1 ) { @@ -897,8 +900,8 @@ continue; rb->snprintf( bbuf, MAX_PATH, FONT_DIR "/%s", de->d_name ); - rb->font_load( bbuf ); - rb->font_getstringsize( de->d_name, &fw, &fh, FONT_UI ); + rb->font_load( bbuf, FONT_PLUGIN ); + rb->font_getstringsize( de->d_name, &fw, &fh, FONT_PLUGIN ); if( nvih > 0 ) { nvih -= fh; @@ -932,12 +935,12 @@ { rb->snprintf( bbuf, MAX_PATH, FONT_DIR "/%s", de->d_name ); - rb->font_load( bbuf ); - rb->font_getstringsize( de->d_name, NULL, &fh, FONT_UI ); + rb->font_load( bbuf, FONT_PLUGIN ); + rb->font_getstringsize( de->d_name, NULL, &fh, FONT_PLUGIN ); nvih = fh; } } - rb->font_load( old_font ); + rb->font_load( old_font, FONT_PLUGIN ); rb->closedir( d ); } @@ -1083,7 +1086,7 @@ rb->lcd_putsxy( left + 117, top + 60, str ); rb->snprintf( str, 6, "%d", blue ); rb->lcd_putsxy( left + 117, top + 70, str ); - rb->lcd_setfont( FONT_UI ); + rb->lcd_setfont( FONT_PLUGIN ); #define CURSOR( l ) \ rb->lcd_bitmap_transparent_part( rockpaint_hsvrgb, 1, 1, 16, left+l+1, top+20, 6, 58 ); \ @@ -1479,7 +1482,7 @@ buffer.text.text[0] = '\0'; rb->snprintf( buffer.text.old_font, MAX_PATH, FONT_DIR "/%s.fnt", - rb->global_settings->font_file ); + rb->global_settings->browserfont ); while( 1 ) { int m = TEXT_MENU_TEXT; @@ -1493,7 +1496,7 @@ case TEXT_MENU_FONT: if( browse_fonts( buffer.text.font, MAX_PATH ) ) { - rb->font_load( buffer.text.font ); + rb->font_load( buffer.text.font, FONT_PLUGIN ); } break; @@ -1545,7 +1548,7 @@ buffer.text.text ); case TEXT_MENU_CANCEL: restore_screen(); - rb->font_load( buffer.text.old_font ); + rb->font_load( buffer.text.old_font, FONT_PLUGIN ); return; } } @@ -2305,7 +2308,7 @@ rb->lcd_setfont( FONT_SYSFIXED ); rb->lcd_putsxy( TB_MENU_LEFT, TOP+TB_MENU_TOP, "Menu" ); - rb->lcd_setfont( FONT_UI ); + rb->lcd_setfont( FONT_PLUGIN ); #undef TOP if( update ) rb->lcd_update(); diff -u -r rockbox_svn.orig/apps/plugins/spacerocks.c rockbox_svn/apps/plugins/spacerocks.c --- rockbox_svn.orig/apps/plugins/spacerocks.c 2008-01-05 18:10:57.000000000 -0600 +++ rockbox_svn/apps/plugins/spacerocks.c 2008-01-08 16:48:27.000000000 -0600 @@ -1960,7 +1960,7 @@ iohiscore(); retval = start_game(); iohiscore(); - rb->lcd_setfont(FONT_UI); + rb->lcd_setfont(FONT_PLUGIN); /* Turn on backlight timeout (revert to settings) */ backlight_use_settings(rb); /* backlight control in lib/helper.c */ return retval; diff -u -r rockbox_svn.orig/apps/plugins/stopwatch.c rockbox_svn/apps/plugins/stopwatch.c --- rockbox_svn.orig/apps/plugins/stopwatch.c 2008-01-05 18:10:57.000000000 -0600 +++ rockbox_svn/apps/plugins/stopwatch.c 2008-01-08 16:48:27.000000000 -0600 @@ -195,7 +195,7 @@ #ifdef HAVE_LCD_BITMAP int h; - rb->lcd_setfont(FONT_UI); + rb->lcd_setfont(FONT_PLUGIN); rb->lcd_getstringsize("M", NULL, &h); lines = (LCD_HEIGHT / h) - (LAP_Y); #else diff -u -r rockbox_svn.orig/apps/plugins/viewer.c rockbox_svn/apps/plugins/viewer.c --- rockbox_svn.orig/apps/plugins/viewer.c 2008-01-05 18:10:57.000000000 -0600 +++ rockbox_svn/apps/plugins/viewer.c 2008-01-08 16:48:27.000000000 -0600 @@ -320,7 +320,7 @@ ch = ' '; #ifdef HAVE_LCD_BITMAP - return rb->font_get_width(pf, ch); + return rb->font_get_width(pf, ch, FONT_BROWSER); #else return 1; #endif @@ -1029,8 +1029,9 @@ static bool viewer_init(void) { #ifdef HAVE_LCD_BITMAP - - pf = rb->font_get(FONT_UI); + // MWE + rb->lcd_setfont(FONT_BROWSER); + pf = rb->font_get(FONT_BROWSER); display_lines = LCD_HEIGHT / pf->height; draw_columns = display_columns = LCD_WIDTH; diff -u -r rockbox_svn.orig/apps/plugins/xobox.c rockbox_svn/apps/plugins/xobox.c --- rockbox_svn.orig/apps/plugins/xobox.c 2008-01-05 18:10:57.000000000 -0600 +++ rockbox_svn/apps/plugins/xobox.c 2008-01-08 16:48:27.000000000 -0600 @@ -947,7 +947,7 @@ /* Turn on backlight timeout (revert to settings) */ backlight_use_settings(rb); /* backlight control in lib/helper.c */ - rb->lcd_setfont (FONT_UI); + rb->lcd_setfont (FONT_PLUGIN); return ret; } diff -u -r rockbox_svn.orig/apps/plugins/zxbox/zxbox_keyb.c rockbox_svn/apps/plugins/zxbox/zxbox_keyb.c --- rockbox_svn.orig/apps/plugins/zxbox/zxbox_keyb.c 2008-01-05 18:08:49.000000000 -0600 +++ rockbox_svn/apps/plugins/zxbox/zxbox_keyb.c 2008-01-08 16:48:27.000000000 -0600 @@ -198,13 +198,13 @@ rb->screens[l]->setfont(param[l].curfont); /* find max width of keyboard glyphs */ for (i=0; ifont_get_width(param[l].font, param[l].kbd_buf[i]); + w = rb->font_get_width(param[l].font, param[l].kbd_buf[i], FONT_PLUGIN); if (w > param[l].font_w) param[l].font_w = w; } /* Since we're going to be adding spaces, make sure that we check * their width too */ - w = rb->font_get_width( param[l].font, ' ' ); + w = rb->font_get_width( param[l].font, ' ', FONT_PLUGIN ); if( w > param[l].font_w ) param[l].font_w = w; } @@ -256,7 +256,7 @@ text_w = param[l].font_w; while (*utf8) { utf8 = (unsigned char*)rb->utf8decode(utf8, &ch); - w = rb->font_get_width(param[l].font, ch); + w = rb->font_get_width(param[l].font, ch, FONT_SYSFIXED); if (w > text_w) text_w = w; } @@ -387,7 +387,7 @@ case KBD_ABORT: FOR_NB_SCREENS(l) - rb->screens[l]->setfont(FONT_UI); + rb->screens[l]->setfont(FONT_SYSFIXED); return -1; break; @@ -506,6 +506,6 @@ } } FOR_NB_SCREENS(l) - rb->screens[l]->setfont(FONT_UI); + rb->screens[l]->setfont(FONT_SYSFIXED); return 0; } diff -u -r rockbox_svn.orig/apps/recorder/keyboard.c rockbox_svn/apps/recorder/keyboard.c --- rockbox_svn.orig/apps/recorder/keyboard.c 2008-01-05 18:07:57.000000000 -0600 +++ rockbox_svn/apps/recorder/keyboard.c 2008-01-08 16:48:27.000000000 -0600 @@ -372,7 +372,7 @@ } else { - pm->curfont = FONT_UI; + pm->curfont = FONT_MENU; } } @@ -398,14 +398,14 @@ /* find max width of keyboard glyphs */ for (i = 0; i < pm->nchars; i++) { - w = font_get_width(pm->font, pm->kbd_buf[i]); + w = font_get_width(pm->font, pm->kbd_buf[i], param[l].curfont); if ( w > pm->font_w ) pm->font_w = w; } /* Since we're going to be adding spaces, make sure that we check * their width too */ - w = font_get_width( pm->font, ' ' ); + w = font_get_width( pm->font, ' ', param[l].curfont ); if ( w > pm->font_w ) pm->font_w = w; } @@ -473,7 +473,7 @@ while (*utf8) { - int w = font_get_width(pm->font, ch); + int w = font_get_width(pm->font, ch, param[l].curfont); utf8 = (unsigned char*)utf8decode(utf8, &ch); if (w > text_w) @@ -765,8 +765,6 @@ switch ( button ) { case ACTION_KBD_ABORT: - FOR_NB_SCREENS(l) - screens[l].setfont(FONT_UI); #ifdef HAS_BUTTONBAR global_settings.buttonbar=buttonbar_config; diff -u -r rockbox_svn.orig/apps/recorder/radio.c rockbox_svn/apps/recorder/radio.c --- rockbox_svn.orig/apps/recorder/radio.c 2008-01-05 18:07:57.000000000 -0600 +++ rockbox_svn/apps/recorder/radio.c 2008-01-08 16:48:27.000000000 -0600 @@ -465,13 +465,14 @@ global_settings.statusbar = true; FOR_NB_SCREENS(i) { + screens[i].setfont(FONT_TUNER); gui_textarea_clear(&screens[i]); screen_set_xmargin(&screens[i],0); } gui_syncstatusbar_draw(&statusbars,true); - fh = font_get(FONT_UI)->height; + fh = font_get(FONT_TUNER)->height; /* Adjust for font size, trying to center the information vertically */ if(fh < 10) @@ -887,7 +888,7 @@ int freq; FOR_NB_SCREENS(i) - screens[i].setfont(FONT_UI); + screens[i].setfont(FONT_TUNER); snprintf(buf, 128, curr_preset >= 0 ? "%d. %s" : " ", curr_preset + 1, presets[curr_preset].name); diff -u -r rockbox_svn.orig/apps/recorder/recording.c rockbox_svn/apps/recorder/recording.c --- rockbox_svn.orig/apps/recorder/recording.c 2008-01-05 18:07:57.000000000 -0600 +++ rockbox_svn/apps/recorder/recording.c 2008-01-08 16:48:27.000000000 -0600 @@ -949,7 +949,7 @@ FOR_NB_SCREENS(i) { - screens[i].setfont(FONT_SYSFIXED); + screens[i].setfont(FONT_RECORD); screens[i].getstringsize("M", &w, &h); screens[i].setmargins(global_settings.cursor_style ? 0 : w, 8); filename_offset[i] = ((screens[i].height >= 80) ? 1 : 0); @@ -1355,7 +1355,7 @@ FOR_NB_SCREENS(i) { - screens[i].setfont(FONT_SYSFIXED); + screens[i].setfont(FONT_RECORD); screens[i].setmargins( global_settings.cursor_style ? 0 : w, 8); } @@ -1435,7 +1435,7 @@ #endif FOR_NB_SCREENS(i) - screens[i].setfont(FONT_SYSFIXED); + screens[i].setfont(FONT_RECORD); seconds = audio_recorded_time() / HZ; @@ -1942,9 +1942,6 @@ rec_status &= ~RCSTAT_IN_RECSCREEN; sound_settings_apply(); - FOR_NB_SCREENS(i) - screens[i].setfont(FONT_UI); - /* if the directory was created or recording happened, make sure the browser is updated */ if (rec_status & (RCSTAT_CREATED_DIRECTORY | RCSTAT_HAVE_RECORDED)) @@ -1981,7 +1978,7 @@ FOR_NB_SCREENS(i) { - screens[i].setfont(FONT_SYSFIXED); + screens[i].setfont(FONT_RECORD); screens[i].getstringsize("A",&w,&h); } @@ -2094,8 +2091,6 @@ set_gain(); settings_save(); - FOR_NB_SCREENS(i) - screens[i].setfont(FONT_UI); return false; } @@ -2116,7 +2111,7 @@ FOR_NB_SCREENS(i) { - screens[i].setfont(FONT_SYSFIXED); + screens[i].setfont(FONT_RECORD); screens[i].getstringsize("A",&w,&h); } @@ -2191,8 +2186,6 @@ set_gain(); settings_save(); - FOR_NB_SCREENS(i) - screens[i].setfont(FONT_UI); return false; } diff -u -r rockbox_svn.orig/apps/root_menu.c rockbox_svn/apps/root_menu.c --- rockbox_svn.orig/apps/root_menu.c 2008-01-05 18:13:01.000000000 -0600 +++ rockbox_svn/apps/root_menu.c 2008-01-08 16:48:27.000000000 -0600 @@ -497,6 +497,10 @@ void root_menu(void) { +#ifdef HAVE_LCD_BITMAP + gui_list_context = GUI_LIST_CONTEXT_MENU; /* Set menu font */ +#endif + int previous_browser = GO_TO_FILEBROWSER; int next_screen = GO_TO_ROOT; int selected = 0; @@ -538,6 +542,9 @@ case MENU_SELECTED_EXIT: /* fall through */ case GO_TO_ROOT: +#ifdef HAVE_LCD_BITMAP + gui_list_context = GUI_LIST_CONTEXT_MENU; /* Set menu font */ +#endif if (last_screen != GO_TO_ROOT) selected = get_selection(last_screen); next_screen = do_menu(&root_menu_, &selected); diff -u -r rockbox_svn.orig/apps/screen_access.c rockbox_svn/apps/screen_access.c --- rockbox_svn.orig/apps/screen_access.c 2008-01-08 13:45:06.000000000 -0600 +++ rockbox_svn/apps/screen_access.c 2008-01-08 16:48:27.000000000 -0600 @@ -230,9 +230,6 @@ int i; FOR_NB_SCREENS(i) { -#ifdef HAVE_LCD_BITMAP - ((struct screen*)&screens[i])->setfont(FONT_UI); -#endif gui_textarea_update_nblines(&screens[i]); } } Only in rockbox_svn/apps: screen_access.c~ diff -u -r rockbox_svn.orig/apps/screens.c rockbox_svn/apps/screens.c --- rockbox_svn.orig/apps/screens.c 2008-01-05 18:13:01.000000000 -0600 +++ rockbox_svn/apps/screens.c 2008-01-08 16:48:27.000000000 -0600 @@ -631,7 +631,6 @@ #if CONFIG_CODEC == SWCODEC pcmbuf_set_low_latency(false); #endif - lcd_setfont(FONT_UI); return 0; } #endif /* HAVE_PITCHSCREEN */ diff -u -r rockbox_svn.orig/apps/settings.c rockbox_svn/apps/settings.c --- rockbox_svn.orig/apps/settings.c 2008-01-08 17:00:41.000000000 -0600 +++ rockbox_svn/apps/settings.c 2008-01-08 16:48:27.000000000 -0600 @@ -263,6 +263,32 @@ return false; } +/** reset some settings when loading a wps file + * to keep backward compatibility **/ +void theme_settings_reset(void) +{ + /* multifont settings */ + global_settings.font_file[0] = '\0'; + global_settings.browserfont[0] = '\0'; + global_settings.wpsfont[0] = '\0'; + global_settings.menufont[0] = '\0'; +#ifdef CONFIG_TUNER + global_settings.tunerfont[0] = '\0'; +#endif +#ifdef HAVE_RECORDING + global_settings.recordfont[0] = '\0'; +#endif + /* reset rpws setting */ +#ifdef HAVE_REMOTE_LCD + global_settings.rwps_file[0]='\0'; +#endif + /* reset color settings */ +#ifdef HAVE_LCD_COLOR + global_settings.fg_color=LCD_DEFAULT_FG; + global_settings.bg_color=LCD_DEFAULT_BG; +#endif +} + bool settings_load_config(const char* file, bool apply) { int fd; @@ -274,6 +300,11 @@ if (fd < 0) return false; + /* if loading a theme reset some settings for backward compatibility */ + if(strncmp(file, THEME_DIR, strlen(THEME_DIR))==0){ + theme_settings_reset(); + } + while (read_line(fd, line, sizeof line) > 0) { if (!settings_parseline(line, &name, &value)) @@ -724,6 +755,8 @@ #if CONFIG_CODEC == SWCODEC int i; #endif + /** backward comp **/ + bool useMultifont=false; DEBUGF( "settings_apply()\n" ); sound_settings_apply(); @@ -855,13 +888,153 @@ #endif #ifdef HAVE_LCD_BITMAP - if ( global_settings.font_file[0]) { + /* Load all the fonts */ + if ( global_settings.browserfont[0] && + global_settings.browserfont[0] != 0xff ) { + useMultifont=true; + snprintf(buf, sizeof buf, FONT_DIR "/%s.fnt", + global_settings.browserfont); + font_load(buf, FONT_BROWSER); + } + else + font_reset(FONT_BROWSER); + + if ( global_settings.wpsfont[0] && + global_settings.wpsfont[0] != 0xff ) { + useMultifont=true; + snprintf(buf, sizeof buf, FONT_DIR "/%s.fnt", + global_settings.wpsfont); + font_load(buf, FONT_WPS); + } + else + font_reset(FONT_WPS); + + if ( global_settings.menufont[0] && + global_settings.menufont[0] != 0xff ) { + useMultifont=true; + snprintf(buf, sizeof buf, FONT_DIR "/%s.fnt", + global_settings.menufont); + font_load(buf, FONT_MENU); + } + else + font_reset(FONT_MENU); + +#ifdef CONFIG_TUNER + if ( global_settings.tunerfont[0] && + global_settings.tunerfont[0] != 0xff ) { + useMultifont=true; + snprintf(buf, sizeof buf, FONT_DIR "/%s.fnt", + global_settings.tunerfont); + font_load(buf, FONT_TUNER); + } + else + font_reset(FONT_TUNER); +#endif /* CONFIG_TUNER */ + +#ifdef HAVE_RECORDING + if ( global_settings.recordfont[0] && + global_settings.recordfont[0] != 0xff ) { + useMultifont=true; + snprintf(buf, sizeof buf, FONT_DIR "/%s.fnt", + global_settings.recordfont); + font_load(buf, FONT_RECORD); + } + else + font_reset(FONT_RECORD); +#endif /* HAVE_RECORDING */ + + /** backward comp **/ + if(!useMultifont){ + if ( global_settings.font_file[0] && + global_settings.font_file[0] != 0xff ) { + snprintf(buf, sizeof buf, FONT_DIR "/%s.fnt", + global_settings.font_file); + font_load(buf, FONT_BROWSER); + font_load(buf, FONT_WPS); + font_load(buf, FONT_MENU); +#ifdef CONFIG_TUNER + font_load(buf, FONT_TUNER); +#endif +#ifdef HAVE_RECORDING + font_load(buf, FONT_RECORD); +#endif + } + else { + font_reset(FONT_BROWSER); + font_reset(FONT_WPS); + font_reset(FONT_MENU); +#ifdef CONFIG_TUNER + font_reset(FONT_TUNER); +#endif +#ifdef HAVE_RECORDING + font_reset(FONT_RECORD); +#endif + } + } + + /* Load all user fonts */ + if ( global_settings.userfont1[0] && + global_settings.userfont1[0] != 0xff ) { snprintf(buf, sizeof buf, FONT_DIR "/%s.fnt", - global_settings.font_file); - font_load(buf); + global_settings.userfont1); + font_load(buf, FONT_USER1); } else - font_reset(); + font_reset(FONT_USER1); + + if ( global_settings.userfont2[0] && + global_settings.userfont2[0] != 0xff ) { + snprintf(buf, sizeof buf, FONT_DIR "/%s.fnt", + global_settings.userfont2); + font_load(buf, FONT_USER2); + } + else + font_reset(FONT_USER2); + + if ( global_settings.userfont3[0] && + global_settings.userfont3[0] != 0xff ) { + snprintf(buf, sizeof buf, FONT_DIR "/%s.fnt", + global_settings.userfont3); + font_load(buf, FONT_USER3); + } + else + font_reset(FONT_USER3); + + if ( global_settings.userfont4[0] && + global_settings.userfont4[0] != 0xff ) { + snprintf(buf, sizeof buf, FONT_DIR "/%s.fnt", + global_settings.userfont4); + font_load(buf, FONT_USER4); + } + else + font_reset(FONT_USER4); + + if ( global_settings.userfont5[0] && + global_settings.userfont5[0] != 0xff ) { + snprintf(buf, sizeof buf, FONT_DIR "/%s.fnt", + global_settings.userfont5); + font_load(buf, FONT_USER5); + } + else + font_reset(FONT_USER5); + + if ( global_settings.userfont6[0] && + global_settings.userfont6[0] != 0xff ) { + snprintf(buf, sizeof buf, FONT_DIR "/%s.fnt", + global_settings.userfont6); + font_load(buf, FONT_USER6); + } + else + font_reset(FONT_USER6); + + if ( global_settings.userfont7[0] && + global_settings.userfont7[0] != 0xff ) { + snprintf(buf, sizeof buf, FONT_DIR "/%s.fnt", + global_settings.userfont7); + font_load(buf, FONT_USER7); + } + else + font_reset(FONT_USER7); if ( global_settings.kbd_file[0]) { snprintf(buf, sizeof buf, ROCKBOX_DIR "/%s.kbd", @@ -975,6 +1148,13 @@ #if defined (HAVE_RECORDING) && CONFIG_CODEC == SWCODEC enc_global_settings_reset(); #endif + global_settings.userfont1[0] = '\0'; + global_settings.userfont2[0] = '\0'; + global_settings.userfont3[0] = '\0'; + global_settings.userfont4[0] = '\0'; + global_settings.userfont5[0] = '\0'; + global_settings.userfont6[0] = '\0'; + global_settings.userfont7[0] = '\0'; } /** Changing setting values **/ @@ -1049,14 +1229,15 @@ void set_file(char* filename, char* setting, int maxlen) { - char* fptr = strrchr(filename,'/'); + char *fptr = strrchr(filename,'/'); int len; int extlen = 0; - char* ptr; + char *ptr, *oldptr; if (!fptr) return; + oldptr = fptr; *fptr = 0; fptr++; diff -u -r rockbox_svn.orig/apps/settings.h rockbox_svn/apps/settings.h --- rockbox_svn.orig/apps/settings.h 2008-01-05 18:13:01.000000000 -0600 +++ rockbox_svn/apps/settings.h 2008-01-08 16:48:27.000000000 -0600 @@ -411,7 +411,26 @@ #if CONFIG_TUNER unsigned char fmr_file[MAX_FILENAME+1]; /* last fmr preset */ #endif - unsigned char font_file[MAX_FILENAME+1]; /* last font */ + unsigned char font_file[MAX_FILENAME+1]; /* backward comp */ + + unsigned char browserfont[MAX_FILENAME+1]; /* UI fonts */ + unsigned char wpsfont[MAX_FILENAME+1]; + unsigned char menufont[MAX_FILENAME+1]; +#ifdef CONFIG_TUNER + unsigned char tunerfont[MAX_FILENAME+1]; +#endif +#ifdef HAVE_RECORDING + unsigned char recordfont[MAX_FILENAME+1]; +#endif + + unsigned char userfont1[MAX_FILENAME+1]; + unsigned char userfont2[MAX_FILENAME+1]; + unsigned char userfont3[MAX_FILENAME+1]; + unsigned char userfont4[MAX_FILENAME+1]; + unsigned char userfont5[MAX_FILENAME+1]; + unsigned char userfont6[MAX_FILENAME+1]; + unsigned char userfont7[MAX_FILENAME+1]; + unsigned char wps_file[MAX_FILENAME+1]; /* last wps */ unsigned char lang_file[MAX_FILENAME+1]; /* last language */ diff -u -r rockbox_svn.orig/apps/settings_list.c rockbox_svn/apps/settings_list.c --- rockbox_svn.orig/apps/settings_list.c 2008-01-05 18:13:01.000000000 -0600 +++ rockbox_svn/apps/settings_list.c 2008-01-08 16:48:27.000000000 -0600 @@ -468,6 +468,13 @@ false, "force fm mono", toggle_mono_mode), SYSTEM_SETTING(NVRAM(4),last_frequency,0), #endif + FILENAME_SETTING(F_THEMESETTING,userfont1,"userfont1","",FONT_DIR "/",".fnt",MAX_FILENAME+1), + FILENAME_SETTING(F_THEMESETTING,userfont2,"userfont2","",FONT_DIR "/",".fnt",MAX_FILENAME+1), + FILENAME_SETTING(F_THEMESETTING,userfont3,"userfont3","",FONT_DIR "/",".fnt",MAX_FILENAME+1), + FILENAME_SETTING(F_THEMESETTING,userfont4,"userfont4","",FONT_DIR "/",".fnt",MAX_FILENAME+1), + FILENAME_SETTING(F_THEMESETTING,userfont5,"userfont5","",FONT_DIR "/",".fnt",MAX_FILENAME+1), + FILENAME_SETTING(F_THEMESETTING,userfont6,"userfont6","",FONT_DIR "/",".fnt",MAX_FILENAME+1), + FILENAME_SETTING(F_THEMESETTING,userfont7,"userfont7","",FONT_DIR "/",".fnt",MAX_FILENAME+1), #if BATTERY_TYPES_COUNT > 1 CHOICE_SETTING(0, battery_type, LANG_BATTERY_TYPE, 0, @@ -1081,8 +1088,20 @@ FILENAME_SETTING(0, fmr_file, "fmr", "", FMPRESET_PATH "/", ".fmr", MAX_FILENAME+1), #endif - FILENAME_SETTING(F_THEMESETTING, font_file, "font", - "", FONT_DIR "/", ".fnt", MAX_FILENAME+1), + + /** backward comp **/ + FILENAME_SETTING(F_THEMESETTING,font_file,"font","",FONT_DIR "/",".fnt",MAX_FILENAME+1), + + FILENAME_SETTING(F_THEMESETTING,browserfont,"browserfont","",FONT_DIR "/",".fnt",MAX_FILENAME+1), + FILENAME_SETTING(F_THEMESETTING,wpsfont,"wpsfont","",FONT_DIR "/",".fnt",MAX_FILENAME+1), + FILENAME_SETTING(F_THEMESETTING,menufont,"menufont","",FONT_DIR "/",".fnt",MAX_FILENAME+1), +#ifdef HAVE_RECORDING + FILENAME_SETTING(F_THEMESETTING,recordfont,"recordfont","",FONT_DIR "/",".fnt",MAX_FILENAME+1), +#endif +#ifdef CONFIG_TUNER + FILENAME_SETTING(F_THEMESETTING,tunerfont,"tunerfont","",FONT_DIR "/",".fnt",MAX_FILENAME+1), +#endif + FILENAME_SETTING(F_THEMESETTING,wps_file, "wps", "", WPS_DIR "/", ".wps", MAX_FILENAME+1), FILENAME_SETTING(0,lang_file,"lang","",LANG_DIR "/",".lng",MAX_FILENAME+1), diff -u -r rockbox_svn.orig/apps/tree.c rockbox_svn/apps/tree.c --- rockbox_svn.orig/apps/tree.c 2008-01-05 18:13:01.000000000 -0600 +++ rockbox_svn/apps/tree.c 2008-01-08 16:48:27.000000000 -0600 @@ -314,6 +314,10 @@ check_rockboxdir(); +#ifdef HAVE_LCD_BITMAP + gui_list_context = GUI_LIST_CONTEXT_BRWSR; /* Set browser font */ +#endif + strcpy(tc.currdir, "/"); #ifdef HAVE_LCD_CHARCELLS @@ -1043,6 +1047,10 @@ int *last_filter = tc.dirfilter; tc.dirfilter = &dirfilter; +#ifdef HAVE_LCD_BITMAP + gui_list_context = GUI_LIST_CONTEXT_BRWSR; /* Set browser font */ +#endif + reload_dir = true; if (dirfilter >= NUM_FILTER_MODES) { @@ -1070,6 +1078,11 @@ ret_val = dirbrowse(); } tc.dirfilter = last_filter; + +#ifdef HAVE_LCD_BITMAP + gui_list_context = GUI_LIST_CONTEXT_MENU; /* Set menu font */ +#endif + return ret_val; } diff -u -r rockbox_svn.orig/firmware/drivers/lcd-16bit.c rockbox_svn/firmware/drivers/lcd-16bit.c --- rockbox_svn.orig/firmware/drivers/lcd-16bit.c 2008-01-07 21:40:02.000000000 -0600 +++ rockbox_svn/firmware/drivers/lcd-16bit.c 2008-01-08 16:48:27.000000000 -0600 @@ -926,7 +926,7 @@ const unsigned char *bits; /* get proportional width and glyph bits */ - width = font_get_width(pf,ch); + width = font_get_width(pf,ch,current_vp->font); if (ofs > width) { @@ -934,7 +934,7 @@ continue; } - bits = font_get_bits(pf, ch); + bits = font_get_bits(pf, ch, current_vp->font); lcd_mono_bitmap_part(bits, ofs, 0, width, x, y, width - ofs, pf->height); diff -u -r rockbox_svn.orig/firmware/drivers/lcd-2bit-horz.c rockbox_svn/firmware/drivers/lcd-2bit-horz.c --- rockbox_svn.orig/firmware/drivers/lcd-2bit-horz.c 2008-01-07 21:40:02.000000000 -0600 +++ rockbox_svn/firmware/drivers/lcd-2bit-horz.c 2008-01-08 16:48:27.000000000 -0600 @@ -897,7 +897,7 @@ const unsigned char *bits; /* get proportional width and glyph bits */ - width = font_get_width(pf,ch); + width = font_get_width(pf,ch,current_vp->font); if (ofs > width) { @@ -905,7 +905,7 @@ continue; } - bits = font_get_bits(pf, ch); + bits = font_get_bits(pf, ch, current_vp->font); lcd_mono_bitmap_part(bits, ofs, 0, width, x, y, width - ofs, pf->height); diff -u -r rockbox_svn.orig/firmware/drivers/lcd-2bit-vert.c rockbox_svn/firmware/drivers/lcd-2bit-vert.c --- rockbox_svn.orig/firmware/drivers/lcd-2bit-vert.c 2008-01-07 21:40:02.000000000 -0600 +++ rockbox_svn/firmware/drivers/lcd-2bit-vert.c 2008-01-08 16:48:27.000000000 -0600 @@ -1035,7 +1035,7 @@ const unsigned char *bits; /* get proportional width and glyph bits */ - width = font_get_width(pf,ch); + width = font_get_width(pf,ch, current_vp->font); if (ofs > width) { @@ -1043,7 +1043,7 @@ continue; } - bits = font_get_bits(pf, ch); + bits = font_get_bits(pf, ch, current_vp->font); lcd_mono_bitmap_part(bits, ofs, 0, width, x, y, width - ofs, pf->height); diff -u -r rockbox_svn.orig/firmware/drivers/lcd-remote-1bit-v.c rockbox_svn/firmware/drivers/lcd-remote-1bit-v.c --- rockbox_svn.orig/firmware/drivers/lcd-remote-1bit-v.c 2008-01-07 21:40:02.000000000 -0600 +++ rockbox_svn/firmware/drivers/lcd-remote-1bit-v.c 2008-01-08 16:48:27.000000000 -0600 @@ -682,7 +682,7 @@ const unsigned char *bits; /* get proportional width and glyph bits */ - width = font_get_width(pf, ch); + width = font_get_width(pf, ch, current_vp->font); if (ofs > width) { @@ -690,7 +690,7 @@ continue; } - bits = font_get_bits(pf, ch); + bits = font_get_bits(pf, ch, current_vp->font); lcd_remote_bitmap_part(bits, ofs, 0, width, x, y, width - ofs, pf->height); diff -u -r rockbox_svn.orig/firmware/drivers/lcd-remote-2bit-vi.c rockbox_svn/firmware/drivers/lcd-remote-2bit-vi.c --- rockbox_svn.orig/firmware/drivers/lcd-remote-2bit-vi.c 2008-01-07 21:40:02.000000000 -0600 +++ rockbox_svn/firmware/drivers/lcd-remote-2bit-vi.c 2008-01-08 16:48:27.000000000 -0600 @@ -1031,7 +1031,7 @@ const unsigned char *bits; /* get proportional width and glyph bits */ - width = font_get_width(pf, ch); + width = font_get_width(pf, ch, current_vp->font); if (ofs > width) { @@ -1039,7 +1039,7 @@ continue; } - bits = font_get_bits(pf, ch); + bits = font_get_bits(pf, ch, current_vp->font); lcd_remote_mono_bitmap_part(bits, ofs, 0, width, x, y, width - ofs, pf->height); diff -u -r rockbox_svn.orig/firmware/export/font.h rockbox_svn/firmware/export/font.h --- rockbox_svn.orig/firmware/export/font.h 2008-01-05 18:17:35.000000000 -0600 +++ rockbox_svn/firmware/export/font.h 2008-01-08 16:48:27.000000000 -0600 @@ -46,7 +46,23 @@ #define FONT_HEADER_SIZE 36 #endif -#define GLYPH_CACHE_FILE "/.rockbox/.glyphcache" + +#define GLYPH_CACHE_FILE_BRWSR "/.rockbox/.glyphcache-brwsr" +#define GLYPH_CACHE_FILE_WPS "/.rockbox/.glyphcache-wps" +#define GLYPH_CACHE_FILE_MENU "/.rockbox/.glyphcache-menu" +#ifdef CONFIG_TUNER +#define GLYPH_CACHE_FILE_TUNER "/.rockbox/.glyphcache-tuner" +#endif +#ifdef HAVE_RECORDING +#define GLYPH_CACHE_FILE_RECORD "/.rockbox/.glyphcache-record" +#endif +#define GLYPH_CACHE_FILE_USER1 "/.rockbox/.glyphcache-user1" +#define GLYPH_CACHE_FILE_USER2 "/.rockbox/.glyphcache-user2" +#define GLYPH_CACHE_FILE_USER3 "/.rockbox/.glyphcache-user3" +#define GLYPH_CACHE_FILE_USER4 "/.rockbox/.glyphcache-user4" +#define GLYPH_CACHE_FILE_USER5 "/.rockbox/.glyphcache-user5" +#define GLYPH_CACHE_FILE_USER6 "/.rockbox/.glyphcache-user6" +#define GLYPH_CACHE_FILE_USER7 "/.rockbox/.glyphcache-user7" /* * Fonts are specified by number, and used for display @@ -60,10 +76,29 @@ */ enum { FONT_SYSFIXED, /* system fixed pitch font*/ - FONT_UI, /* system porportional font*/ + FONT_BROWSER, /* Browser font */ + FONT_WPS, /* WPS font */ + FONT_MENU, /* Settings/menu font */ +#ifdef CONFIG_TUNER + FONT_TUNER, /* FM/radio font */ +#endif +#ifdef HAVE_RECORDING + FONT_RECORD, /* Recording font */ +#endif + FONT_USER1, /* User custom fonts for use in wps */ + FONT_USER2, /* User custom fonts for use in wps */ + FONT_USER3, /* User custom fonts for use in wps */ + FONT_USER4, /* User custom fonts for use in wps */ + FONT_USER5, /* User custom fonts for use in wps */ + FONT_USER6, /* User custom fonts for use in wps */ + FONT_USER7, /* User custom fonts for use in wps */ MAXFONTS }; +/* FIXME: Hack to keep things compiling for now */ +#define FONT_PLUGIN FONT_SYSFIXED +#define FONT_UI FONT_SYSFIXED + /* * .fnt loadable font file format definition * @@ -106,13 +141,13 @@ /* font routines*/ void font_init(void); -struct font* font_load(const char *path); +struct font* font_load(const char *path, int font); struct font* font_get(int font); -void font_reset(void); -int font_getstringsize(const unsigned char *str, int *w, int *h, int fontnumber); -int font_get_width(struct font* ft, unsigned short ch); -const unsigned char * font_get_bits(struct font* ft, unsigned short ch); -void glyph_cache_save(void); +void font_reset(int font); +int font_getstringsize(const unsigned char *str, int *w, int *h, int font); +int font_get_width(struct font* ft, unsigned short ch, int font); +const unsigned char * font_get_bits(struct font* ft, unsigned short ch, int font); +void glyph_cache_save(int font); #else /* HAVE_LCD_BITMAP */ diff -u -r rockbox_svn.orig/firmware/font.c rockbox_svn/firmware/font.c --- rockbox_svn.orig/firmware/font.c 2008-01-05 18:18:30.000000000 -0600 +++ rockbox_svn/firmware/font.c 2008-01-08 16:48:27.000000000 -0600 @@ -46,33 +46,81 @@ /* compiled-in font */ extern struct font sysfont; -/* structure filled in by font_load */ -static struct font font_ui; +/* font structures filled in by font_load */ +static struct font browserfont; +static struct font wpsfont; +static struct font menufont; +#ifdef CONFIG_TUNER +static struct font tunerfont; +#endif +#ifdef HAVE_RECORDING +static struct font recordfont; +#endif +static struct font userfont1; +static struct font userfont2; +static struct font userfont3; +static struct font userfont4; +static struct font userfont5; +static struct font userfont6; +static struct font userfont7; /* system font table, in order of FONT_xxx definition */ -static struct font* const sysfonts[MAXFONTS] = { &sysfont, &font_ui }; +static struct font* sysfonts[MAXFONTS] = { + &sysfont, + &browserfont, + &wpsfont, + &menufont, +#ifdef CONFIG_TUNER + &tunerfont, +#endif +#ifdef HAVE_RECORDING + &recordfont, +#endif + &userfont1, + &userfont2, + &userfont3, + &userfont4, + &userfont5, + &userfont6, + &userfont7 + }; /* 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 unsigned char font_membuf[MAXCACHEFONTS][MAX_FONT_SIZE]; /* Sysfont is compiled-in, no need for buffer */ /* Font cache structures */ -static struct font_cache font_cache_ui; -static int fnt_file = -1; /* >=0 if font is cached */ -uint32_t file_width_offset; /* offset to file width data */ -uint32_t file_offset_offset; /* offset to file offset data */ -static void cache_create(int maxwidth, int height); -static int long_offset = 0; -static int glyph_file; +static struct font_cache sys_font_cache[MAXCACHEFONTS]; +static struct font_file_info fntfile[MAXCACHEFONTS]; +static void cache_create(int maxwidth, int height, int font); +static void font_cache_init(void); /* End Font cache structures */ -static void glyph_cache_load(void); +static void glyph_cache_load(int font); +/* Zero out all font structures */ void font_init(void) { - memset(&font_ui, 0, sizeof(struct font)); + int i = FONT_BROWSER; /* Skip sysfont */ + + while (i < MAXFONTS) + { + memset(sysfonts[i], 0, sizeof(struct font)); + i++; + } + + font_cache_init(); +} + +void font_cache_init(void) +{ + int i = 0; + + while (i < MAXCACHEFONTS) + { + fntfile[i].font_fd = -1; + i++; + } + return; } /* Check if we have x bytes left in the file buffer */ @@ -82,126 +130,147 @@ the file buffer. Bounds-checking must be done in the calling function. */ - -static short readshort(void) + +static short readshort(unsigned short *sp, int font) { unsigned short s; - s = *fileptr++ & 0xff; - s |= (*fileptr++ << 8); - return s; + s = *fntfile[font].fileptr++ & 0xff; + *sp = (*fntfile[font].fileptr++ << 8) | s; + return (fntfile[font].fileptr <= fntfile[font].eofptr); } -static int32_t readlong(void) +static int32_t readlong(uint32_t *lp, int font) { uint32_t l; - l = *fileptr++ & 0xff; - l |= *fileptr++ << 8; - l |= ((uint32_t)(*fileptr++)) << 16; - l |= ((uint32_t)(*fileptr++)) << 24; - return l; + l = *fntfile[font].fileptr++ & 0xff; + l |= *fntfile[font].fileptr++ << 8; + l |= ((uint32_t)(*fntfile[font].fileptr++)) << 16; + l |= ((uint32_t)(*fntfile[font].fileptr++)) << 24; + *lp = l; + return (fntfile[font].fileptr <= fntfile[font].eofptr); } /* read count bytes*/ -static void readstr(char *buf, int count) +static int readstr(char *buf, int count, int font) { - while (count--) - *buf++ = *fileptr++; + int n = count; + + while (--n >= 0) + *buf++ = *fntfile[font].fileptr++; + + return (fntfile[font].fileptr <= fntfile[font].eofptr)? count: 0; } -void font_reset(void) +void font_reset(int font) { - memset(&font_ui, 0, sizeof(struct font)); + memset(sysfonts[font], 0, sizeof(struct font)); } -static struct font* font_load_header(struct font *pf) +static struct font* font_load_header(struct font *pf, int font) { char version[4+1]; - - /* Check we have enough data */ - if (!HAVEBYTES(28)) - return NULL; + unsigned short maxwidth, height, ascent, pad; + uint32_t firstchar, defaultchar, size; + uint32_t nbits; /* read magic and version #*/ memset(version, 0, sizeof(version)); - readstr(version, 4); + if (readstr(version, 4, font) != 4) + return NULL; if (strcmp(version, VERSION) != 0) return NULL; /* font info*/ - pf->maxwidth = readshort(); - pf->height = readshort(); - pf->ascent = readshort(); - fileptr += 2; /* Skip padding */ - pf->firstchar = readlong(); - pf->defaultchar = readlong(); - pf->size = readlong(); + if (!readshort(&maxwidth, font)) + return NULL; + pf->maxwidth = maxwidth; + + if (!readshort(&height, font)) + return NULL; + pf->height = height; + + if (!readshort(&ascent, font)) + return NULL; + pf->ascent = ascent; + + if (!readshort(&pad, font)) + return NULL; + + if (!readlong(&firstchar, font)) + return NULL; + pf->firstchar = firstchar; + + if (!readlong(&defaultchar, font)) + return NULL; + pf->defaultchar = defaultchar; + + if (!readlong(&size, font)) + return NULL; + pf->size = size; /* get variable font data sizes*/ /* # words of bitmap_t*/ - pf->bits_size = readlong(); + if (!readlong(&nbits, font)) + return NULL; + pf->bits_size = nbits; return pf; } /* Load memory font */ -static struct font* font_load_in_memory(struct font* pf) +static struct font* font_load_in_memory(struct font* pf, int font) { int32_t i, noffset, nwidth; - if (!HAVEBYTES(4)) - return NULL; - /* # longs of offset*/ - noffset = readlong(); + if (!readlong(&noffset, font)) + return NULL; /* # bytes of width*/ - nwidth = readlong(); + if (!readlong(&nwidth, font)) + return NULL; /* variable font data*/ - pf->bits = (unsigned char *)fileptr; - fileptr += pf->bits_size*sizeof(unsigned char); + pf->bits = (unsigned char *)fntfile[font].fileptr; + fntfile[font].fileptr += pf->bits_size*sizeof(unsigned char); if ( pf->bits_size < 0xFFDB ) { /* pad to 16-bit boundary */ - fileptr = (unsigned char *)(((intptr_t)fileptr + 1) & ~1); + fntfile[font].fileptr = (unsigned char *)(((intptr_t)fntfile[font].fileptr + 1) & ~1); } else { /* pad to 32-bit boundary*/ - fileptr = (unsigned char *)(((intptr_t)fileptr + 3) & ~3); + fntfile[font].fileptr = (unsigned char *)(((intptr_t)fntfile[font].fileptr + 3) & ~3); } if (noffset) { if ( pf->bits_size < 0xFFDB ) { - long_offset = 0; - pf->offset = (unsigned short *)fileptr; - - /* Check we have sufficient buffer */ - if (!HAVEBYTES(noffset * sizeof(short))) - return NULL; - + fntfile[font].long_offset = 0; + pf->offset = (unsigned short *)fntfile[font].fileptr; for (i=0; ioffset))[i] = (unsigned short)readshort(); + unsigned short offset; + if (!readshort(&offset, font)) + return NULL; + ((unsigned short*)(pf->offset))[i] = (unsigned short)offset; } } else { - long_offset = 1; - pf->offset = (unsigned short *)fileptr; - - /* Check we have sufficient buffer */ - if (!HAVEBYTES(noffset * sizeof(int32_t))) - return NULL; - + fntfile[font].long_offset = 1; + pf->offset = (unsigned short *)fntfile[font].fileptr; for (i=0; ioffset))[i] = (uint32_t)readlong(); + uint32_t offset; + if (!readlong(&offset, font)) + return NULL; + ((uint32_t*)(pf->offset))[i] = (uint32_t)offset; } } } @@ -209,140 +278,140 @@ pf->offset = NULL; if (nwidth) { - pf->width = (unsigned char *)fileptr; - fileptr += nwidth*sizeof(unsigned char); + pf->width = (unsigned char *)fntfile[font].fileptr; + fntfile[font].fileptr += nwidth*sizeof(unsigned char); } else pf->width = NULL; - if (fileptr > eofptr) + if (fntfile[font].fileptr > fntfile[font].eofptr) return NULL; return pf; /* success!*/ } /* Load cached font */ -static struct font* font_load_cached(struct font* pf) +static struct font* font_load_cached(struct font* pf, int font) { uint32_t noffset, nwidth; - unsigned char* oldfileptr = fileptr; - - if (!HAVEBYTES(2 * sizeof(int32_t))) - return NULL; + unsigned char* oldfileptr = fntfile[font].fileptr; /* # longs of offset*/ - noffset = readlong(); + if (!readlong(&noffset, font)) + return NULL; /* # bytes of width*/ - nwidth = readlong(); + if (!readlong(&nwidth, font)) + return NULL; /* We are now at the bitmap data, this is fixed at 36.. */ pf->bits = NULL; /* Calculate offset to offset data */ - fileptr += pf->bits_size * sizeof(unsigned char); + fntfile[font].fileptr += pf->bits_size * sizeof(unsigned char); if ( pf->bits_size < 0xFFDB ) { - long_offset = 0; + fntfile[font].long_offset = 0; /* pad to 16-bit boundary */ - fileptr = (unsigned char *)(((intptr_t)fileptr + 1) & ~1); + fntfile[font].fileptr = (unsigned char *)(((intptr_t)fntfile[font].fileptr + 1) & ~1); } else { - long_offset = 1; + fntfile[font].long_offset = 1; /* pad to 32-bit boundary*/ - fileptr = (unsigned char *)(((intptr_t)fileptr + 3) & ~3); + fntfile[font].fileptr = (unsigned char *)(((intptr_t)fntfile[font].fileptr + 3) & ~3); } if (noffset) - file_offset_offset = (uint32_t)(fileptr - freeptr); + fntfile[font].file_offset_offset = (uint32_t)(fntfile[font].fileptr - fntfile[font].freeptr); else - file_offset_offset = 0; + fntfile[font].file_offset_offset = 0; /* Calculate offset to widths data */ if ( pf->bits_size < 0xFFDB ) - fileptr += noffset * sizeof(unsigned short); + fntfile[font].fileptr += noffset * sizeof(unsigned short); else - fileptr += noffset * sizeof(uint32_t); + fntfile[font].fileptr += noffset * sizeof(uint32_t); if (nwidth) - file_width_offset = (uint32_t)(fileptr - freeptr); + fntfile[font].file_width_offset = (uint32_t)(fntfile[font].fileptr - fntfile[font].freeptr); else - file_width_offset = 0; + fntfile[font].file_width_offset = 0; - fileptr = oldfileptr; + fntfile[font].fileptr = oldfileptr; /* Create the cache */ - cache_create(pf->maxwidth, pf->height); + cache_create(pf->maxwidth, pf->height, font); return pf; } /* read and load font into incore font structure*/ -struct font* font_load(const char *path) +struct font* font_load(const char *path, int _font) { int size; - struct font* pf = &font_ui; + int font = _font - 1; /* cache index vs global font index */ + struct font* pf = sysfonts[_font]; /* save loaded glyphs */ - glyph_cache_save(); + glyph_cache_save(font); /* Close font file handle */ - if (fnt_file >= 0) - close(fnt_file); + if (fntfile[font].font_fd >= 0) + close(fntfile[font].font_fd); /* open and read entire font file*/ - fnt_file = open(path, O_RDONLY|O_BINARY); + fntfile[font].font_fd = open(path, O_RDONLY|O_BINARY); - if (fnt_file < 0) { + if (fntfile[font].font_fd < 0) { DEBUGF("Can't open font: %s\n", path); return NULL; } /* Check file size */ - size = filesize(fnt_file); + size = filesize(fntfile[font].font_fd); - font_reset(); + font_reset(_font); /* currently, font loading replaces earlier font allocation*/ - freeptr = (unsigned char *)(((intptr_t)mbuf + 3) & ~3); - fileptr = freeptr; + fntfile[font].freeptr = (unsigned char *)(((intptr_t)font_membuf[font] + 3) & ~3); + fntfile[font].fileptr = fntfile[font].freeptr; if (size > MAX_FONT_SIZE) { - read(fnt_file, fileptr, FONT_HEADER_SIZE); - eofptr = fileptr + FONT_HEADER_SIZE; + read(fntfile[font].font_fd, fntfile[font].fileptr, FONT_HEADER_SIZE); + fntfile[font].eofptr = fntfile[font].fileptr + FONT_HEADER_SIZE; - if (!font_load_header(pf)) + if (!font_load_header(pf, font)) { DEBUGF("Failed font header load"); return NULL; } - if (!font_load_cached(pf)) + if (!font_load_cached(pf, font)) { DEBUGF("Failed font cache load"); return NULL; } - glyph_cache_load(); + glyph_cache_load(font); } else { - read(fnt_file, fileptr, MAX_FONT_SIZE); - eofptr = fileptr + size; - close(fnt_file); - fnt_file = -1; + read(fntfile[font].font_fd, fntfile[font].fileptr, MAX_FONT_SIZE); + fntfile[font].eofptr = fntfile[font].fileptr + size; + close(fntfile[font].font_fd); + fntfile[font].font_fd = -1; - if (!font_load_header(pf)) + if (!font_load_header(pf, font)) { DEBUGF("Failed font header load"); return NULL; } - if (!font_load_in_memory(pf)) + if (!font_load_in_memory(pf, font)) { DEBUGF("Failed mem load"); return NULL; @@ -359,13 +428,25 @@ /* * Return a pointer to an incore font structure. * If the requested font isn't loaded/compiled-in, - * decrement the font number and try again. + * (decrement the font number and try again) + * MWE return sysfont instead + * */ -struct font* font_get(int font) +struct font *font_get(int font) { - struct font* pf; + struct font *pf; + + if (font >= MAXFONTS){ + return &sysfont; + } + + pf = sysfonts[font]; + if (pf && pf->height) + return pf; + + return &sysfont; - if (font >= MAXFONTS) +/* if (font >= MAXFONTS) font = 0; while (1) { @@ -374,14 +455,14 @@ return pf; if (--font < 0) panicf("No font!"); - } + }*/ } /* * Returns the stringsize of a given string. */ -int font_getstringsize(const unsigned char *str, int *w, int *h, int fontnumber) +int font_getstringsize(const unsigned char *str, int *w, int *h, int font) { - struct font* pf = font_get(fontnumber); + struct font* pf = font_get(font); unsigned short ch; int width = 0; @@ -389,7 +470,7 @@ { /* get proportional width and glyph bits*/ - width += font_get_width(pf,ch); + width += font_get_width(pf, ch, font); } if ( w ) *w = width; @@ -402,17 +483,17 @@ * Reads an entry into cache entry */ static void -load_cache_entry(struct font_cache_entry* p, void* callback_data) +load_cache_entry(struct font_cache_entry* p, void* callback_data, int font) { struct font* pf = callback_data; unsigned short char_code = p->_char_code; unsigned char tmp[2]; - if (file_width_offset) + if (fntfile[font].file_width_offset) { - int width_offset = file_width_offset + char_code; - lseek(fnt_file, width_offset, SEEK_SET); - read(fnt_file, &(p->width), 1); + int width_offset = fntfile[font].file_width_offset + char_code; + lseek(fntfile[font].font_fd, width_offset, SEEK_SET); + read(fntfile[font].font_fd, &(p->width), 1); } else { @@ -421,14 +502,14 @@ int32_t bitmap_offset = 0; - if (file_offset_offset) + if (fntfile[font].file_offset_offset) { - int32_t offset = file_offset_offset + char_code * (long_offset ? sizeof(int32_t) : sizeof(short)); - lseek(fnt_file, offset, SEEK_SET); - read (fnt_file, tmp, 2); + int32_t offset = fntfile[font].file_offset_offset + char_code * (fntfile[font].long_offset ? sizeof(int32_t) : sizeof(short)); + lseek(fntfile[font].font_fd, offset, SEEK_SET); + read (fntfile[font].font_fd, tmp, 2); bitmap_offset = tmp[0] | (tmp[1] << 8); - if (long_offset) { - read (fnt_file, tmp, 2); + if (fntfile[font].long_offset) { + read (fntfile[font].font_fd, tmp, 2); bitmap_offset |= (tmp[0] << 16) | (tmp[1] << 24); } } @@ -438,117 +519,205 @@ } int32_t file_offset = FONT_HEADER_SIZE + bitmap_offset; - lseek(fnt_file, file_offset, SEEK_SET); + lseek(fntfile[font].font_fd, file_offset, SEEK_SET); int src_bytes = p->width * ((pf->height + 7) / 8); - read(fnt_file, p->bitmap, src_bytes); + read(fntfile[font].font_fd, p->bitmap, src_bytes); } /* * Converts cbuf into a font cache */ -static void cache_create(int maxwidth, int height) +static void cache_create(int maxwidth, int height, int font) { /* maximum size of rotated bitmap */ int bitmap_size = maxwidth * ((height + 7) / 8); /* Initialise cache */ - font_cache_create(&font_cache_ui, mbuf, MAX_FONT_SIZE, bitmap_size); + font_cache_create(&sys_font_cache[font], &font_membuf[font], MAX_FONT_SIZE, bitmap_size); } /* * Returns width of character */ -int font_get_width(struct font* pf, unsigned short char_code) +int font_get_width(struct font* pf, unsigned short char_code, int font) { /* check input range*/ if (char_code < pf->firstchar || char_code >= pf->firstchar+pf->size) char_code = pf->defaultchar; char_code -= pf->firstchar; - return (fnt_file >= 0 && pf != &sysfont)? - font_cache_get(&font_cache_ui,char_code,load_cache_entry,pf)->width: - pf->width? pf->width[char_code]: pf->maxwidth; + if (pf == &sysfont || fntfile[font-1].font_fd < 0) /* sysfont or loaded into mem */ + { + if (pf->width) + return pf->width[char_code]; + else + return pf->maxwidth; + } + else /* cached */ + return font_cache_get(&sys_font_cache[font-1], char_code, load_cache_entry, pf, font-1)->width; } -const unsigned char* font_get_bits(struct font* pf, unsigned short char_code) +const unsigned char* font_get_bits(struct font* pf, unsigned short char_code, int font) { const unsigned char* bits; /* check input range*/ if (char_code < pf->firstchar || char_code >= pf->firstchar+pf->size) char_code = pf->defaultchar; - char_code -= pf->firstchar; + char_code -= pf->firstchar; - if (fnt_file >= 0 && pf != &sysfont) - { - bits = - (unsigned char*)font_cache_get(&font_cache_ui,char_code,load_cache_entry,pf)->bitmap; - } - else - { - bits = pf->bits + (pf->offset? - pf->offset[char_code]: - (((pf->height + 7) / 8) * pf->maxwidth * char_code)); + if (font <= 0 || fntfile[font-1].font_fd < 0) /* sysfont */ + bits = pf->bits + (pf->offset?pf->offset[char_code]:(((pf->height + 7) / 8) * pf->maxwidth * char_code)); + else + bits = (unsigned char*)font_cache_get(&sys_font_cache[font-1], char_code, load_cache_entry, pf, font-1)->bitmap; + + return bits; } - - return bits; -} -static void glyph_file_write(void* data) -{ - struct font_cache_entry* p = data; - struct font* pf = &font_ui; - unsigned short ch; - unsigned char tmp[2]; +static void glyph_file_write(void* data, int font) + { + struct font_cache_entry* p = data; + struct font* pf = sysfonts[font]; + unsigned short ch; + unsigned char tmp[2]; - ch = p->_char_code + pf->firstchar; + ch = p->_char_code + pf->firstchar; - if (ch != 0xffff && glyph_file >= 0) { - tmp[0] = ch >> 8; - tmp[1] = ch & 0xff; - if (write(glyph_file, tmp, 2) != 2) { - close(glyph_file); - glyph_file = -1; + if (p->_char_code != 0xffff && fntfile[font].glyph_fd >= 0) { + tmp[0] = p->_char_code >> 8; + tmp[1] = p->_char_code & 0xff; + + if (write(fntfile[font].glyph_fd, tmp, 2) != 2) { + close(fntfile[font].glyph_fd); + fntfile[font].glyph_fd = -1; + } } + return; } - return; -} -/* save the char codes of the loaded glyphs to a file */ -void glyph_cache_save(void) -{ + /* save the char codes of the loaded glyphs to a file */ +void glyph_cache_save(int font) + { - if (fnt_file >= 0) { + if (fntfile[font].font_fd >= 0) { - glyph_file = creat(GLYPH_CACHE_FILE); + switch (font) + { + case 0: + fntfile[font].glyph_fd = creat(GLYPH_CACHE_FILE_BRWSR); + break; + case 1: + fntfile[font].glyph_fd = creat(GLYPH_CACHE_FILE_WPS); + break; + case 2: + fntfile[font].glyph_fd = creat(GLYPH_CACHE_FILE_MENU); + break; +#ifdef CONFIG_TUNER + case 3: + fntfile[font].glyph_fd = creat(GLYPH_CACHE_FILE_TUNER); + break; +#endif +#ifdef HAVE_RECORDING + case 4: + fntfile[font].glyph_fd = creat(GLYPH_CACHE_FILE_RECORD); + break; +#endif + case 5: + fntfile[font].glyph_fd = creat(GLYPH_CACHE_FILE_USER1); + break; + case 6: + fntfile[font].glyph_fd = creat(GLYPH_CACHE_FILE_USER2); + break; + case 7: + fntfile[font].glyph_fd = creat(GLYPH_CACHE_FILE_USER3); + break; + case 8: + fntfile[font].glyph_fd = creat(GLYPH_CACHE_FILE_USER4); + break; + case 9: + fntfile[font].glyph_fd = creat(GLYPH_CACHE_FILE_USER5); + break; + case 10: + fntfile[font].glyph_fd = creat(GLYPH_CACHE_FILE_USER6); + break; + case 11: + fntfile[font].glyph_fd = creat(GLYPH_CACHE_FILE_USER7); + break; + default: + return; + } - if (glyph_file < 0) return; + if (fntfile[font].glyph_fd < 0) return; - lru_traverse(&font_cache_ui._lru, glyph_file_write); + lru_traverse(&sys_font_cache[font]._lru, glyph_file_write, font); - if (glyph_file >= 0) - close(glyph_file); + if (fntfile[font].glyph_fd >= 0) + close(fntfile[font].glyph_fd); + } + return; } - return; -} -static void glyph_cache_load(void) -{ - if (fnt_file >= 0) { +static void glyph_cache_load(int font) + { + if (fntfile[font].font_fd >= 0) { int fd; unsigned char tmp[2]; unsigned short ch; - struct font* pf = &font_ui; + struct font* pf = sysfonts[font]; - fd = open(GLYPH_CACHE_FILE, O_RDONLY|O_BINARY); + switch (font) + { + case 0: + fd = open(GLYPH_CACHE_FILE_BRWSR, O_RDONLY|O_BINARY); + break; + case 1: + fd = open(GLYPH_CACHE_FILE_WPS, O_RDONLY|O_BINARY); + break; + case 2: + fd = open(GLYPH_CACHE_FILE_MENU, O_RDONLY|O_BINARY); + break; +#ifdef CONFIG_TUNER + case 3: + fd = open(GLYPH_CACHE_FILE_TUNER, O_RDONLY|O_BINARY); + break; +#endif +#ifdef HAVE_RECORDING + case 4: + fd = open(GLYPH_CACHE_FILE_RECORD, O_RDONLY|O_BINARY); + break; +#endif + case 5: + fd = open(GLYPH_CACHE_FILE_USER1, O_RDONLY|O_BINARY); + break; + case 6: + fd = open(GLYPH_CACHE_FILE_USER2, O_RDONLY|O_BINARY); + break; + case 7: + fd = open(GLYPH_CACHE_FILE_USER3, O_RDONLY|O_BINARY); + break; + case 8: + fd = open(GLYPH_CACHE_FILE_USER4, O_RDONLY|O_BINARY); + break; + case 9: + fd = open(GLYPH_CACHE_FILE_USER5, O_RDONLY|O_BINARY); + break; + case 10: + fd = open(GLYPH_CACHE_FILE_USER6, O_RDONLY|O_BINARY); + break; + case 11: + fd = open(GLYPH_CACHE_FILE_USER7, O_RDONLY|O_BINARY); + break; + default: + return; + } if (fd >= 0) { while (read(fd, tmp, 2) == 2) { ch = (tmp[0] << 8) | tmp[1]; - font_get_bits(pf, ch); + font_get_bits(pf, ch, font); } close(fd); @@ -556,7 +725,7 @@ /* load latin1 chars into cache */ ch = 256; while (ch-- > 32) - font_get_bits(pf, ch); + font_get_bits(pf, ch, font); } } return; diff -u -r rockbox_svn.orig/firmware/font_cache.c rockbox_svn/firmware/font_cache.c --- rockbox_svn.orig/firmware/font_cache.c 2008-01-05 18:18:30.000000000 -0600 +++ rockbox_svn/firmware/font_cache.c 2008-01-08 16:48:27.000000000 -0600 @@ -23,8 +23,9 @@ /******************************************************************************* * font_cache_lru_init ******************************************************************************/ -void font_cache_lru_init(void* data) +void font_cache_lru_init(void* data, int font) { + font = 0; /* Kill gcc warning */ struct font_cache_entry* p = data; p->_char_code = 0xffff; /* assume invalid char */ } @@ -60,7 +61,7 @@ lru_create(&fcache->_lru, lru_buf, cache_size, font_cache_entry_size); /* initialise cache */ - lru_traverse(&fcache->_lru, font_cache_lru_init); + lru_traverse(&fcache->_lru, font_cache_lru_init, 0); /* font parameter not needed for callback */ short i; for (i = 0; i < cache_size; i++) fcache->_index[i] = i; /* small cheat here */ @@ -158,8 +159,8 @@ struct font_cache_entry* font_cache_get( struct font_cache* fcache, unsigned short char_code, - void (*callback) (struct font_cache_entry* p, void *callback_data), - void *callback_data) + void (*callback) (struct font_cache_entry* p, void *callback_data, int font), + void *callback_data, int font) { int insertion_point = font_cache_insertion_point(fcache, char_code); if (insertion_point >= 0) @@ -207,7 +208,7 @@ fcache->_size++; p->_char_code = char_code; - callback(p, callback_data); + callback(p, callback_data, font); return p; } diff -u -r rockbox_svn.orig/firmware/include/font_cache.h rockbox_svn/firmware/include/font_cache.h --- rockbox_svn.orig/firmware/include/font_cache.h 2008-01-05 18:17:44.000000000 -0600 +++ rockbox_svn/firmware/include/font_cache.h 2008-01-08 16:48:27.000000000 -0600 @@ -21,6 +21,10 @@ /******************************************************************************* * ******************************************************************************/ + +/* Maximum loadable/cacheable fonts. Exclude sysfont since it's compiled in */ +#define MAXCACHEFONTS MAXFONTS-1 + struct font_cache { struct lru _lru; @@ -36,6 +40,19 @@ unsigned char bitmap[1]; /* place holder */ }; +/* Per-font internal cache struct */ +struct font_file_info +{ + unsigned long file_width_offset; /* offset to file width data */ + unsigned long file_offset_offset; /* offset to file offset data */ + int long_offset; + int glyph_fd; + unsigned char *freeptr; + unsigned char *fileptr; + unsigned char *eofptr; + int font_fd; /* >=0 if font is cached */ +}; + /* void (*f) (void*, struct font_cache_entry*); */ /* Create an auto sized font cache from buf */ void font_cache_create( @@ -44,5 +61,5 @@ struct font_cache_entry* font_cache_get( struct font_cache* fcache, unsigned short char_code, - void (*callback) (struct font_cache_entry* p, void *callback_data), - void *callback_data); + void (*callback) (struct font_cache_entry* p, void *callback_data, int font), + void *callback_data, int font); diff -u -r rockbox_svn.orig/firmware/include/lru.h rockbox_svn/firmware/include/lru.h --- rockbox_svn.orig/firmware/include/lru.h 2008-01-05 18:17:44.000000000 -0600 +++ rockbox_svn/firmware/include/lru.h 2008-01-08 16:48:27.000000000 -0600 @@ -40,7 +40,7 @@ /* Data */ void *lru_data(struct lru* pl, short handle); /* Traverse lru-wise */ -void lru_traverse(struct lru* pl, void (*callback)(void* data)); +void lru_traverse(struct lru* pl, void (*callback)(void* data, int font), int font); #endif /* LRU_H */ diff -u -r rockbox_svn.orig/firmware/lru.c rockbox_svn/firmware/lru.c --- rockbox_svn.orig/firmware/lru.c 2008-01-05 18:18:30.000000000 -0600 +++ rockbox_svn/firmware/lru.c 2008-01-08 16:48:27.000000000 -0600 @@ -57,7 +57,7 @@ /******************************************************************************* * lru_traverse ******************************************************************************/ -void lru_traverse(struct lru* pl, void (*callback)(void* data)) +void lru_traverse(struct lru* pl, void (*callback)(void* data, int font), int font) { short i; struct lru_node* slot; @@ -66,7 +66,7 @@ for (i = 0; i < pl->_size; i++) { slot = lru_node_p(pl, loc); - callback(slot->data); + callback(slot->data, font); loc = slot->_next; } } diff -u -r rockbox_svn.orig/firmware/powermgmt.c rockbox_svn/firmware/powermgmt.c --- rockbox_svn.orig/firmware/powermgmt.c 2008-01-05 18:18:30.000000000 -0600 +++ rockbox_svn/firmware/powermgmt.c 2008-01-08 16:48:27.000000000 -0600 @@ -1187,7 +1187,12 @@ audio_stop(); if (battery_level_safe()) { /* do not save on critical battery */ #ifdef HAVE_LCD_BITMAP - glyph_cache_save(); + int i = FONT_BROWSER; /* Skip sysfont, even though glyph_cache_save() would ignore it */ + while (i < MAXFONTS) + { + glyph_cache_save(i); + i++; + } #endif if(ata_disk_is_active()) ata_spindown(1); Only in rockbox_svn/tools: bmp2rb Only in rockbox_svn/tools: codepages Only in rockbox_svn/tools: convbdf Only in rockbox_svn/tools: gigabeat.o Only in rockbox_svn/tools: gigabeats.o Only in rockbox_svn/tools: ipod_fw Only in rockbox_svn/tools: iriver.o Only in rockbox_svn/tools: mi4.o Only in rockbox_svn/tools: rdf2binary Only in rockbox_svn/tools: scramble Only in rockbox_svn/tools: scramble.o Only in rockbox_svn/tools: telechips.o