summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFred Bauer <fred.w.bauer@gmail.com>2011-10-22 17:13:33 +0000
committerFred Bauer <fred.w.bauer@gmail.com>2011-10-22 17:13:33 +0000
commite299eb3ea36cba48875cf35bb1dcc93eaba0d279 (patch)
treea2d9e853522207fae414d82c9f5e6dba81252ea4
parent4d2ab32339fb8e7c02841e52d35498081503d188 (diff)
downloadrockbox-e299eb3ea36cba48875cf35bb1dcc93eaba0d279.tar.gz
rockbox-e299eb3ea36cba48875cf35bb1dcc93eaba0d279.zip
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.c5
-rw-r--r--apps/gui/list.c1
-rw-r--r--apps/settings.c1
-rw-r--r--firmware/export/font.h5
-rw-r--r--firmware/font.c75
5 files changed, 66 insertions, 21 deletions
diff --git a/apps/filetree.c b/apps/filetree.c
index 59e7343600..2407be9d79 100644
--- a/apps/filetree.c
+++ b/apps/filetree.c
@@ -427,7 +427,10 @@ static void ft_load_font(char *file)
427 current_font_id = global_status.font_id[screen]; 427 current_font_id = global_status.font_id[screen];
428 if (current_font_id >= 0) 428 if (current_font_id >= 0)
429 font_unload(current_font_id); 429 font_unload(current_font_id);
430 global_status.font_id[screen] = font_load(file); 430 current_font_id = font_load(file);
431 if(screen==SCREEN_MAIN)
432 font_set_ui(current_font_id);
433 global_status.font_id[screen] = current_font_id;
431 viewportmanager_theme_changed(THEME_UI_VIEWPORT); 434 viewportmanager_theme_changed(THEME_UI_VIEWPORT);
432} 435}
433#endif 436#endif
diff --git a/apps/gui/list.c b/apps/gui/list.c
index f875a6559e..4a51bdace4 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)
133static int list_get_nb_lines(struct gui_synclist *list, enum screen_type screen) 133static int list_get_nb_lines(struct gui_synclist *list, enum screen_type screen)
134{ 134{
135 struct viewport *vp = list->parent[screen]; 135 struct viewport *vp = list->parent[screen];
136 vp->line_height = font_get(vp->font)->height;
136 int lines = skinlist_get_line_count(screen, list); 137 int lines = skinlist_get_line_count(screen, list);
137 if (lines < 0) 138 if (lines < 0)
138 { 139 {
diff --git a/apps/settings.c b/apps/settings.c
index 21665e0c6a..7142cfb0c6 100644
--- a/apps/settings.c
+++ b/apps/settings.c
@@ -886,6 +886,7 @@ void settings_apply(bool read_disk)
886 if (global_status.font_id[SCREEN_MAIN] >= 0) 886 if (global_status.font_id[SCREEN_MAIN] >= 0)
887 font_unload(global_status.font_id[SCREEN_MAIN]); 887 font_unload(global_status.font_id[SCREEN_MAIN]);
888 rc = font_load(buf); 888 rc = font_load(buf);
889 font_set_ui(rc);
889 CHART2("<font_load ", global_settings.font_file); 890 CHART2("<font_load ", global_settings.font_file);
890 global_status.font_id[SCREEN_MAIN] = rc; 891 global_status.font_id[SCREEN_MAIN] = rc;
891 lcd_setfont(rc); 892 lcd_setfont(rc);
diff --git a/firmware/export/font.h b/firmware/export/font.h
index 914d3aa2ff..76f86c845f 100644
--- a/firmware/export/font.h
+++ b/firmware/export/font.h
@@ -55,7 +55,7 @@ enum {
55 55
56/* SYSFONT, FONT_UI, FONT_UI_REMOTE + MAXUSERFONTS fonts in skins */ 56/* SYSFONT, FONT_UI, FONT_UI_REMOTE + MAXUSERFONTS fonts in skins */
57#define MAXFONTS (FONT_FIRSTUSERFONT + MAXUSERFONTS) 57#define MAXFONTS (FONT_FIRSTUSERFONT + MAXUSERFONTS)
58#define FONT_UI MAXFONTS 58#define FONT_UI MAXUSERFONTS
59 59
60/* 60/*
61 * .fnt loadable font file format definition 61 * .fnt loadable font file format definition
@@ -124,6 +124,9 @@ int font_glyphs_to_bufsize(const char *path, int glyphs);
124void font_unload(int font_id); 124void font_unload(int font_id);
125void font_unload_all(void); 125void font_unload_all(void);
126void font_lock(int font_id, bool lock); 126void font_lock(int font_id, bool lock);
127/* set the default UI font */
128void font_set_ui(int font_id);
129int font_get_ui(void);
127 130
128struct font* font_get(int font); 131struct font* font_get(int font);
129 132
diff --git a/firmware/font.c b/firmware/font.c
index f1cddb0f3c..eb15bb7420 100644
--- a/firmware/font.c
+++ b/firmware/font.c
@@ -88,6 +88,7 @@ struct buflib_alloc_data {
88}; 88};
89static int buflib_allocations[MAXFONTS]; 89static int buflib_allocations[MAXFONTS];
90 90
91static int font_ui = -1;
91static int cache_fd; 92static int cache_fd;
92static struct font* cache_pf; 93static struct font* cache_pf;
93 94
@@ -559,7 +560,7 @@ int font_load_ex(const char *path, size_t buffer_size)
559 560
560 lock_font_handle(handle, false); 561 lock_font_handle(handle, false);
561 buflib_allocations[font_id] = handle; 562 buflib_allocations[font_id] = handle;
562 //printf("%s -> [%d] -> %d\n", path, font_id, *handle); 563 //printf("%s -> [%d] -> %d\n", path, font_id, handle);
563 return font_id; /* success!*/ 564 return font_id; /* success!*/
564} 565}
565int font_load(const char *path) 566int font_load(const char *path)
@@ -616,28 +617,52 @@ void font_unload_all(void)
616 617
617/* 618/*
618 * Return a pointer to an incore font structure. 619 * Return a pointer to an incore font structure.
619 * If the requested font isn't loaded/compiled-in, 620 * Return the requested font, font_ui, or sysfont
620 * decrement the font number and try again.
621 */ 621 */
622struct font* font_get(int font) 622struct font* font_get(int font_id)
623{ 623{
624 struct font* pf; 624 struct buflib_alloc_data *alloc;
625 if (font == FONT_UI) 625 struct font *pf;
626 font = MAXFONTS-1; 626 int handle, id=-1;
627 if (font <= FONT_SYSFIXED)
628 return &sysfont;
629 627
630 while (1) { 628 if( font_id == FONT_UI )
631 if (buflib_allocations[font] > 0) 629 id = font_ui;
632 { 630
633 struct buflib_alloc_data *alloc = core_get_data(buflib_allocations[font]); 631 if( font_id == FONT_SYSFIXED )
634 pf = &alloc->font; 632 return &sysfont;
635 if (pf && pf->height) 633
636 return pf; 634 if( id == -1 )
637 } 635 id = font_id;
638 if (--font < 0) 636
639 return &sysfont; 637 handle = buflib_allocations[id];
638 if( handle > 0 )
639 {
640 alloc = core_get_data(buflib_allocations[id]);
641 pf=&alloc->font;
642 if( pf && pf->height )
643 return pf;
644 }
645 handle = buflib_allocations[font_ui];
646 if( handle > 0 )
647 {
648 alloc = core_get_data(buflib_allocations[font_ui]);
649 pf=&alloc->font;
650 if( pf && pf->height )
651 return pf;
640 } 652 }
653
654 return &sysfont;
655}
656
657void font_set_ui( int font_id )
658{
659 font_ui = font_id;
660 return;
661}
662
663int font_get_ui()
664{
665 return font_ui;
641} 666}
642 667
643static int pf_to_handle(struct font* pf) 668static int pf_to_handle(struct font* pf)
@@ -980,6 +1005,18 @@ struct font* font_get(int font)
980 return &sysfont; 1005 return &sysfont;
981} 1006}
982 1007
1008void font_set_ui(int font_id)
1009{
1010 (void)font_id;
1011 return;
1012}
1013
1014int font_get_ui()
1015{
1016 return FONT_SYSFIXED;
1017}
1018
1019
983/* 1020/*
984 * Returns width of character 1021 * Returns width of character
985 */ 1022 */