### Eclipse Workspace Patch 1.0
#P rockbox-devel
Index: apps/gui/gwps-common.c
===================================================================
RCS file: /cvsroot/rockbox/apps/gui/gwps-common.c,v
retrieving revision 1.62
diff -u -r1.62 gwps-common.c
--- apps/gui/gwps-common.c	26 Aug 2006 15:52:44 -0000	1.62
+++ apps/gui/gwps-common.c	28 Aug 2006 10:31:37 -0000
@@ -1646,7 +1646,8 @@
         return false;
     }
 #ifdef HAVE_LCD_BITMAP
-    int h = font_get(FONT_UI)->height;
+    display->setfont(FONT_WPS);
+    int h = font_get(FONT_WPS)->height;
     int offset = 0;
     gui_wps_statusbar_draw(gwps, true);
     if(data->wps_sb_tag && data->show_sb_on_wps)
Index: apps/gui/gwps.c
===================================================================
RCS file: /cvsroot/rockbox/apps/gui/gwps.c,v
retrieving revision 1.52
diff -u -r1.52 gwps.c
--- apps/gui/gwps.c	22 Aug 2006 08:23:24 -0000	1.52
+++ apps/gui/gwps.c	28 Aug 2006 10:31:38 -0000
@@ -81,6 +81,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;
@@ -95,6 +100,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);
Index: apps/gui/buttonbar.c
===================================================================
RCS file: /cvsroot/rockbox/apps/gui/buttonbar.c,v
retrieving revision 1.5
diff -u -r1.5 buttonbar.c
--- apps/gui/buttonbar.c	6 Dec 2005 13:27:00 -0000	1.5
+++ apps/gui/buttonbar.c	28 Aug 2006 10:31:34 -0000
@@ -116,7 +116,7 @@
         gui_buttonbar_draw_button(buttonbar, i);
     display->update_rect(0, display->height - BUTTONBAR_HEIGHT,
                          display->width, BUTTONBAR_HEIGHT);
-    display->setfont(FONT_UI);
+    display->setfont(FONT_BROWSER);
 }
 
 bool gui_buttonbar_isset(struct gui_buttonbar * buttonbar)
Index: apps/gui/quickscreen.c
===================================================================
RCS file: /cvsroot/rockbox/apps/gui/quickscreen.c,v
retrieving revision 1.14
diff -u -r1.14 quickscreen.c
--- apps/gui/quickscreen.c	15 Aug 2006 12:27:05 -0000	1.14
+++ apps/gui/quickscreen.c	28 Aug 2006 10:31:39 -0000
@@ -114,7 +114,6 @@
                          PUTSXY_BOTTOM-font_h, 7, 8);
 
     gui_textarea_update(display);
-    display->setfont(FONT_UI);
 }
 
 void gui_syncquickscreen_draw(struct gui_quickscreen * qs)
Index: apps/gui/statusbar.c
===================================================================
RCS file: /cvsroot/rockbox/apps/gui/statusbar.c,v
retrieving revision 1.27
diff -u -r1.27 statusbar.c
--- apps/gui/statusbar.c	17 Aug 2006 12:33:36 -0000	1.27
+++ apps/gui/statusbar.c	28 Aug 2006 10:31:40 -0000
@@ -354,8 +354,6 @@
             display->putsxy(STATUSBAR_BATTERY_X_POS
                              + STATUSBAR_BATTERY_WIDTH / 2
                              - width/2, STATUSBAR_Y_POS, buffer);
-        display->setfont(FONT_UI);
-
     }
     else {
         /* draw battery */
@@ -384,7 +382,6 @@
         display->setfont(FONT_SYSFIXED);
         display->putsxy(STATUSBAR_BATTERY_X_POS + STATUSBAR_BATTERY_WIDTH / 2
                          - 4, STATUSBAR_Y_POS, "?");
-        display->setfont(FONT_UI);
     }
 }
 
@@ -438,7 +435,6 @@
                                  + STATUSBAR_VOLUME_WIDTH / 2
                                  - width/2, STATUSBAR_Y_POS, buffer);
             }
-            display->setfont(FONT_UI);
         } else {
             /* display volume bar */
             vol = (volume - minvol) * 14 / (maxvol - minvol);
@@ -548,8 +544,6 @@
         display->putsxy(STATUSBAR_TIME_X_END(display->width) - width,
                         STATUSBAR_Y_POS, buffer);
     }
-    display->setfont(FONT_UI);
-
 }
 #endif
 
Index: apps/gui/list.h
===================================================================
RCS file: /cvsroot/rockbox/apps/gui/list.h,v
retrieving revision 1.26
diff -u -r1.26 list.h
--- apps/gui/list.h	23 Aug 2006 20:02:06 -0000	1.26
+++ apps/gui/list.h	28 Aug 2006 10:31:39 -0000
@@ -93,6 +93,13 @@
     ICON title_icon;
 };
 
+/* 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
+
 /*
  * Initializes a scrolling list
  *  - gui_list : the list structure to initialize
Index: apps/gui/list.c
===================================================================
RCS file: /cvsroot/rockbox/apps/gui/list.c,v
retrieving revision 1.31
diff -u -r1.31 list.c
--- apps/gui/list.c	23 Aug 2006 20:02:06 -0000	1.31
+++ apps/gui/list.c	28 Aug 2006 10:31:39 -0000
@@ -25,6 +25,7 @@
 #include "string.h"
 #include "settings.h"
 #include "kernel.h"
+#include "debug.h"
 
 #include "action.h"
 #include "screen_access.h"
@@ -40,6 +41,10 @@
 #endif
 
 #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;
@@ -118,7 +123,7 @@
                                       bool put_from_end)
 {
 #ifdef HAVE_LCD_BITMAP
-    gui_list->display->setfont(FONT_UI);
+    gui_list->display->setfont(FONT_MENU);
 #endif
     gui_textarea_update_nblines(gui_list->display);
     int nb_lines=gui_list->display->nb_lines;
@@ -234,7 +239,17 @@
 
     /* Adjust the position of icon, cursor, text for the list */
 #ifdef HAVE_LCD_BITMAP
-    display->setfont(FONT_UI);
+    switch (gui_list_context)   /* Set appropriate font */
+    {
+        case GUI_LIST_CONTEXT_MENU:
+            display->setfont(FONT_MENU);
+            break;
+        case GUI_LIST_CONTEXT_BRWSR:
+            display->setfont(FONT_BROWSER);
+            break;
+        default:
+            debugf("gui_list_draw(): unknown font context: %i\n", gui_list_context);
+    }
     gui_textarea_update_nblines(display);
     bool draw_scrollbar;
 
Index: firmware/drivers/lcd-h100.c
===================================================================
RCS file: /cvsroot/rockbox/firmware/drivers/lcd-h100.c,v
retrieving revision 1.53
diff -u -r1.53 lcd-h100.c
--- firmware/drivers/lcd-h100.c	23 Aug 2006 20:07:58 -0000	1.53
+++ firmware/drivers/lcd-h100.c	28 Aug 2006 10:32:17 -0000
@@ -1053,7 +1053,7 @@
         const unsigned char *bits;
 
         /* get proportional width and glyph bits */
-        width = font_get_width(pf,ch);
+        width = font_get_width(pf,ch,curfont);
 
         if (ofs > width)
         {
@@ -1061,7 +1061,7 @@
             continue;
         }
 
-        bits = font_get_bits(pf, ch);
+        bits = font_get_bits(pf, ch, curfont);
 
         lcd_mono_bitmap_part(bits, ofs, 0, width, x, y, width - ofs,
                              pf->height);
