summaryrefslogtreecommitdiff
path: root/firmware
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 /firmware
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
Diffstat (limited to 'firmware')
-rw-r--r--firmware/export/font.h5
-rw-r--r--firmware/font.c75
2 files changed, 60 insertions, 20 deletions
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 */