diff options
| author | Fred Bauer <fred.w.bauer@gmail.com> | 2011-10-22 17:13:33 +0000 |
|---|---|---|
| committer | Fred Bauer <fred.w.bauer@gmail.com> | 2011-10-22 17:13:33 +0000 |
| commit | e299eb3ea36cba48875cf35bb1dcc93eaba0d279 (patch) | |
| tree | a2d9e853522207fae414d82c9f5e6dba81252ea4 | |
| parent | 4d2ab32339fb8e7c02841e52d35498081503d188 (diff) | |
| download | rockbox-e299eb3ea36cba48875cf35bb1dcc93eaba0d279.zip rockbox-e299eb3ea36cba48875cf35bb1dcc93eaba0d279.tar.gz rockbox-e299eb3ea36cba48875cf35bb1dcc93eaba0d279.tar.bz2 rockbox-e299eb3ea36cba48875cf35bb1dcc93eaba0d279.tar.xz | |
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
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30826 a1c6a512-1295-4272-9138-f99709370657
| -rw-r--r-- | apps/filetree.c | 5 | ||||
| -rw-r--r-- | apps/gui/list.c | 1 | ||||
| -rw-r--r-- | apps/settings.c | 1 | ||||
| -rw-r--r-- | firmware/export/font.h | 5 | ||||
| -rw-r--r-- | firmware/font.c | 75 |
5 files changed, 66 insertions, 21 deletions
diff --git a/apps/filetree.c b/apps/filetree.c index 59e7343..2407be9 100644 --- a/apps/filetree.c +++ b/apps/filetree.c @@ -427,7 +427,10 @@ static void ft_load_font(char *file) 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 diff --git a/apps/gui/list.c b/apps/gui/list.c index f875a65..4a51bda 100644 --- a/apps/gui/list.c +++ b/apps/gui/list.c @@ -133,6 +133,7 @@ bool list_display_title(struct gui_synclist *list, enum screen_type screen) 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) { diff --git a/apps/settings.c b/apps/settings.c index 21665e0..7142cfb 100644 --- a/apps/settings.c +++ b/apps/settings.c @@ -886,6 +886,7 @@ void settings_apply(bool read_disk) 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); diff --git a/firmware/export/font.h b/firmware/export/font.h index 914d3aa..76f86c8 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 MAXFONTS +#define FONT_UI MAXUSERFONTS /* * .fnt loadable font file format definition @@ -124,6 +124,9 @@ 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 f1cddb0..eb15bb7 100644 --- a/firmware/font.c +++ b/firmware/font.c @@ -88,6 +88,7 @@ struct buflib_alloc_data { }; static int buflib_allocations[MAXFONTS]; +static int font_ui = -1; static int cache_fd; static struct font* cache_pf; @@ -559,7 +560,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) @@ -616,28 +617,52 @@ void font_unload_all(void) /* * 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) - return &sysfont; + struct buflib_alloc_data *alloc; + struct font *pf; + int handle, id=-1; - 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; + 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; } + + 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) @@ -980,6 +1005,18 @@ 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 */ |