Index: firmware/drivers/lcd-16bit.c
===================================================================
RCS file: /cvsroot/rockbox/firmware/drivers/lcd-16bit.c,v
retrieving revision 1.36
diff -u -r1.36 lcd-16bit.c
--- firmware/drivers/lcd-16bit.c	23 Aug 2006 20:07:54 -0000	1.36
+++ firmware/drivers/lcd-16bit.c	28 Aug 2006 10:32:13 -0000
@@ -730,7 +730,7 @@
         const unsigned char *bits;
 
         /* get proportional width and glyph bits */
-        width = font_get_width(pf,ch);
+        width = font_get_width(pf,ch,curfont);
 
         if (ofs > width)
         {
@@ -738,7 +738,7 @@
             continue;
         }
 
-        bits = font_get_bits(pf, ch);
+        bits = font_get_bits(pf, ch,curfont);
 
         lcd_mono_bitmap_part(bits, ofs, 0, width, x, y, width - ofs, pf->height);
         
Index: firmware/drivers/lcd-h100-remote.c
===================================================================
RCS file: /cvsroot/rockbox/firmware/drivers/lcd-h100-remote.c,v
retrieving revision 1.62
diff -u -r1.62 lcd-h100-remote.c
--- firmware/drivers/lcd-h100-remote.c	23 Aug 2006 20:07:58 -0000	1.62
+++ firmware/drivers/lcd-h100-remote.c	28 Aug 2006 10:32:15 -0000
@@ -1217,7 +1217,7 @@
         const unsigned char *bits;
 
         /* get proportional width and glyph bits */
-        width = font_get_width(pf, ch);
+        width = font_get_width(pf, ch, curfont);
 
         if (ofs > width)
         {
@@ -1225,7 +1225,7 @@
             continue;
         }
 
-        bits = font_get_bits(pf, ch);
+        bits = font_get_bits(pf, ch, curfont);
 
         lcd_remote_bitmap_part(bits, ofs, 0, width, x, y, width - ofs,
                                pf->height);
Index: firmware/drivers/lcd-2bit-horz.c
===================================================================
RCS file: /cvsroot/rockbox/firmware/drivers/lcd-2bit-horz.c,v
retrieving revision 1.19
diff -u -r1.19 lcd-2bit-horz.c
--- firmware/drivers/lcd-2bit-horz.c	23 Aug 2006 20:07:54 -0000	1.19
+++ firmware/drivers/lcd-2bit-horz.c	28 Aug 2006 10:32:14 -0000
@@ -711,7 +711,7 @@
         const unsigned char *bits;
 
         /* get proportional width and glyph bits */
-        width = font_get_width(pf,ch);
+        width = font_get_width(pf,ch,curfont);
 
         if (ofs > width)
         {
@@ -719,7 +719,7 @@
             continue;
         }
 
-        bits = font_get_bits(pf, ch);
+        bits = font_get_bits(pf, ch, curfont);
 
         lcd_mono_bitmap_part(bits, ofs, 0, width, x, y, width - ofs,
                              pf->height);
Index: apps/plugins/databox/databox.c
===================================================================
RCS file: /cvsroot/rockbox/apps/plugins/databox/databox.c,v
retrieving revision 1.22
diff -u -r1.22 databox.c
--- apps/plugins/databox/databox.c	3 Aug 2006 20:17:22 -0000	1.22
+++ apps/plugins/databox/databox.c	28 Aug 2006 10:32:04 -0000
@@ -362,7 +362,7 @@
           default:
             if (rb->default_event_handler(button) == SYS_USB_CONNECTED) {
 #ifdef HAVE_LCD_BITMAP
-                rb->lcd_setfont(FONT_UI);
+                rb->lcd_setfont(FONT_PLUGIN);
 #endif                
                 return PLUGIN_USB_CONNECTED;
             }
@@ -370,7 +370,7 @@
         }
     } while (!done&&!abort);
 #ifdef HAVE_LCD_BITMAP
-    rb->lcd_setfont(FONT_UI);
+    rb->lcd_setfont(FONT_PLUGIN);
 #endif
     if(abort)
         return PLUGIN_OK;
Index: apps/sound_menu.c
===================================================================
RCS file: /cvsroot/rockbox/apps/sound_menu.c,v
retrieving revision 1.108
diff -u -r1.108 sound_menu.c
--- apps/sound_menu.c	16 Aug 2006 23:26:54 -0000	1.108
+++ apps/sound_menu.c	28 Aug 2006 10:31:33 -0000
@@ -998,7 +998,6 @@
     }
 
     peak_meter_trigger(false);
-    lcd_setfont(FONT_UI);
     lcd_setmargins(old_x_margin, old_y_margin);
     return retval;
 }
