Attached is 90% of the work to do this somewhat more nicely. The remaining work is to check each plugin and make sure they don't use lcd_setfont() directly (which a quick look shows alot do :( ) the quick fix for that is just put a wrapper in the plugin api for it like what has been added for the screen_access api.
On 23 October 2011 16:31, Jonathan Gordon <jdgo...@gmail.com> wrote: > Can this please be reverted? firmware/fonts.c should now know or care > about the ui font at all, and post buflib fonts it doesnt. > screen_access.c added a helper to set the font > (screens[screen].set_font() ) which should be being used by the > keyboard and lrcviewer. If those are still having issues then that > helper might need more work. (actually it appears keyboard.c needs to > use font_get() which has no helper to get > global_status.font_id[screen]. > > Ideally a font_get_height() function be added which (to the screen > api) to get the correct font height seen as that is what most calls to > font_get() actually care about. > > On 23 October 2011 04:13, <mai...@svn.rockbox.org> wrote: >> Date: 2011-10-22 19:13:33 +0200 (Sat, 22 Oct 2011) >> New Revision: 30826 >> >> Log Message: >> Add functions font_set_ui() and font_get_ui(). The font returned by FONT_UI >> used to be fixed at zero but since buflib-fonts (r30589) can be different, >> depending on the order of loads and unloads. Fixes broken behavoir in >> virtual keyboard (FS#12336), lyrics player (FS#12306), and hopefully, >> FS#12337 >> >> Modified: >> trunk/apps/filetree.c >> trunk/apps/gui/list.c >> trunk/apps/settings.c >> trunk/firmware/export/font.h >> trunk/firmware/font.c >> >> Modified: trunk/apps/filetree.c >> =================================================================== >> --- trunk/apps/filetree.c 2011-10-22 15:28:09 UTC (rev 30825) >> +++ trunk/apps/filetree.c 2011-10-22 17:13:33 UTC (rev 30826) >> @@ -427,7 +427,10 @@ >> current_font_id = global_status.font_id[screen]; >> if (current_font_id >= 0) >> font_unload(current_font_id); >> - global_status.font_id[screen] = font_load(file); >> + current_font_id = font_load(file); >> + if(screen==SCREEN_MAIN) >> + font_set_ui(current_font_id); >> + global_status.font_id[screen] = current_font_id; >> viewportmanager_theme_changed(THEME_UI_VIEWPORT); >> } >> #endif >> >> Modified: trunk/apps/gui/list.c >> =================================================================== >> --- trunk/apps/gui/list.c 2011-10-22 15:28:09 UTC (rev 30825) >> +++ trunk/apps/gui/list.c 2011-10-22 17:13:33 UTC (rev 30826) >> @@ -133,6 +133,7 @@ >> static int list_get_nb_lines(struct gui_synclist *list, enum screen_type >> screen) >> { >> struct viewport *vp = list->parent[screen]; >> + vp->line_height = font_get(vp->font)->height; >> int lines = skinlist_get_line_count(screen, list); >> if (lines < 0) >> { >> >> Modified: trunk/apps/settings.c >> =================================================================== >> --- trunk/apps/settings.c 2011-10-22 15:28:09 UTC (rev 30825) >> +++ trunk/apps/settings.c 2011-10-22 17:13:33 UTC (rev 30826) >> @@ -886,6 +886,7 @@ >> if (global_status.font_id[SCREEN_MAIN] >= 0) >> font_unload(global_status.font_id[SCREEN_MAIN]); >> rc = font_load(buf); >> + font_set_ui(rc); >> CHART2("<font_load ", global_settings.font_file); >> global_status.font_id[SCREEN_MAIN] = rc; >> lcd_setfont(rc); >> >> Modified: trunk/firmware/export/font.h >> =================================================================== >> --- trunk/firmware/export/font.h 2011-10-22 15:28:09 UTC (rev 30825) >> +++ trunk/firmware/export/font.h 2011-10-22 17:13:33 UTC (rev 30826) >> @@ -55,7 +55,7 @@ >> >> /* SYSFONT, FONT_UI, FONT_UI_REMOTE + MAXUSERFONTS fonts in skins */ >> #define MAXFONTS (FONT_FIRSTUSERFONT + MAXUSERFONTS) >> -#define FONT_UI MAXFONTS >> +#define FONT_UI MAXUSERFONTS >> >> /* >> * .fnt loadable font file format definition >> @@ -124,6 +124,9 @@ >> void font_unload(int font_id); >> void font_unload_all(void); >> void font_lock(int font_id, bool lock); >> +/* set the default UI font */ >> +void font_set_ui(int font_id); >> +int font_get_ui(void); >> >> struct font* font_get(int font); >> >> >> Modified: trunk/firmware/font.c >> =================================================================== >> --- trunk/firmware/font.c 2011-10-22 15:28:09 UTC (rev 30825) >> +++ trunk/firmware/font.c 2011-10-22 17:13:33 UTC (rev 30826) >> @@ -88,6 +88,7 @@ >> }; >> static int buflib_allocations[MAXFONTS]; >> >> +static int font_ui = -1; >> static int cache_fd; >> static struct font* cache_pf; >> >> @@ -559,7 +560,7 @@ >> >> lock_font_handle(handle, false); >> buflib_allocations[font_id] = handle; >> - //printf("%s -> [%d] -> %d\n", path, font_id, *handle); >> + //printf("%s -> [%d] -> %d\n", path, font_id, handle); >> return font_id; /* success!*/ >> } >> int font_load(const char *path) >> @@ -616,30 +617,54 @@ >> >> /* >> * Return a pointer to an incore font structure. >> - * If the requested font isn't loaded/compiled-in, >> - * decrement the font number and try again. >> + * Return the requested font, font_ui, or sysfont >> */ >> -struct font* font_get(int font) >> +struct font* font_get(int font_id) >> { >> - struct font* pf; >> - if (font == FONT_UI) >> - font = MAXFONTS-1; >> - if (font <= FONT_SYSFIXED) >> + struct buflib_alloc_data *alloc; >> + struct font *pf; >> + int handle, id=-1; >> + >> + if( font_id == FONT_UI ) >> + id = font_ui; >> + >> + if( font_id == FONT_SYSFIXED ) >> return &sysfont; >> + >> + if( id == -1 ) >> + id = font_id; >> + >> + handle = buflib_allocations[id]; >> + if( handle > 0 ) >> + { >> + alloc = core_get_data(buflib_allocations[id]); >> + pf=&alloc->font; >> + if( pf && pf->height ) >> + return pf; >> + } >> + handle = buflib_allocations[font_ui]; >> + if( handle > 0 ) >> + { >> + alloc = core_get_data(buflib_allocations[font_ui]); >> + pf=&alloc->font; >> + if( pf && pf->height ) >> + return pf; >> + } >> >> - while (1) { >> - if (buflib_allocations[font] > 0) >> - { >> - struct buflib_alloc_data *alloc = >> core_get_data(buflib_allocations[font]); >> - pf = &alloc->font; >> - if (pf && pf->height) >> - return pf; >> - } >> - if (--font < 0) >> - return &sysfont; >> - } >> + return &sysfont; >> } >> >> +void font_set_ui( int font_id ) >> +{ >> + font_ui = font_id; >> + return; >> +} >> + >> +int font_get_ui() >> +{ >> + return font_ui; >> +} >> + >> static int pf_to_handle(struct font* pf) >> { >> int i; >> @@ -980,6 +1005,18 @@ >> return &sysfont; >> } >> >> +void font_set_ui(int font_id) >> +{ >> + (void)font_id; >> + return; >> +} >> + >> +int font_get_ui() >> +{ >> + return FONT_SYSFIXED; >> +} >> + >> + >> /* >> * Returns width of character >> */ >> >> _______________________________________________ >> rockbox-cvs mailing list >> rockbox-...@cool.haxx.se >> http://cool.haxx.se/cgi-bin/mailman/listinfo/rockbox-cvs >> >
diff --git a/apps/filetree.c b/apps/filetree.c index 2407be9..fe3980a 100644 --- a/apps/filetree.c +++ b/apps/filetree.c @@ -424,13 +424,10 @@ static void ft_load_font(char *file) set_file(file, (char *)global_settings.font_file, MAX_FILENAME); #endif splash(0, ID2P(LANG_WAIT)); - current_font_id = global_status.font_id[screen]; + current_font_id = screens[screen].getuifont(); if (current_font_id >= 0) font_unload(current_font_id); - current_font_id = font_load(file); - if(screen==SCREEN_MAIN) - font_set_ui(current_font_id); - global_status.font_id[screen] = current_font_id; + screens[screen].(setuifont(font_load(file)); viewportmanager_theme_changed(THEME_UI_VIEWPORT); } #endif diff --git a/apps/gui/skin_engine/skin_parser.c b/apps/gui/skin_engine/skin_parser.c index a9689a8..c6632b86 100644 --- a/apps/gui/skin_engine/skin_parser.c +++ b/apps/gui/skin_engine/skin_parser.c @@ -249,7 +249,7 @@ static int parse_statusbar_tags(struct skin_element* element, /* viewport_set_defaults() sets the font to FONT_UI+curr_screen. * This parser requires font 1 to always be the UI font, * so force it back to FONT_UI and handle the screen number at the end */ - default_vp->vp.font = FONT_UI; + default_vp->vp.font = 1; #endif } return 0; @@ -1645,7 +1645,7 @@ static bool skin_load_fonts(struct wps_data *data) font_id = skin_vp->parsed_fontid; if (font_id == 1) { /* the usual case -> built-in fonts */ - vp->font = global_status.font_id[curr_screen]; + vp->font = screens[curr_screen].getuifont(); continue; } else if (font_id <= 0) diff --git a/apps/gui/skin_engine/skin_render.c b/apps/gui/skin_engine/skin_render.c index 369bd46..4d41a6f 100644 --- a/apps/gui/skin_engine/skin_render.c +++ b/apps/gui/skin_engine/skin_render.c @@ -658,7 +658,7 @@ void skin_render_viewport(struct skin_element* viewport, struct gui_wps *gwps, /* fix font ID's */ if (skin_viewport->parsed_fontid == 1) - skin_viewport->vp.font = global_status.font_id[display->screen_type]; + skin_viewport->vp.font = display->getuifont(); #endif while (line) diff --git a/apps/gui/statusbar-skinned.c b/apps/gui/statusbar-skinned.c index 7850e7c..f79672c 100644 --- a/apps/gui/statusbar-skinned.c +++ b/apps/gui/statusbar-skinned.c @@ -128,7 +128,7 @@ struct viewport *sb_skin_get_info_vp(enum screen_type screen) if (!vp) return NULL; if (vp->parsed_fontid == 1) - vp->vp.font = global_status.font_id[screen]; + vp->vp.font = screens[screen].getuifont(); return &vp->vp; } diff --git a/apps/gui/usb_screen.c b/apps/gui/usb_screen.c index 06770b1..2b7d472 100644 --- a/apps/gui/usb_screen.c +++ b/apps/gui/usb_screen.c @@ -265,8 +265,8 @@ void gui_usb_screen_run(bool early_usb) #ifdef HAVE_LCD_BITMAP FOR_NB_SCREENS(i) { - font_unload(global_status.font_id[i]); - global_status.font_id[i] = -1; + font_unload(screens[i].getuifont()); + screens[i].setuifont(FONT_SYSFIXED); } skin_unload_all(); #endif diff --git a/apps/gui/viewport.c b/apps/gui/viewport.c index c5e4427..b17f765 100644 --- a/apps/gui/viewport.c +++ b/apps/gui/viewport.c @@ -317,7 +317,7 @@ void viewport_set_fullscreen(struct viewport *vp, #ifndef __PCTOOL__ set_default_align_flags(vp); #endif - vp->font = global_status.font_id[screen]; + vp->font = screens[screen].getuifont(); vp->line_height = font_get(vp->font)->height; vp->drawmode = DRMODE_SOLID; #if LCD_DEPTH > 1 diff --git a/apps/plugins/bubbles.c b/apps/plugins/bubbles.c index d9f76f7..1c4bbca 100644 --- a/apps/plugins/bubbles.c +++ b/apps/plugins/bubbles.c @@ -1435,7 +1435,7 @@ static void bubbles_drawboard(struct game_context* bb) { /* clear screen */ rb->lcd_clear_display(); - int font = rb->screens[SCREEN_MAIN]->getfont(); + int font = rb->screens[SCREEN_MAIN]->getuifont(); h = rb->font_get(font)->height + 1; /* draw background */ #ifdef HAVE_LCD_COLOR diff --git a/apps/recorder/keyboard.c b/apps/recorder/keyboard.c index c4cfe48..4910c74 100644 --- a/apps/recorder/keyboard.c +++ b/apps/recorder/keyboard.c @@ -720,7 +720,7 @@ static void kbd_calc_params(struct keyboard_parameters *pm, (touchscreen_get_mode() == TOUCHSCREEN_POINT)); #endif - pm->curfont = pm->default_lines ? FONT_SYSFIXED : FONT_UI; + pm->curfont = pm->default_lines ? FONT_SYSFIXED : sc->getuifont(); font = font_get(pm->curfont); pm->font_h = font->height; diff --git a/apps/screen_access.c b/apps/screen_access.c index 01fdebe..ac0f31d 100644 --- a/apps/screen_access.c +++ b/apps/screen_access.c @@ -77,6 +77,22 @@ void screen_helper_setfont(int font) #endif } +int screen_helper_getuifont(void) +{ +#ifdef HAVE_LCD_BITMAP + return global_status.font_id[SCREEN_MAIN]; +#else + return FONT_SYSFIXED; +#endif +} + +void screen_helper_setuifont(int font) +{ +#ifdef HAVE_LCD_BITMAP + global_status.font_id[SCREEN_MAIN] = font; +#endif +} + #if NB_SCREENS == 2 static int screen_helper_remote_getcharwidth(void) { @@ -116,6 +132,23 @@ void screen_helper_remote_setfont(int font) font = global_status.font_id[SCREEN_REMOTE]; lcd_remote_setfont(font); } + +int screen_helper_remote_getuifont(void) +{ +#ifdef HAVE_LCD_BITMAP + return global_status.font_id[SCREEN_REMOTE]; +#else + return FONT_SYSFIXED; +#endif +} + +void screen_helper_remote_setuifont(int font) +{ +#ifdef HAVE_LCD_BITMAP + global_status.font_id[SCREEN_REMOTE] = font; +#endif +} + #endif struct screen screens[NB_SCREENS] = @@ -147,7 +180,8 @@ struct screen screens[NB_SCREENS] = .getstringsize=&lcd_getstringsize, #ifdef HAVE_LCD_BITMAP .setfont=screen_helper_setfont, - .getfont=&lcd_getfont, + .getuifont=screen_helper_getuifont, + .setuifont=screen_helper_setuifont, .mono_bitmap=&lcd_mono_bitmap, .mono_bitmap_part=&lcd_mono_bitmap_part, .set_drawmode=&lcd_set_drawmode, @@ -246,8 +280,9 @@ struct screen screens[NB_SCREENS] = .getheight=&lcd_remote_getheight, .getstringsize=&lcd_remote_getstringsize, #if 1 /* all remote LCDs are bitmapped so far */ - .setfont=screen_helper_setfont, - .getfont=&lcd_remote_getfont, + .setfont=screen_helper_remote_setfont, + .getuifont=screen_helper_remote_getuifont, + .setuifont=screen_helper_remote_setuifont, .mono_bitmap=&lcd_remote_mono_bitmap, .mono_bitmap_part=&lcd_remote_mono_bitmap_part, .bitmap=(screen_bitmap_func*)&lcd_remote_bitmap, diff --git a/apps/screen_access.h b/apps/screen_access.h index 2713219..04cc6f4 100644 --- a/apps/screen_access.h +++ b/apps/screen_access.h @@ -71,7 +71,8 @@ struct screen int (*getstringsize)(const unsigned char *str, int *w, int *h); #if defined(HAVE_LCD_BITMAP) || defined(HAVE_REMOTE_LCD) /* always bitmap */ void (*setfont)(int newfont); - int (*getfont)(void); + int (*getuifont)(void); + void (*setuifont)(int newfont); void (*scroll_step)(int pixels); void (*puts_style_offset)(int x, int y, const unsigned char *str, diff --git a/apps/settings.c b/apps/settings.c index 7142cfb..fbfa438 100644 --- a/apps/settings.c +++ b/apps/settings.c @@ -876,37 +876,38 @@ void settings_apply(bool read_disk) /* fonts need to be loaded before the WPS */ if (global_settings.font_file[0] && global_settings.font_file[0] != '-') { - const char* loaded_font = font_filename(global_status.font_id[SCREEN_MAIN]); + int font_ui = screens[SCREEN_MAIN].getuifont(); + const char* loaded_font = font_filename(font_ui); snprintf(buf, sizeof buf, FONT_DIR "/%s.fnt", global_settings.font_file); if (!loaded_font || strcmp(loaded_font, buf)) { CHART2(">font_load ", global_settings.font_file); - if (global_status.font_id[SCREEN_MAIN] >= 0) - font_unload(global_status.font_id[SCREEN_MAIN]); + if (font_ui >= 0) + font_unload(font_ui); rc = font_load(buf); - font_set_ui(rc); CHART2("<font_load ", global_settings.font_file); - global_status.font_id[SCREEN_MAIN] = rc; - lcd_setfont(rc); + screens[SCREEN_MAIN].setuifont(rc); + screens[SCREEN_MAIN].setfont(rc); } } #ifdef HAVE_REMOTE_LCD if ( global_settings.remote_font_file[0] && global_settings.remote_font_file[0] != '-') { - const char* loaded_font = font_filename(global_status.font_id[SCREEN_REMOTE]); + int font_ui = screens[SCREEN_REMOTE].getuifont(); + const char* loaded_font = font_filename(font_ui); snprintf(buf, sizeof buf, FONT_DIR "/%s.fnt", global_settings.remote_font_file); if (!loaded_font || strcmp(loaded_font, buf)) { CHART2(">font_load_remoteui ", global_settings.remote_font_file); - if (global_status.font_id[SCREEN_REMOTE] >= 0) - font_unload(global_status.font_id[SCREEN_REMOTE]); + if (font_ui >= 0) + font_unload(font_ui); rc = font_load(buf); CHART2("<font_load_remoteui ", global_settings.remote_font_file); - global_status.font_id[SCREEN_REMOTE] = rc; - lcd_remote_setfont(rc); + screens[SCREEN_REMOTE].setuifont(rc); + screens[SCREEN_REMOTE].setfont(rc); } } #endif @@ -1076,10 +1077,11 @@ void settings_reset(void) #ifdef HAVE_LCD_BITMAP FOR_NB_SCREENS(i) { - if (global_status.font_id[i] > FONT_SYSFIXED) + if (screens[i].getuifont() > FONT_SYSFIXED) { - font_unload(global_status.font_id[i]); - global_status.font_id[i] = FONT_SYSFIXED; + font_unload(screens[i].getuifont()); + screens[i].setuifont(FONT_SYSFIXED); + screens[i].setfont(FONT_SYSFIXED); } } #endif diff --git a/firmware/export/font.h b/firmware/export/font.h index 76f86c8..914d3aa 100644 --- a/firmware/export/font.h +++ b/firmware/export/font.h @@ -55,7 +55,7 @@ enum { /* SYSFONT, FONT_UI, FONT_UI_REMOTE + MAXUSERFONTS fonts in skins */ #define MAXFONTS (FONT_FIRSTUSERFONT + MAXUSERFONTS) -#define FONT_UI MAXUSERFONTS +#define FONT_UI MAXFONTS /* * .fnt loadable font file format definition @@ -124,9 +124,6 @@ int font_glyphs_to_bufsize(const char *path, int glyphs); void font_unload(int font_id); void font_unload_all(void); void font_lock(int font_id, bool lock); -/* set the default UI font */ -void font_set_ui(int font_id); -int font_get_ui(void); struct font* font_get(int font); diff --git a/firmware/font.c b/firmware/font.c index eb15bb7..f1cddb0 100644 --- a/firmware/font.c +++ b/firmware/font.c @@ -88,7 +88,6 @@ struct buflib_alloc_data { }; static int buflib_allocations[MAXFONTS]; -static int font_ui = -1; static int cache_fd; static struct font* cache_pf; @@ -560,7 +559,7 @@ int font_load_ex(const char *path, size_t buffer_size) lock_font_handle(handle, false); buflib_allocations[font_id] = handle; - //printf("%s -> [%d] -> %d\n", path, font_id, handle); + //printf("%s -> [%d] -> %d\n", path, font_id, *handle); return font_id; /* success!*/ } int font_load(const char *path) @@ -617,52 +616,28 @@ void font_unload_all(void) /* * Return a pointer to an incore font structure. - * Return the requested font, font_ui, or sysfont + * If the requested font isn't loaded/compiled-in, + * decrement the font number and try again. */ -struct font* font_get(int font_id) +struct font* font_get(int font) { - struct buflib_alloc_data *alloc; - struct font *pf; - int handle, id=-1; - - if( font_id == FONT_UI ) - id = font_ui; - - if( font_id == FONT_SYSFIXED ) + struct font* pf; + if (font == FONT_UI) + font = MAXFONTS-1; + if (font <= FONT_SYSFIXED) return &sysfont; - - if( id == -1 ) - id = font_id; - - handle = buflib_allocations[id]; - if( handle > 0 ) - { - alloc = core_get_data(buflib_allocations[id]); - pf=&alloc->font; - if( pf && pf->height ) - return pf; - } - handle = buflib_allocations[font_ui]; - if( handle > 0 ) - { - alloc = core_get_data(buflib_allocations[font_ui]); - pf=&alloc->font; - if( pf && pf->height ) - return pf; - } - - return &sysfont; -} - -void font_set_ui( int font_id ) -{ - font_ui = font_id; - return; -} -int font_get_ui() -{ - return font_ui; + while (1) { + if (buflib_allocations[font] > 0) + { + struct buflib_alloc_data *alloc = core_get_data(buflib_allocations[font]); + pf = &alloc->font; + if (pf && pf->height) + return pf; + } + if (--font < 0) + return &sysfont; + } } static int pf_to_handle(struct font* pf) @@ -1005,18 +980,6 @@ struct font* font_get(int font) return &sysfont; } -void font_set_ui(int font_id) -{ - (void)font_id; - return; -} - -int font_get_ui() -{ - return FONT_SYSFIXED; -} - - /* * Returns width of character */