Index: apps/filetree.c
===================================================================
RCS file: /cvsroot/rockbox/apps/filetree.c,v
retrieving revision 1.36
diff -u -r1.36 filetree.c
--- apps/filetree.c	10 Aug 2006 09:50:45 -0000	1.36
+++ apps/filetree.c	28 Aug 2006 10:31:27 -0000
@@ -511,8 +511,25 @@
 #ifdef HAVE_LCD_BITMAP
             case TREE_ATTR_FONT:
                 gui_syncsplash(0, true, str(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(buf, (char *)global_settings.browserfont, MAX_FILENAME);
+                
+                font_load(buf, FONT_WPS);
+                set_file(buf, (char *)global_settings.wpsfont, MAX_FILENAME);
+                
+                font_load(buf, FONT_MENU);
+                set_file(buf, (char *)global_settings.menufont, MAX_FILENAME);
+                
+#ifdef CONFIG_TUNER
+                font_load(buf, FONT_TUNER);
+                set_file(buf, (char *)global_settings.tunerfont, MAX_FILENAME);
+#endif
+#ifdef HAVE_RECORDING
+                font_load(buf, FONT_RECORD);
+                set_file(buf, (char *)global_settings.recordfont, MAX_FILENAME);
+#endif
+                
                 break;
 
             case TREE_ATTR_KBD:
Index: apps/settings.h
===================================================================
RCS file: /cvsroot/rockbox/apps/settings.h,v
retrieving revision 1.233
diff -u -r1.233 settings.h
--- apps/settings.h	16 Aug 2006 23:26:54 -0000	1.233
+++ apps/settings.h	28 Aug 2006 10:31:32 -0000
@@ -234,10 +234,20 @@
     int resume_seed;   /* shuffle seed (-1=no resume shuffle 0=sorted
                           >0=shuffled) */
 
+    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
+
 #ifdef CONFIG_TUNER
     unsigned char fmr_file[MAX_FILENAME+1]; /* last fmr preset */
 #endif
-    unsigned char font_file[MAX_FILENAME+1]; /* last font */
+
     unsigned char wps_file[MAX_FILENAME+1];  /* last wps */
     unsigned char lang_file[MAX_FILENAME+1]; /* last language */
 
Index: apps/settings.c
===================================================================
RCS file: /cvsroot/rockbox/apps/settings.c,v
retrieving revision 1.409
diff -u -r1.409 settings.c
--- apps/settings.c	23 Aug 2006 20:02:05 -0000	1.409
+++ apps/settings.c	28 Aug 2006 10:31:31 -0000
@@ -943,9 +943,25 @@
     strncpy((char *)&config_block[i], (char *)global_settings.lang_file,
             MAX_FILENAME);
     i+= MAX_FILENAME;
-    strncpy((char *)&config_block[i], (char *)global_settings.font_file,
+    strncpy((char *)&config_block[i], (char *)global_settings.browserfont,
             MAX_FILENAME);
     i+= MAX_FILENAME;
+    strncpy((char *)&config_block[i], (char *)global_settings.wpsfont,
+            MAX_FILENAME);
+    i+= MAX_FILENAME;
+    strncpy((char *)&config_block[i], (char *)global_settings.menufont,
+            MAX_FILENAME);
+    i+= MAX_FILENAME;
+#ifdef CONFIG_TUNER
+    strncpy((char *)&config_block[i], (char *)global_settings.tunerfont,
+            MAX_FILENAME);
+    i+= MAX_FILENAME;
+#endif
+#ifdef HAVE_RECORDING
+    strncpy((char *)&config_block[i], (char *)global_settings.recordfont,
+            MAX_FILENAME);
+    i+= MAX_FILENAME;
+#endif
 #ifdef HAVE_REMOTE_LCD
     strncpy((char *)&config_block[i], (char *)global_settings.rwps_file,
             MAX_FILENAME);
@@ -1160,14 +1176,55 @@
 #endif
 
 #ifdef HAVE_LCD_BITMAP
-    if ( global_settings.font_file[0] &&
-         global_settings.font_file[0] != 0xff ) {
+    /* Load all the fonts */
+    if ( global_settings.browserfont[0] &&
+         global_settings.browserfont[0] != 0xff ) {
         snprintf(buf, sizeof buf, ROCKBOX_DIR FONT_DIR "/%s.fnt",
-                 global_settings.font_file);
-        font_load(buf);
+                 global_settings.browserfont);
+        font_load(buf, FONT_BROWSER);
     }
     else
-        font_reset();
+        font_reset(FONT_BROWSER);
+
+    if ( global_settings.wpsfont[0] &&
+         global_settings.wpsfont[0] != 0xff ) {
+        snprintf(buf, sizeof buf, ROCKBOX_DIR 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 ) {
+        snprintf(buf, sizeof buf, ROCKBOX_DIR 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 ) {
+        snprintf(buf, sizeof buf, ROCKBOX_DIR 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 ) {
+        snprintf(buf, sizeof buf, ROCKBOX_DIR FONT_DIR "/%s.fnt",
+                 global_settings.recordfont);
+        font_load(buf, FONT_RECORD);
+    }
+    else
+        font_reset(FONT_RECORD);
+#endif /* HAVE_RECORDING */
 
     if ( global_settings.kbd_file[0] &&
          global_settings.kbd_file[0] != 0xff ) {
@@ -1323,9 +1380,25 @@
         strncpy((char *)global_settings.lang_file, (char *)&config_block[i],
                 MAX_FILENAME);
         i+= MAX_FILENAME;
-        strncpy((char *)global_settings.font_file, (char *)&config_block[i],
+        strncpy((char *)global_settings.browserfont, (char *)&config_block[i],
+                MAX_FILENAME);
+        i+= MAX_FILENAME;
+        strncpy((char *)global_settings.wpsfont, (char *)&config_block[i],
+                MAX_FILENAME);
+        i+= MAX_FILENAME;
+        strncpy((char *)global_settings.menufont, (char *)&config_block[i],
+                MAX_FILENAME);
+        i+= MAX_FILENAME;
+#ifdef CONFIG_TUNER
+        strncpy((char *)global_settings.tunerfont, (char *)&config_block[i],
                 MAX_FILENAME);
         i+= MAX_FILENAME;
+#endif
+#ifdef HAVE_RECORDING
+        strncpy((char *)global_settings.recordfont, (char *)&config_block[i],
+                MAX_FILENAME);
+        i+= MAX_FILENAME;
+#endif
 #ifdef HAVE_REMOTE_LCD
         strncpy((char *)global_settings.rwps_file, (char *)&config_block[i],
                 MAX_FILENAME);
@@ -1353,14 +1426,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++;
 
@@ -1376,6 +1450,9 @@
         (len-extlen > maxlen))
         return;
 
+    /* Restore last slash mangled above */
+    *oldptr = '/';
+    
     strncpy(setting, fptr, len-extlen);
     setting[len-extlen]=0;
 
@@ -1518,11 +1595,31 @@
         }
 #endif
 #ifdef HAVE_LCD_BITMAP
-        else if (!strcasecmp(name, "font")) {
-            if (font_load(value))
-                set_file(value, (char *)global_settings.font_file, MAX_FILENAME);
+        else if (!strcasecmp(name, "browserfont")) {
+            if (font_load(value, FONT_BROWSER))
+                set_file(value, (char *)global_settings.browserfont, MAX_FILENAME);
+        }
+        else if (!strcasecmp(name, "wpsfont")) {
+            if (font_load(value, FONT_WPS))
+                set_file(value, (char *)global_settings.wpsfont, MAX_FILENAME);
+        }
+        else if (!strcasecmp(name, "menufont")) {
+            if (font_load(value, FONT_MENU))
+                set_file(value, (char *)global_settings.menufont, MAX_FILENAME);
         }
-#endif
+#ifdef CONFIG_TUNER
+        else if (!strcasecmp(name, "tunerfont")) {
+            if (font_load(value, FONT_TUNER))
+                set_file(value, (char *)global_settings.tunerfont, MAX_FILENAME);
+        }
+#endif /* CONFIG_TUNER */
+#ifdef HAVE_RECORDING
+        else if (!strcasecmp(name, "recordfont")) {
+            if (font_load(value, FONT_RECORD))
+                set_file(value, (char *)global_settings.recordfont, MAX_FILENAME);
+        }
+#endif /* HAVE_RECORDING */
+#endif /* HAVE_LCD_BITMAP */
 #ifdef HAVE_LCD_COLOR
         else if (!strcasecmp(name, "backdrop")) {
             if (load_main_backdrop(value)) {
@@ -1684,10 +1781,26 @@
                  global_settings.lang_file);
 
 #ifdef HAVE_LCD_BITMAP
-    if (global_settings.font_file[0] != 0)
-        fdprintf(fd, "font: %s/%s.fnt\r\n", ROCKBOX_DIR FONT_DIR,
-                 global_settings.font_file);
-#endif
+    if (global_settings.browserfont[0] != 0)
+        fdprintf(fd, "browserfont: %s/%s.fnt\r\n", ROCKBOX_DIR FONT_DIR,
+                 global_settings.browserfont);
+    if (global_settings.wpsfont[0] != 0)
+        fdprintf(fd, "wpsfont: %s/%s.fnt\r\n", ROCKBOX_DIR FONT_DIR,
+                 global_settings.wpsfont);
+    if (global_settings.menufont[0] != 0)
+        fdprintf(fd, "menufont: %s/%s.fnt\r\n", ROCKBOX_DIR FONT_DIR,
+                 global_settings.menufont);
+#ifdef CONFIG_TUNER
+    if (global_settings.tunerfont[0] != 0)
+        fdprintf(fd, "tunerfont: %s/%s.fnt\r\n", ROCKBOX_DIR FONT_DIR,
+                 global_settings.tunerfont);
+#endif /* CONFIG_TUNER */
+#ifdef HAVE_RECORDING
+    if (global_settings.recordfont[0] != 0)
+        fdprintf(fd, "recordfont: %s/%s.fnt\r\n", ROCKBOX_DIR FONT_DIR,
+                 global_settings.recordfont);
+#endif /* HAVE_RECORDING */
+#endif /* HAVE_LCD_BITMAP */
 
 #ifdef HAVE_LCD_COLOR
     if (global_settings.backdrop_file[0] != 0)
@@ -1790,7 +1903,15 @@
 #ifdef HAVE_REMOTE_LCD
     global_settings.rwps_file[0] = '\0';
 #endif
-    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
     global_settings.lang_file[0] = '\0';
 #ifdef HAVE_LCD_COLOR
     global_settings.backdrop_file[0] = '\0';
Index: apps/menu.c
===================================================================
RCS file: /cvsroot/rockbox/apps/menu.c,v
retrieving revision 1.104
diff -u -r1.104 menu.c
--- apps/menu.c	15 Aug 2006 12:27:04 -0000	1.104
+++ apps/menu.c	28 Aug 2006 10:31:27 -0000
@@ -116,6 +116,9 @@
 void menu_exit(int m)
 {
     inuse[m] = false;
+#ifdef HAVE_LCD_BITMAP
+    gui_list_context = GUI_LIST_CONTEXT_BRWSR; /* If returning to WPS, gui_wps_refresh() will set the font */
+#endif
 }
 
 int menu_show(int m)
@@ -126,6 +129,9 @@
     bool exit = false;
     int key;
 
+#ifdef HAVE_LCD_BITMAP
+    gui_list_context = GUI_LIST_CONTEXT_MENU; /* Set menu font */
+#endif
     gui_synclist_draw(&(menus[m].synclist));
     gui_syncstatusbar_draw(&statusbars, true);
     menu_talk_selected(m);
Index: apps/screens.c
===================================================================
RCS file: /cvsroot/rockbox/apps/screens.c,v
retrieving revision 1.167
diff -u -r1.167 screens.c
--- apps/screens.c	21 Aug 2006 07:03:15 -0000	1.167
+++ apps/screens.c	28 Aug 2006 10:31:29 -0000
@@ -495,7 +495,6 @@
 #if CONFIG_CODEC == SWCODEC
     pcmbuf_set_low_latency(false);
 #endif
-    lcd_setfont(FONT_UI);
     action_signalscreenchange();
     return 0;
 }
Index: apps/tree.c
===================================================================
RCS file: /cvsroot/rockbox/apps/tree.c,v
retrieving revision 1.436
diff -u -r1.436 tree.c
--- apps/tree.c	23 Aug 2006 20:02:05 -0000	1.436
+++ apps/tree.c	28 Aug 2006 10:31:34 -0000
@@ -571,6 +571,10 @@
     lastextra = -1;
     lastfirstpos = 0;
 
+#ifdef HAVE_LCD_BITMAP
+    gui_list_context = GUI_LIST_CONTEXT_BRWSR;   /* Set browser font */
+#endif
+
     if (*tc.dirfilter < NUM_FILTER_MODES) {
 #ifdef HAVE_RECORDING
 #ifndef SIMULATOR
Index: apps/eq_menu.c
===================================================================
RCS file: /cvsroot/rockbox/apps/eq_menu.c,v
retrieving revision 1.24
diff -u -r1.24 eq_menu.c
--- apps/eq_menu.c	21 Aug 2006 07:03:15 -0000	1.24
+++ apps/eq_menu.c	28 Aug 2006 10:31:26 -0000
@@ -695,7 +695,6 @@
     action_signalscreenchange();
     /* Reset screen settings */
     FOR_NB_SCREENS(i) {
-        screens[i].setfont(FONT_UI);
         screens[i].clear_display();
     }
     return result;
Index: apps/screen_access.c
===================================================================
RCS file: /cvsroot/rockbox/apps/screen_access.c,v
retrieving revision 1.26
diff -u -r1.26 screen_access.c
--- apps/screen_access.c	1 Jul 2006 10:14:26 -0000	1.26
+++ apps/screen_access.c	28 Aug 2006 10:31:27 -0000
@@ -48,7 +48,6 @@
             screen->getymargin=&lcd_remote_getymargin;
             screen->getxmargin=&lcd_remote_getxmargin;
             screen->setfont=&lcd_remote_setfont;
-            screen->setfont(FONT_UI);
             screen->getstringsize=&lcd_remote_getstringsize;
             screen->putsxy=&lcd_remote_putsxy;
             screen->mono_bitmap=&lcd_remote_mono_bitmap;
@@ -120,7 +119,6 @@
             screen->getymargin=&lcd_getymargin;
             screen->getxmargin=&lcd_getxmargin;
             screen->setfont=&lcd_setfont;
-            screen->setfont(FONT_UI);
             screen->getstringsize=&lcd_getstringsize;
             screen->putsxy=&lcd_putsxy;
             screen->mono_bitmap=&lcd_mono_bitmap;
Index: apps/plugins/mp3_encoder.c
===================================================================
RCS file: /cvsroot/rockbox/apps/plugins/mp3_encoder.c,v
retrieving revision 1.16
diff -u -r1.16 mp3_encoder.c
--- apps/plugins/mp3_encoder.c	3 Aug 2006 20:17:15 -0000	1.16
+++ apps/plugins/mp3_encoder.c	28 Aug 2006 10:31:55 -0000
@@ -2480,7 +2480,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
Index: apps/plugins/viewer.c
===================================================================
RCS file: /cvsroot/rockbox/apps/plugins/viewer.c,v
retrieving revision 1.43
diff -u -r1.43 viewer.c
--- apps/plugins/viewer.c	3 Aug 2006 20:17:21 -0000	1.43
+++ apps/plugins/viewer.c	28 Aug 2006 10:32:04 -0000
@@ -947,7 +947,7 @@
 {
 #ifdef HAVE_LCD_BITMAP
 
-    pf = rb->font_get(FONT_UI);
+    pf = rb->font_get(FONT_PLUGIN);
 
     display_lines = LCD_HEIGHT / pf->height;
     draw_columns = display_columns = LCD_WIDTH;
Index: apps/plugins/xobox.c
===================================================================
RCS file: /cvsroot/rockbox/apps/plugins/xobox.c,v
retrieving revision 1.9
diff -u -r1.9 xobox.c
--- apps/plugins/xobox.c	3 Aug 2006 20:17:21 -0000	1.9
+++ apps/plugins/xobox.c	28 Aug 2006 10:32:04 -0000
@@ -703,7 +703,7 @@
     int button, selection = 0, sw, sh, i;
     bool quit = false;
 
-    rb->lcd_setfont(FONT_UI);
+    rb->lcd_setfont(FONT_PLUGIN);
     rb->lcd_getstringsize("A", &sw, &sh);
     if(sw*20 > LCD_WIDTH || sh*4 > LCD_HEIGHT)
         rb->lcd_setfont(FONT_SYSFIXED);
@@ -862,7 +862,7 @@
     }
 
     rb->backlight_set_timeout (rb->global_settings->backlight_timeout);
-    rb->lcd_setfont (FONT_UI);
+    rb->lcd_setfont (FONT_PLUGIN);
 
     return ret;
 }
Index: apps/plugins/jewels.c
===================================================================
RCS file: /cvsroot/rockbox/apps/plugins/jewels.c,v
retrieving revision 1.28
diff -u -r1.28 jewels.c
--- apps/plugins/jewels.c	3 Aug 2006 20:17:15 -0000	1.28
+++ apps/plugins/jewels.c	28 Aug 2006 10:31:48 -0000
@@ -1482,7 +1482,7 @@
                 break;
 
             case BJ_USB:
-                rb->lcd_setfont(FONT_UI);
+                rb->lcd_setfont(FONT_PLUGIN);
                 return PLUGIN_USB_CONNECTED;
 
             case BJ_QUIT:
@@ -1512,7 +1512,7 @@
         }
     }
 
-    rb->lcd_setfont(FONT_UI);
+    rb->lcd_setfont(FONT_PLUGIN);
     return PLUGIN_OK;
 }
 
Index: apps/plugins/rockpaint.c
===================================================================
RCS file: /cvsroot/rockbox/apps/plugins/rockpaint.c,v
retrieving revision 1.7
diff -u -r1.7 rockpaint.c
--- apps/plugins/rockpaint.c	9 Aug 2006 13:25:43 -0000	1.7
+++ apps/plugins/rockpaint.c	28 Aug 2006 10:32:04 -0000
@@ -388,7 +388,7 @@
     unsigned short ch;
     unsigned short *ucs;
 
-    struct font *pf = rb->font_get( FONT_UI );
+    struct font *pf = rb->font_get( FONT_PLUGIN );
     if( !pf ) pf = rb->font_get( FONT_SYSFIXED );
 
     ucs = rb->bidi_l2v( str, 1 );
@@ -821,7 +821,7 @@
 
     rb->snprintf( old_font, MAX_PATH,
                   ROCKBOX_DIR FONT_DIR "/%s.fnt",
-                  rb->global_settings->font_file );
+                  rb->global_settings->browserfont );
 
     while( 1 )
     {
@@ -876,7 +876,7 @@
                 rb->snprintf( bbuf, MAX_PATH, ROCKBOX_DIR FONT_DIR "/%s",
                               de->d_name );
                 rb->font_load( bbuf );
-                rb->font_getstringsize( de->d_name, &fw, &fh, FONT_UI );
+                rb->font_getstringsize( de->d_name, &fw, &fh, FONT_PLUGIN );
                 if( nvih > 0 )
                 {
                     nvih -= fh;
@@ -911,7 +911,7 @@
                     rb->snprintf( bbuf, MAX_PATH, ROCKBOX_DIR FONT_DIR "/%s",
                           de->d_name );
                     rb->font_load( bbuf );
-                    rb->font_getstringsize( de->d_name, NULL, &fh, FONT_UI );
+                    rb->font_getstringsize( de->d_name, NULL, &fh, FONT_PLUGIN );
                     nvih = fh;
                 }
             }
@@ -1061,7 +1061,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 ); \
@@ -1400,7 +1400,7 @@
     buffer.text.text[0] = '\0';
     rb->snprintf( buffer.text.old_font, MAX_PATH,
                   ROCKBOX_DIR FONT_DIR "/%s.fnt",
-                  rb->global_settings->font_file );
+                  rb->global_settings->browserfont );
     while( 1 )
     {
         int m = TEXT_MENU_TEXT;
@@ -2226,7 +2226,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();
Index: apps/plugins/stopwatch.c
===================================================================
RCS file: /cvsroot/rockbox/apps/plugins/stopwatch.c,v
retrieving revision 1.20
diff -u -r1.20 stopwatch.c
--- apps/plugins/stopwatch.c	3 Aug 2006 20:17:20 -0000	1.20
+++ apps/plugins/stopwatch.c	28 Aug 2006 10:32:04 -0000
@@ -152,7 +152,7 @@
     rb = api;
 
 #ifdef HAVE_LCD_BITMAP
-    rb->lcd_setfont(FONT_UI);
+    rb->lcd_setfont(FONT_PLUGIN);
 #endif
 
     rb->lcd_clear_display();
Index: apps/plugins/brickmania.c
===================================================================
RCS file: /cvsroot/rockbox/apps/plugins/brickmania.c,v
retrieving revision 1.27
diff -u -r1.27 brickmania.c
--- apps/plugins/brickmania.c	27 Aug 2006 10:17:21 -0000	1.27
+++ apps/plugins/brickmania.c	28 Aug 2006 10:31:43 -0000
@@ -1942,7 +1942,7 @@
     configfile_save(HIGH_SCORE,config,1,0);
 
     /* Restore user's original backlight setting */
-    rb->lcd_setfont(FONT_UI);
+    rb->lcd_setfont(FONT_PLUGIN);
     rb->backlight_set_timeout(rb->global_settings->backlight_timeout);
 
     return PLUGIN_OK;
Index: apps/plugins/credits.c
===================================================================
RCS file: /cvsroot/rockbox/apps/plugins/credits.c,v
retrieving revision 1.9
diff -u -r1.9 credits.c
--- apps/plugins/credits.c	9 Aug 2006 13:25:19 -0000	1.9
+++ apps/plugins/credits.c	28 Aug 2006 10:31:47 -0000
@@ -146,7 +146,7 @@
     int numnames = (sizeof(credits)/sizeof(char*));
     char name[40], elapsednames[20];
 
-    rb->lcd_setfont(FONT_UI);
+    rb->lcd_setfont(FONT_PLUGIN);
     rb->lcd_clear_display();
     rb->lcd_update();
 
Index: apps/plugins/bounce.c
===================================================================
RCS file: /cvsroot/rockbox/apps/plugins/bounce.c,v
retrieving revision 1.29
diff -u -r1.29 bounce.c
--- apps/plugins/bounce.c	3 Aug 2006 20:17:14 -0000	1.29
+++ apps/plugins/bounce.c	28 Aug 2006 10:31:41 -0000
@@ -522,7 +522,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;
 }
Index: apps/plugins/spacerocks.c
===================================================================
RCS file: /cvsroot/rockbox/apps/plugins/spacerocks.c,v
retrieving revision 1.9
diff -u -r1.9 spacerocks.c
--- apps/plugins/spacerocks.c	3 Aug 2006 20:17:18 -0000	1.9
+++ apps/plugins/spacerocks.c	28 Aug 2006 10:32:04 -0000
@@ -1667,7 +1667,7 @@
     iohiscore();
     retval = start_game();  
     iohiscore();
-    rb->lcd_setfont(FONT_UI);
+    rb->lcd_setfont(FONT_PLUGIN);
     /* restore normal backlight setting*/
     rb->backlight_set_timeout(rb->global_settings->backlight_timeout);
     
Index: apps/plugins/bubbles.c
===================================================================
RCS file: /cvsroot/rockbox/apps/plugins/bubbles.c,v
retrieving revision 1.12
diff -u -r1.12 bubbles.c
--- apps/plugins/bubbles.c	11 Aug 2006 08:35:26 -0000	1.12
+++ apps/plugins/bubbles.c	28 Aug 2006 10:31:46 -0000
@@ -2704,7 +2704,7 @@
                 break;
 
             case BB_USB:
-                rb->lcd_setfont(FONT_UI);
+                rb->lcd_setfont(FONT_PLUGIN);
                 return PLUGIN_USB_CONNECTED;
 
             case BB_QUIT:
@@ -2720,7 +2720,7 @@
         }
     }
 
-    rb->lcd_setfont(FONT_UI);
+    rb->lcd_setfont(FONT_PLUGIN);
     return PLUGIN_OK;
 }
 
Index: apps/plugins/jpeg.c
===================================================================
RCS file: /cvsroot/rockbox/apps/plugins/jpeg.c,v
retrieving revision 1.58
diff -u -r1.58 jpeg.c
--- apps/plugins/jpeg.c	11 Aug 2006 12:48:35 -0000	1.58
+++ apps/plugins/jpeg.c	28 Aug 2006 10:31:51 -0000
@@ -2558,7 +2558,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();
 
Index: apps/recorder/recording.c
===================================================================
RCS file: /cvsroot/rockbox/apps/recorder/recording.c,v
retrieving revision 1.127
diff -u -r1.127 recording.c
--- apps/recorder/recording.c	20 Aug 2006 21:33:40 -0000	1.127
+++ apps/recorder/recording.c	28 Aug 2006 10:32:10 -0000
@@ -675,7 +675,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.invert_cursor ? 0 : w, 8);
         filename_offset[i] = ((screens[i].height >= 80) ? 1 : 0);
@@ -1550,9 +1550,6 @@
 
     sound_settings_apply();
 
-    FOR_NB_SCREENS(i)
-        screens[i].setfont(FONT_UI);
-
     if (have_recorded)
         reload_directory();
 
@@ -1693,8 +1690,6 @@
     set_gain();
     
     settings_save();
-    FOR_NB_SCREENS(i)
-        screens[i].setfont(FONT_UI);
 
     return false;
 }
@@ -1796,8 +1791,6 @@
     set_gain();
 
     settings_save();
-    FOR_NB_SCREENS(i)
-        screens[i].setfont(FONT_UI);
 
     return false;
 }
Index: apps/recorder/keyboard.c
===================================================================
RCS file: /cvsroot/rockbox/apps/recorder/keyboard.c,v
retrieving revision 1.58
diff -u -r1.58 keyboard.c
--- apps/recorder/keyboard.c	22 Aug 2006 13:21:13 -0000	1.58
+++ apps/recorder/keyboard.c	28 Aug 2006 10:32:05 -0000
@@ -310,7 +310,7 @@
             param[l].nchars = i;
         }
         else
-            param[l].curfont = FONT_UI;
+            param[l].curfont = FONT_BROWSER;
     }
     FOR_NB_SCREENS(l)
     {
@@ -327,13 +327,13 @@
         screens[l].setfont(param[l].curfont);
         /* find max width of keyboard glyphs */
         for (i=0; i<param[l].nchars; i++) {
-            w = font_get_width(param[l].font, param[l].kbd_buf[i]);
+            w = font_get_width(param[l].font, param[l].kbd_buf[i], param[l].curfont);
             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 = font_get_width( param[l].font, ' ' );
+        w = font_get_width( param[l].font, ' ', param[l].curfont);
         if( w > param[l].font_w )
             param[l].font_w = w;
     }
@@ -385,7 +385,7 @@
         text_w = param[l].font_w;
         while (*utf8) {
             utf8 = (unsigned char*)utf8decode(utf8, &ch);
-            w = font_get_width(param[l].font, ch);
+            w = font_get_width(param[l].font, ch, param[l].curfont);
             if (w > text_w)
                 text_w = w;
         }
@@ -589,8 +589,6 @@
         switch ( button ) {
 
             case ACTION_KBD_ABORT:
-                FOR_NB_SCREENS(l)
-                    screens[l].setfont(FONT_UI);
 
 #ifdef HAS_BUTTONBAR
                 global_settings.buttonbar=buttonbar_config;
@@ -1005,7 +1003,5 @@
 #ifdef HAS_BUTTONBAR
     global_settings.buttonbar=buttonbar_config;
 #endif
-    FOR_NB_SCREENS(l)
-        screens[l].setfont(FONT_UI);
     return 0;
 }
Index: apps/recorder/radio.c
===================================================================
RCS file: /cvsroot/rockbox/apps/recorder/radio.c,v
retrieving revision 1.102
diff -u -r1.102 radio.c
--- apps/recorder/radio.c	15 Aug 2006 12:27:07 -0000	1.102
+++ apps/recorder/radio.c	28 Aug 2006 10:32:08 -0000
@@ -377,13 +377,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)
@@ -937,7 +938,7 @@
                 last_seconds = seconds;
 
                 FOR_NB_SCREENS(i)
-                    screens[i].setfont(FONT_UI);
+                    screens[i].setfont(FONT_TUNER);
                 
                 if (curr_preset >= 0 )
                    snprintf(buf, 128, "%d. %s",curr_preset + 1,
Index: apps/recorder/peakmeter.c
===================================================================
RCS file: /cvsroot/rockbox/apps/recorder/peakmeter.c,v
retrieving revision 1.41
diff -u -r1.41 peakmeter.c
--- apps/recorder/peakmeter.c	20 Aug 2006 21:33:40 -0000	1.41
+++ apps/recorder/peakmeter.c	28 Aug 2006 10:32:07 -0000
@@ -537,9 +537,9 @@
     int left, right;
    /* read current values */
 #if CONFIG_CODEC == SWCODEC
+#ifdef HAVE_RECORDING    
     if (pm_playback)
         pcm_calculate_peaks(&pm_cur_left, &pm_cur_right);
-#ifdef HAVE_RECORDING        
     if (!pm_playback)
     {
         pcm_rec_get_peaks(&pm_cur_left, &pm_cur_right);
Index: firmware/lru.c
===================================================================
RCS file: /cvsroot/rockbox/firmware/lru.c,v
retrieving revision 1.1
diff -u -r1.1 lru.c
--- firmware/lru.c	6 Dec 2005 13:27:01 -0000	1.1
+++ firmware/lru.c	28 Aug 2006 10:32:11 -0000
@@ -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;
     }
 }
Index: firmware/font.c
===================================================================
RCS file: /cvsroot/rockbox/firmware/font.c,v
retrieving revision 1.20
diff -u -r1.20 font.c
--- firmware/font.c	30 May 2006 11:26:41 -0000	1.20
+++ firmware/font.c	28 Aug 2006 10:32:11 -0000
@@ -19,8 +19,8 @@
 /*
  * Rockbox startup font initialization
  * This file specifies which fonts get compiled-in and
- * loaded at startup, as well as their mapping into
- * the FONT_SYSFIXED, FONT_UI and FONT_MP3 ids.
+ * loaded at runtime, as well as their mapping into
+ * the various FONT_* ids
  */
 #include "config.h"
 
@@ -45,70 +45,105 @@
 /* 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
 
 /* 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
+ };
 
 /* 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   */
-unsigned long file_width_offset;    /* offset to file width data    */
-unsigned long 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 */
 
+/* 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;
 }
 
-static int readshort(unsigned short *sp)
+static int readshort(unsigned short *sp, int font)
 {
     unsigned short s;
 
-    s = *fileptr++ & 0xff;
-    *sp = (*fileptr++ << 8) | s;
-    return (fileptr <= eofptr);
+    s = *fntfile[font].fileptr++ & 0xff;
+    *sp = (*fntfile[font].fileptr++ << 8) | s;
+    return (fntfile[font].fileptr <= fntfile[font].eofptr);
 }
 
-static long readlong(unsigned long *lp)
+static long readlong(unsigned long *lp, int font)
 {
     unsigned long l;
 
-    l = *fileptr++ & 0xff;
-    l |= *fileptr++ << 8;
-    l |= ((unsigned long)(*fileptr++)) << 16;
-    l |= ((unsigned long)(*fileptr++)) << 24;
+    l = *fntfile[font].fileptr++ & 0xff;
+    l |= *fntfile[font].fileptr++ << 8;
+    l |= ((unsigned long)(*fntfile[font].fileptr++)) << 16;
+    l |= ((unsigned long)(*fntfile[font].fileptr++)) << 24;
     *lp = l;
-    return (fileptr <= eofptr);
+    return (fntfile[font].fileptr <= fntfile[font].eofptr);
 }
 
 /* read count bytes*/
-static int readstr(char *buf, int count)
+static int readstr(char *buf, int count, int font)
 {
     int n = count;
 
     while (--n >= 0)
-        *buf++ = *fileptr++;
-    return (fileptr <= eofptr)? count: 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];
     unsigned short maxwidth, height, ascent, pad;
@@ -117,91 +152,98 @@
 
     /* read magic and version #*/
     memset(version, 0, sizeof(version));
-    if (readstr(version, 4) != 4)
+    if (readstr(version, 4, font) != 4)
         return NULL;
+
     if (strcmp(version, VERSION) != 0)
         return NULL;
 
     /* font info*/
-    if (!readshort(&maxwidth))
+    if (!readshort(&maxwidth, font))
         return NULL;
     pf->maxwidth = maxwidth;
-    if (!readshort(&height))
+    
+    if (!readshort(&height, font))
         return NULL;
     pf->height = height;
-    if (!readshort(&ascent))
+    
+    if (!readshort(&ascent, font))
         return NULL;
     pf->ascent = ascent;
-    if (!readshort(&pad))
+    
+    if (!readshort(&pad, font))
         return NULL;
-    if (!readlong(&firstchar))
+
+    if (!readlong(&firstchar, font))
         return NULL;
     pf->firstchar = firstchar;
-    if (!readlong(&defaultchar))
+    
+    if (!readlong(&defaultchar, font))
         return NULL;
     pf->defaultchar = defaultchar;
-    if (!readlong(&size))
+    
+    if (!readlong(&size, font))
         return NULL;
     pf->size = size;
 
     /* get variable font data sizes*/
     /* # words of bitmap_t*/
-    if (!readlong(&nbits))
+    if (!readlong(&nbits, font))
         return NULL;
     pf->bits_size = nbits;
 
     return pf;
 }
 /* Load memory font */
-struct font* font_load_in_memory(struct font* pf)
+struct font* font_load_in_memory(struct font* pf, int font)
 {
     long i, noffset, nwidth;
 
     /* # longs of offset*/
-    if (!readlong(&noffset))
+    if (!readlong(&noffset, font))
         return NULL;
 
     /* # bytes of width*/
-    if (!readlong(&nwidth))
+    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 *)(((long)fileptr + 1) & ~1);
+        fntfile[font].fileptr = (unsigned char *)(((long)fntfile[font].fileptr + 1) & ~1);
     }
     else
     {
         /* pad to 32-bit boundary*/
-        fileptr = (unsigned char *)(((long)fileptr + 3) & ~3);
+        fntfile[font].fileptr = (unsigned char *)(((long)fntfile[font].fileptr + 3) & ~3);
     }
 
     if (noffset)
     {
         if ( pf->bits_size < 0xFFDB )
         {
-            long_offset = 0;
-            pf->offset = (unsigned short *)fileptr;
+            fntfile[font].long_offset = 0;
+            pf->offset = (unsigned short *)fntfile[font].fileptr;
             for (i=0; i<noffset; ++i)
             {
                 unsigned short offset;
-                if (!readshort(&offset))
+                if (!readshort(&offset, font))
                     return NULL;
                 ((unsigned short*)(pf->offset))[i] = (unsigned short)offset;
             }
         }
         else
         {
-            long_offset = 1;
-            pf->offset = (unsigned short *)fileptr;
+            fntfile[font].long_offset = 1;
+            pf->offset = (unsigned short *)fntfile[font].fileptr;
             for (i=0; i<noffset; ++i)
             {
                 unsigned long offset;
-                if (!readlong(&offset))
+                if (!readlong(&offset, font))
                     return NULL;
                 ((unsigned long*)(pf->offset))[i] = (unsigned long)offset;
             }
@@ -211,139 +253,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 */
-struct font* font_load_cached(struct font* pf)
+struct font* font_load_cached(struct font* pf, int font)
 {
     unsigned long noffset, nwidth;
-    unsigned char* oldfileptr = fileptr;
+    unsigned char* oldfileptr = fntfile[font].fileptr;
 
     /* # longs of offset*/
-    if (!readlong(&noffset))
+    if (!readlong(&noffset, font))
         return NULL;
 
     /* # bytes of width*/
-    if (!readlong(&nwidth))
+    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 *)(((long)fileptr + 1) & ~1);
+        fntfile[font].fileptr = (unsigned char *)(((long)fntfile[font].fileptr + 1) & ~1);
     }
     else
     {
-        long_offset = 1;
+        fntfile[font].long_offset = 1;
         /* pad to 32-bit boundary*/
-        fileptr = (unsigned char *)(((long)fileptr + 3) & ~3);
+        fntfile[font].fileptr = (unsigned char *)(((long)fntfile[font].fileptr + 3) & ~3);
     }
 
     if (noffset)
-        file_offset_offset = (unsigned long)(fileptr - freeptr);
+        fntfile[font].file_offset_offset = (unsigned long)(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(unsigned long);
+        fntfile[font].fileptr += noffset * sizeof(unsigned long);
 
     if (nwidth)
-        file_width_offset = (unsigned long)(fileptr - freeptr);
+        fntfile[font].file_width_offset = (unsigned long)(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 *)(((int)mbuf + 3) & ~3);
-    fileptr = freeptr;
+    fntfile[font].freeptr = (unsigned char *)(((int)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;
@@ -362,9 +405,9 @@
  * If the requested font isn't loaded/compiled-in,
  * decrement the font number and try again.
  */
-struct font* font_get(int font)
+struct font *font_get(int font)
 {
-    struct font* pf;
+    struct font *pf;
 
     if (font >= MAXFONTS)
         font = 0;
@@ -380,9 +423,9 @@
 /*
  * 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;
 
@@ -390,7 +433,7 @@
     {
 
         /* get proportional width and glyph bits*/
-        width += font_get_width(pf,ch);
+        width += font_get_width(pf, ch, font);
     }
     if ( w )
         *w = width;
@@ -403,17 +446,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
     {
@@ -422,14 +465,14 @@
  
     long bitmap_offset = 0;
 
-    if (file_offset_offset)
+    if (fntfile[font].file_offset_offset)
     {
-        long offset = file_offset_offset + char_code * (long_offset ? sizeof(long) : sizeof(short));
-        lseek(fnt_file, offset, SEEK_SET);
-        read (fnt_file, tmp, 2);
+        long offset = fntfile[font].file_offset_offset + char_code * (fntfile[font].long_offset ? sizeof(long) : 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);
         }
     }
@@ -439,40 +482,46 @@
     }
 
     long 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;
 
@@ -481,75 +530,115 @@
         char_code = pf->defaultchar;
     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;
-    }
+    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 = pf->bits + (pf->offset?
-            pf->offset[char_code]:
-            (((pf->height + 7) / 8) * pf->maxwidth * char_code));
-    }
+	bits = (unsigned char*)font_cache_get(&sys_font_cache[font-1], char_code, load_cache_entry, pf, font-1)->bitmap;
         
     return bits;
 }
 
-void glyph_file_write(void* data)
+void glyph_file_write(void* data, int font)
 {
     struct font_cache_entry* p = data;
-    struct font* pf = &font_ui;
+    struct font* pf = sysfonts[font];
     unsigned short ch;
     unsigned char tmp[2];
 
     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;
 }
 
 /* save the char codes of the loaded glyphs to a file */
-void glyph_cache_save(void)
+void glyph_cache_save(int font)
 {
 
-    if (fnt_file >= 0) {
-
-        glyph_file = creat(GLYPH_CACHE_FILE, O_WRONLY);
-
-        if (glyph_file < 0) return;
+    if (fntfile[font].font_fd >= 0) {
 
-        lru_traverse(&font_cache_ui._lru, glyph_file_write);
-
-        if (glyph_file >= 0)
-            close(glyph_file);
+	switch (font)
+	{
+	    case 0:
+		fntfile[font].glyph_fd = creat(GLYPH_CACHE_FILE_BRWSR, 0);
+		break;
+	    case 1:
+		fntfile[font].glyph_fd = creat(GLYPH_CACHE_FILE_WPS, 0);
+		break;
+	    case 2:
+		fntfile[font].glyph_fd = creat(GLYPH_CACHE_FILE_MENU, 0);
+		break;
+#ifdef CONFIG_TUNER
+	    case 3:
+		fntfile[font].glyph_fd = creat(GLYPH_CACHE_FILE_TUNER, 0);
+		break;
+#endif
+#ifdef HAVE_RECORDING
+	    case 4:
+		fntfile[font].glyph_fd = creat(GLYPH_CACHE_FILE_RECORD, 0);
+		break;
+#endif
+	    default:
+		return;
+	}
+	
+	if (fntfile[font].glyph_fd < 0) return;
+	
+	lru_traverse(&sys_font_cache[font]._lru, glyph_file_write, font);
+	
+	if (fntfile[font].glyph_fd >= 0)
+	    close(fntfile[font].glyph_fd);
     }
     return;
 }
 
-void glyph_cache_load(void)
+void glyph_cache_load(int font)
 {
-    if (fnt_file >= 0) {
+    if (fntfile[font].font_fd >= 0) {
 
         int fd;
         unsigned char tmp[2];
         unsigned short ch;
-        struct font* pf = &font_ui;
-
-        fd = open(GLYPH_CACHE_FILE, O_RDONLY|O_BINARY);
+        struct font* pf = sysfonts[font];
 
+	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
+	    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);
@@ -557,7 +646,7 @@
             /* load latin1 chars into cache */
             ch = 256;
             while (ch-- > 32)
-                font_get_bits(pf, ch);
+                font_get_bits(pf, ch, font);
         }
     }
     return;
Index: firmware/powermgmt.c
===================================================================
RCS file: /cvsroot/rockbox/firmware/powermgmt.c,v
retrieving revision 1.118
diff -u -r1.118 powermgmt.c
--- firmware/powermgmt.c	19 Aug 2006 17:45:37 -0000	1.118
+++ firmware/powermgmt.c	28 Aug 2006 10:32:12 -0000
@@ -1024,7 +1024,12 @@
 #endif
     audio_stop();
 #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
     ata_flush();
     ata_spindown(1);
Index: firmware/font_cache.c
===================================================================
RCS file: /cvsroot/rockbox/firmware/font_cache.c,v
retrieving revision 1.2
diff -u -r1.2 font_cache.c
--- firmware/font_cache.c	6 Feb 2006 17:24:47 -0000	1.2
+++ firmware/font_cache.c	28 Aug 2006 10:32:11 -0000
@@ -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, NULL);  /* 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;
 }
Index: firmware/export/font.h
===================================================================
RCS file: /cvsroot/rockbox/firmware/export/font.h,v
retrieving revision 1.10
diff -u -r1.10 font.h
--- firmware/export/font.h	6 Dec 2005 13:27:01 -0000	1.10
+++ firmware/export/font.h	28 Aug 2006 10:32:17 -0000
@@ -27,9 +27,10 @@
 #if defined(HAVE_LCD_BITMAP) || defined(SIMULATOR)
 
 /* max static loadable font buffer size */
+/* fonts > 45kb in size go through the font/glyph cache code */
 #ifndef MAX_FONT_SIZE
 #if LCD_HEIGHT > 64
-#define MAX_FONT_SIZE   10000
+#define MAX_FONT_SIZE   45000
 #else
 #define MAX_FONT_SIZE   4000
 #endif
@@ -39,7 +40,16 @@
 #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
 
 /*
  * Fonts are specified by number, and used for display
@@ -53,10 +63,21 @@
  */
 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
     MAXFONTS
 };
 
+/* FIXME: Hack to keep things compiling for now */
+#define FONT_PLUGIN FONT_SYSFIXED
+
 /*
  * .fnt loadable font file format definition
  *
@@ -99,14 +120,14 @@
 
 /* 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 glyph_cache_load(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);
+void glyph_cache_load(int font);
 
 #else /* HAVE_LCD_BITMAP */
 
Index: apps/plugins/doom/rockdoom.c
===================================================================
RCS file: /cvsroot/rockbox/apps/plugins/doom/rockdoom.c,v
retrieving revision 1.19
diff -u -r1.19 rockdoom.c
--- apps/plugins/doom/rockdoom.c	10 Jun 2006 18:47:11 -0000	1.19
+++ apps/plugins/doom/rockdoom.c	28 Aug 2006 10:32:04 -0000
@@ -812,7 +812,7 @@
    M_LoadDefaults ();              // load before initing other systems
 
 #ifdef FANCY_MENU
-   rb->lcd_setfont(FONT_UI);
+   rb->lcd_setfont(FONT_PLUGIN);
    rb->lcd_putsxy(5,LCD_HEIGHT-20, "Welcome to RockDoom");
    rb->lcd_update();
    rb->sleep(HZ*2);
Index: tools/convbdf.c
===================================================================
RCS file: /cvsroot/rockbox/tools/convbdf.c,v
retrieving revision 1.20
diff -u -r1.20 convbdf.c
--- tools/convbdf.c	18 Apr 2006 17:24:14 -0000	1.20
+++ tools/convbdf.c	28 Aug 2006 10:32:18 -0000
@@ -340,7 +340,7 @@
             continue;
         }
         if (isprefix(buf, "COPYRIGHT ")) {	/* not required*/
-            if (sscanf(buf, "COPYRIGHT \"%[^\"]", copyright) != 1) {
+            if (sscanf(buf, "COPYRIGHT \"%s\"", copyright) != 1) {
                 fprintf(stderr, "Error: bad 'COPYRIGHT'\n");
                 return 0;
             }
Index: firmware/include/lru.h
===================================================================
RCS file: /cvsroot/rockbox/firmware/include/lru.h,v
retrieving revision 1.1
diff -u -r1.1 lru.h
--- firmware/include/lru.h	6 Dec 2005 13:27:01 -0000	1.1
+++ firmware/include/lru.h	28 Aug 2006 10:32:17 -0000
@@ -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 */
 
Index: firmware/include/font_cache.h
===================================================================
RCS file: /cvsroot/rockbox/firmware/include/font_cache.h,v
retrieving revision 1.1
diff -u -r1.1 font_cache.h
--- firmware/include/font_cache.h	6 Dec 2005 13:27:01 -0000	1.1
+++ firmware/include/font_cache.h	28 Aug 2006 10:32:17 -0000
@@ -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);
Index: apps/plugins/chessbox/chessbox.c
===================================================================
RCS file: /cvsroot/rockbox/apps/plugins/chessbox/chessbox.c,v
retrieving revision 1.14
diff -u -r1.14 chessbox.c
--- apps/plugins/chessbox/chessbox.c	3 Aug 2006 20:17:21 -0000	1.14
+++ apps/plugins/chessbox/chessbox.c	28 Aug 2006 10:32:04 -0000
@@ -709,7 +709,8 @@
     }
     
     cb_saveposition();
-    rb->lcd_setfont(FONT_UI);
+    rb->lcd_setfont(FONT_PLUGIN);
+
     return PLUGIN_OK;
 }
 
Index: apps/plugins/rockblox.c
===================================================================
RCS file: /cvsroot/rockbox/apps/plugins/rockblox.c,v
retrieving revision 1.11
diff -u -r1.11 rockblox.c
--- apps/plugins/rockblox.c	19 Sep 2006 20:48:44 -0000	1.11
+++ apps/plugins/rockblox.c	28 Sep 2006 12:40:10 -0000
@@ -860,7 +860,7 @@
     ret = rockblox_loop ();
 
     /* Lets use the default font */
-    rb->lcd_setfont (FONT_UI);
+    rb->lcd_setfont (FONT_BROWSER);
     /* Restore user's original backlight setting */
     rb->backlight_set_timeout (rb->global_settings->backlight_timeout);
 
Index: apps/plugins/zxbox/zxbox_keyb.c
===================================================================
RCS file: /cvsroot/rockbox/apps/plugins/zxbox/zxbox_keyb.c,v
retrieving revision 1.1
diff -u -r1.1 zxbox_keyb.c
--- apps/plugins/zxbox/zxbox_keyb.c	15 Sep 2006 11:11:16 -0000	1.1
+++ apps/plugins/zxbox/zxbox_keyb.c	28 Sep 2006 12:44:35 -0000
@@ -373,7 +373,7 @@
 
             case KBD_ABORT:
                 FOR_NB_SCREENS(l)
-                    rb->screens[l]->setfont(FONT_UI);
+                    rb->screens[l]->setfont(FONT_BROWSER);
 
                 return -1;
                 break;
@@ -492,6 +492,6 @@
         }
     }
     FOR_NB_SCREENS(l)
-        rb->screens[l]->setfont(FONT_UI);
+        rb->screens[l]->setfont(FONT_BROWSER);
     return 0;
 }
