summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/filetree.c7
-rw-r--r--apps/gui/skin_engine/skin_parser.c12
-rw-r--r--apps/gui/skin_engine/skin_render.c2
-rw-r--r--apps/gui/statusbar-skinned.c2
-rw-r--r--apps/gui/usb_screen.c4
-rw-r--r--apps/gui/viewport.c2
-rw-r--r--apps/plugins/bubbles.c2
-rw-r--r--apps/recorder/keyboard.c2
-rw-r--r--apps/screen_access.c43
-rw-r--r--apps/screen_access.h3
-rw-r--r--apps/settings.c30
-rw-r--r--firmware/export/font.h5
-rw-r--r--firmware/font.c75
13 files changed, 94 insertions, 95 deletions
diff --git a/apps/filetree.c b/apps/filetree.c
index 2407be9d79..d33b823fc0 100644
--- a/apps/filetree.c
+++ b/apps/filetree.c
@@ -424,13 +424,10 @@ static void ft_load_font(char *file)
424 set_file(file, (char *)global_settings.font_file, MAX_FILENAME); 424 set_file(file, (char *)global_settings.font_file, MAX_FILENAME);
425#endif 425#endif
426 splash(0, ID2P(LANG_WAIT)); 426 splash(0, ID2P(LANG_WAIT));
427 current_font_id = global_status.font_id[screen]; 427 current_font_id = screens[screen].getuifont();
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 current_font_id = font_load(file); 430 screens[screen].setuifont(font_load(file));
431 if(screen==SCREEN_MAIN)
432 font_set_ui(current_font_id);
433 global_status.font_id[screen] = current_font_id;
434 viewportmanager_theme_changed(THEME_UI_VIEWPORT); 431 viewportmanager_theme_changed(THEME_UI_VIEWPORT);
435} 432}
436#endif 433#endif
diff --git a/apps/gui/skin_engine/skin_parser.c b/apps/gui/skin_engine/skin_parser.c
index 1557783a7c..d207a1fb3e 100644
--- a/apps/gui/skin_engine/skin_parser.c
+++ b/apps/gui/skin_engine/skin_parser.c
@@ -246,10 +246,12 @@ static int parse_statusbar_tags(struct skin_element* element,
246 viewport_set_fullscreen(&default_vp->vp, curr_screen); 246 viewport_set_fullscreen(&default_vp->vp, curr_screen);
247 } 247 }
248#ifdef HAVE_REMOTE_LCD 248#ifdef HAVE_REMOTE_LCD
249 /* viewport_set_defaults() sets the font to FONT_UI+curr_screen. 249 /* This parser requires viewports which will use the settings font to
250 * This parser requires font 1 to always be the UI font, 250 * have font == 1, but the above viewport_set() calls set font to
251 * so force it back to FONT_UI and handle the screen number at the end */ 251 * the current real font id. So force 1 here it will be set correctly
252 default_vp->vp.font = FONT_UI; 252 * at the end
253 */
254 default_vp->vp.font = 1;
253#endif 255#endif
254 } 256 }
255 return 0; 257 return 0;
@@ -1645,7 +1647,7 @@ static bool skin_load_fonts(struct wps_data *data)
1645 font_id = skin_vp->parsed_fontid; 1647 font_id = skin_vp->parsed_fontid;
1646 if (font_id == 1) 1648 if (font_id == 1)
1647 { /* the usual case -> built-in fonts */ 1649 { /* the usual case -> built-in fonts */
1648 vp->font = global_status.font_id[curr_screen]; 1650 vp->font = screens[curr_screen].getuifont();
1649 continue; 1651 continue;
1650 } 1652 }
1651 else if (font_id <= 0) 1653 else if (font_id <= 0)
diff --git a/apps/gui/skin_engine/skin_render.c b/apps/gui/skin_engine/skin_render.c
index 369bd46be5..4d41a6f9b7 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,
658 658
659 /* fix font ID's */ 659 /* fix font ID's */
660 if (skin_viewport->parsed_fontid == 1) 660 if (skin_viewport->parsed_fontid == 1)
661 skin_viewport->vp.font = global_status.font_id[display->screen_type]; 661 skin_viewport->vp.font = display->getuifont();
662#endif 662#endif
663 663
664 while (line) 664 while (line)
diff --git a/apps/gui/statusbar-skinned.c b/apps/gui/statusbar-skinned.c
index 7850e7cc27..f79672c0d9 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)
128 if (!vp) 128 if (!vp)
129 return NULL; 129 return NULL;
130 if (vp->parsed_fontid == 1) 130 if (vp->parsed_fontid == 1)
131 vp->vp.font = global_status.font_id[screen]; 131 vp->vp.font = screens[screen].getuifont();
132 return &vp->vp; 132 return &vp->vp;
133} 133}
134 134
diff --git a/apps/gui/usb_screen.c b/apps/gui/usb_screen.c
index 06770b1b94..2b7d47209b 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)
265#ifdef HAVE_LCD_BITMAP 265#ifdef HAVE_LCD_BITMAP
266 FOR_NB_SCREENS(i) 266 FOR_NB_SCREENS(i)
267 { 267 {
268 font_unload(global_status.font_id[i]); 268 font_unload(screens[i].getuifont());
269 global_status.font_id[i] = -1; 269 screens[i].setuifont(FONT_SYSFIXED);
270 } 270 }
271 skin_unload_all(); 271 skin_unload_all();
272#endif 272#endif
diff --git a/apps/gui/viewport.c b/apps/gui/viewport.c
index 33ffed79f3..940f7f9cfa 100644
--- a/apps/gui/viewport.c
+++ b/apps/gui/viewport.c
@@ -319,7 +319,7 @@ void viewport_set_fullscreen(struct viewport *vp,
319#ifndef __PCTOOL__ 319#ifndef __PCTOOL__
320 set_default_align_flags(vp); 320 set_default_align_flags(vp);
321#endif 321#endif
322 vp->font = global_status.font_id[screen]; 322 vp->font = screens[screen].getuifont();
323 vp->line_height = 0; /* calculate from font height */ 323 vp->line_height = 0; /* calculate from font height */
324 vp->drawmode = DRMODE_SOLID; 324 vp->drawmode = DRMODE_SOLID;
325#if LCD_DEPTH > 1 325#if LCD_DEPTH > 1
diff --git a/apps/plugins/bubbles.c b/apps/plugins/bubbles.c
index d9f76f7f72..1c4bbca788 100644
--- a/apps/plugins/bubbles.c
+++ b/apps/plugins/bubbles.c
@@ -1435,7 +1435,7 @@ static void bubbles_drawboard(struct game_context* bb) {
1435 1435
1436 /* clear screen */ 1436 /* clear screen */
1437 rb->lcd_clear_display(); 1437 rb->lcd_clear_display();
1438 int font = rb->screens[SCREEN_MAIN]->getfont(); 1438 int font = rb->screens[SCREEN_MAIN]->getuifont();
1439 h = rb->font_get(font)->height + 1; 1439 h = rb->font_get(font)->height + 1;
1440 /* draw background */ 1440 /* draw background */
1441#ifdef HAVE_LCD_COLOR 1441#ifdef HAVE_LCD_COLOR
diff --git a/apps/recorder/keyboard.c b/apps/recorder/keyboard.c
index c4cfe48ad9..4910c74877 100644
--- a/apps/recorder/keyboard.c
+++ b/apps/recorder/keyboard.c
@@ -720,7 +720,7 @@ static void kbd_calc_params(struct keyboard_parameters *pm,
720 (touchscreen_get_mode() == TOUCHSCREEN_POINT)); 720 (touchscreen_get_mode() == TOUCHSCREEN_POINT));
721#endif 721#endif
722 722
723 pm->curfont = pm->default_lines ? FONT_SYSFIXED : FONT_UI; 723 pm->curfont = pm->default_lines ? FONT_SYSFIXED : sc->getuifont();
724 font = font_get(pm->curfont); 724 font = font_get(pm->curfont);
725 pm->font_h = font->height; 725 pm->font_h = font->height;
726 726
diff --git a/apps/screen_access.c b/apps/screen_access.c
index 01fdebe0db..f07b906fda 100644
--- a/apps/screen_access.c
+++ b/apps/screen_access.c
@@ -77,6 +77,24 @@ void screen_helper_setfont(int font)
77#endif 77#endif
78} 78}
79 79
80int screen_helper_getuifont(void)
81{
82#ifdef HAVE_LCD_BITMAP
83 return global_status.font_id[SCREEN_MAIN];
84#else
85 return FONT_SYSFIXED;
86#endif
87}
88
89void screen_helper_setuifont(int font)
90{
91#ifdef HAVE_LCD_BITMAP
92 global_status.font_id[SCREEN_MAIN] = font;
93#else
94 (void)font;
95#endif
96}
97
80#if NB_SCREENS == 2 98#if NB_SCREENS == 2
81static int screen_helper_remote_getcharwidth(void) 99static int screen_helper_remote_getcharwidth(void)
82{ 100{
@@ -116,6 +134,23 @@ void screen_helper_remote_setfont(int font)
116 font = global_status.font_id[SCREEN_REMOTE]; 134 font = global_status.font_id[SCREEN_REMOTE];
117 lcd_remote_setfont(font); 135 lcd_remote_setfont(font);
118} 136}
137
138int screen_helper_remote_getuifont(void)
139{
140#ifdef HAVE_LCD_BITMAP
141 return global_status.font_id[SCREEN_REMOTE];
142#else
143 return FONT_SYSFIXED;
144#endif
145}
146
147void screen_helper_remote_setuifont(int font)
148{
149#ifdef HAVE_LCD_BITMAP
150 global_status.font_id[SCREEN_REMOTE] = font;
151#endif
152}
153
119#endif 154#endif
120 155
121struct screen screens[NB_SCREENS] = 156struct screen screens[NB_SCREENS] =
@@ -147,7 +182,8 @@ struct screen screens[NB_SCREENS] =
147 .getstringsize=&lcd_getstringsize, 182 .getstringsize=&lcd_getstringsize,
148#ifdef HAVE_LCD_BITMAP 183#ifdef HAVE_LCD_BITMAP
149 .setfont=screen_helper_setfont, 184 .setfont=screen_helper_setfont,
150 .getfont=&lcd_getfont, 185 .getuifont=screen_helper_getuifont,
186 .setuifont=screen_helper_setuifont,
151 .mono_bitmap=&lcd_mono_bitmap, 187 .mono_bitmap=&lcd_mono_bitmap,
152 .mono_bitmap_part=&lcd_mono_bitmap_part, 188 .mono_bitmap_part=&lcd_mono_bitmap_part,
153 .set_drawmode=&lcd_set_drawmode, 189 .set_drawmode=&lcd_set_drawmode,
@@ -246,8 +282,9 @@ struct screen screens[NB_SCREENS] =
246 .getheight=&lcd_remote_getheight, 282 .getheight=&lcd_remote_getheight,
247 .getstringsize=&lcd_remote_getstringsize, 283 .getstringsize=&lcd_remote_getstringsize,
248#if 1 /* all remote LCDs are bitmapped so far */ 284#if 1 /* all remote LCDs are bitmapped so far */
249 .setfont=screen_helper_setfont, 285 .setfont=screen_helper_remote_setfont,
250 .getfont=&lcd_remote_getfont, 286 .getuifont=screen_helper_remote_getuifont,
287 .setuifont=screen_helper_remote_setuifont,
251 .mono_bitmap=&lcd_remote_mono_bitmap, 288 .mono_bitmap=&lcd_remote_mono_bitmap,
252 .mono_bitmap_part=&lcd_remote_mono_bitmap_part, 289 .mono_bitmap_part=&lcd_remote_mono_bitmap_part,
253 .bitmap=(screen_bitmap_func*)&lcd_remote_bitmap, 290 .bitmap=(screen_bitmap_func*)&lcd_remote_bitmap,
diff --git a/apps/screen_access.h b/apps/screen_access.h
index 2713219811..04cc6f4f90 100644
--- a/apps/screen_access.h
+++ b/apps/screen_access.h
@@ -71,7 +71,8 @@ struct screen
71 int (*getstringsize)(const unsigned char *str, int *w, int *h); 71 int (*getstringsize)(const unsigned char *str, int *w, int *h);
72#if defined(HAVE_LCD_BITMAP) || defined(HAVE_REMOTE_LCD) /* always bitmap */ 72#if defined(HAVE_LCD_BITMAP) || defined(HAVE_REMOTE_LCD) /* always bitmap */
73 void (*setfont)(int newfont); 73 void (*setfont)(int newfont);
74 int (*getfont)(void); 74 int (*getuifont)(void);
75 void (*setuifont)(int newfont);
75 76
76 void (*scroll_step)(int pixels); 77 void (*scroll_step)(int pixels);
77 void (*puts_style_offset)(int x, int y, const unsigned char *str, 78 void (*puts_style_offset)(int x, int y, const unsigned char *str,
diff --git a/apps/settings.c b/apps/settings.c
index 7142cfb0c6..fbfa438ab5 100644
--- a/apps/settings.c
+++ b/apps/settings.c
@@ -876,37 +876,38 @@ void settings_apply(bool read_disk)
876 /* fonts need to be loaded before the WPS */ 876 /* fonts need to be loaded before the WPS */
877 if (global_settings.font_file[0] 877 if (global_settings.font_file[0]
878 && global_settings.font_file[0] != '-') { 878 && global_settings.font_file[0] != '-') {
879 const char* loaded_font = font_filename(global_status.font_id[SCREEN_MAIN]); 879 int font_ui = screens[SCREEN_MAIN].getuifont();
880 const char* loaded_font = font_filename(font_ui);
880 881
881 snprintf(buf, sizeof buf, FONT_DIR "/%s.fnt", 882 snprintf(buf, sizeof buf, FONT_DIR "/%s.fnt",
882 global_settings.font_file); 883 global_settings.font_file);
883 if (!loaded_font || strcmp(loaded_font, buf)) 884 if (!loaded_font || strcmp(loaded_font, buf))
884 { 885 {
885 CHART2(">font_load ", global_settings.font_file); 886 CHART2(">font_load ", global_settings.font_file);
886 if (global_status.font_id[SCREEN_MAIN] >= 0) 887 if (font_ui >= 0)
887 font_unload(global_status.font_id[SCREEN_MAIN]); 888 font_unload(font_ui);
888 rc = font_load(buf); 889 rc = font_load(buf);
889 font_set_ui(rc);
890 CHART2("<font_load ", global_settings.font_file); 890 CHART2("<font_load ", global_settings.font_file);
891 global_status.font_id[SCREEN_MAIN] = rc; 891 screens[SCREEN_MAIN].setuifont(rc);
892 lcd_setfont(rc); 892 screens[SCREEN_MAIN].setfont(rc);
893 } 893 }
894 } 894 }
895#ifdef HAVE_REMOTE_LCD 895#ifdef HAVE_REMOTE_LCD
896 if ( global_settings.remote_font_file[0] 896 if ( global_settings.remote_font_file[0]
897 && global_settings.remote_font_file[0] != '-') { 897 && global_settings.remote_font_file[0] != '-') {
898 const char* loaded_font = font_filename(global_status.font_id[SCREEN_REMOTE]); 898 int font_ui = screens[SCREEN_REMOTE].getuifont();
899 const char* loaded_font = font_filename(font_ui);
899 snprintf(buf, sizeof buf, FONT_DIR "/%s.fnt", 900 snprintf(buf, sizeof buf, FONT_DIR "/%s.fnt",
900 global_settings.remote_font_file); 901 global_settings.remote_font_file);
901 if (!loaded_font || strcmp(loaded_font, buf)) 902 if (!loaded_font || strcmp(loaded_font, buf))
902 { 903 {
903 CHART2(">font_load_remoteui ", global_settings.remote_font_file); 904 CHART2(">font_load_remoteui ", global_settings.remote_font_file);
904 if (global_status.font_id[SCREEN_REMOTE] >= 0) 905 if (font_ui >= 0)
905 font_unload(global_status.font_id[SCREEN_REMOTE]); 906 font_unload(font_ui);
906 rc = font_load(buf); 907 rc = font_load(buf);
907 CHART2("<font_load_remoteui ", global_settings.remote_font_file); 908 CHART2("<font_load_remoteui ", global_settings.remote_font_file);
908 global_status.font_id[SCREEN_REMOTE] = rc; 909 screens[SCREEN_REMOTE].setuifont(rc);
909 lcd_remote_setfont(rc); 910 screens[SCREEN_REMOTE].setfont(rc);
910 } 911 }
911 } 912 }
912#endif 913#endif
@@ -1076,10 +1077,11 @@ void settings_reset(void)
1076#ifdef HAVE_LCD_BITMAP 1077#ifdef HAVE_LCD_BITMAP
1077 FOR_NB_SCREENS(i) 1078 FOR_NB_SCREENS(i)
1078 { 1079 {
1079 if (global_status.font_id[i] > FONT_SYSFIXED) 1080 if (screens[i].getuifont() > FONT_SYSFIXED)
1080 { 1081 {
1081 font_unload(global_status.font_id[i]); 1082 font_unload(screens[i].getuifont());
1082 global_status.font_id[i] = FONT_SYSFIXED; 1083 screens[i].setuifont(FONT_SYSFIXED);
1084 screens[i].setfont(FONT_SYSFIXED);
1083 } 1085 }
1084 } 1086 }
1085#endif 1087#endif
diff --git a/firmware/export/font.h b/firmware/export/font.h
index 76f86c845f..914d3aa2ff 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 MAXUSERFONTS 58#define FONT_UI MAXFONTS
59 59
60/* 60/*
61 * .fnt loadable font file format definition 61 * .fnt loadable font file format definition
@@ -124,9 +124,6 @@ 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);
130 127
131struct font* font_get(int font); 128struct font* font_get(int font);
132 129
diff --git a/firmware/font.c b/firmware/font.c
index 8e576016bd..ff5bc4b008 100644
--- a/firmware/font.c
+++ b/firmware/font.c
@@ -88,7 +88,6 @@ struct buflib_alloc_data {
88}; 88};
89static int buflib_allocations[MAXFONTS]; 89static int buflib_allocations[MAXFONTS];
90 90
91static int font_ui = -1;
92static int cache_fd; 91static int cache_fd;
93static struct font* cache_pf; 92static struct font* cache_pf;
94 93
@@ -560,7 +559,7 @@ int font_load_ex(const char *path, size_t buffer_size)
560 559
561 lock_font_handle(handle, false); 560 lock_font_handle(handle, false);
562 buflib_allocations[font_id] = handle; 561 buflib_allocations[font_id] = handle;
563 //printf("%s -> [%d] -> %d\n", path, font_id, handle); 562 //printf("%s -> [%d] -> %d\n", path, font_id, *handle);
564 return font_id; /* success!*/ 563 return font_id; /* success!*/
565} 564}
566int font_load(const char *path) 565int font_load(const char *path)
@@ -617,52 +616,28 @@ void font_unload_all(void)
617 616
618/* 617/*
619 * Return a pointer to an incore font structure. 618 * Return a pointer to an incore font structure.
620 * Return the requested font, font_ui, or sysfont 619 * If the requested font isn't loaded/compiled-in,
620 * decrement the font number and try again.
621 */ 621 */
622struct font* font_get(int font_id) 622struct font* font_get(int font)
623{ 623{
624 struct buflib_alloc_data *alloc; 624 struct font* pf;
625 struct font *pf; 625 if (font == FONT_UI)
626 int handle, id=-1; 626 font = MAXFONTS-1;
627 627 if (font <= FONT_SYSFIXED)
628 if( font_id == FONT_UI )
629 id = font_ui;
630
631 if( font_id == FONT_SYSFIXED )
632 return &sysfont; 628 return &sysfont;
633
634 if( id == -1 )
635 id = font_id;
636
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;
652 }
653
654 return &sysfont;
655}
656
657void font_set_ui( int font_id )
658{
659 font_ui = font_id;
660 return;
661}
662 629
663int font_get_ui() 630 while (1) {
664{ 631 if (buflib_allocations[font] > 0)
665 return font_ui; 632 {
633 struct buflib_alloc_data *alloc = core_get_data(buflib_allocations[font]);
634 pf = &alloc->font;
635 if (pf && pf->height)
636 return pf;
637 }
638 if (--font < 0)
639 return &sysfont;
640 }
666} 641}
667 642
668static int pf_to_handle(struct font* pf) 643static int pf_to_handle(struct font* pf)
@@ -1004,18 +979,6 @@ struct font* font_get(int font)
1004 return &sysfont; 979 return &sysfont;
1005} 980}
1006 981
1007void font_set_ui(int font_id)
1008{
1009 (void)font_id;
1010 return;
1011}
1012
1013int font_get_ui()
1014{
1015 return FONT_SYSFIXED;
1016}
1017
1018
1019/* 982/*
1020 * Returns width of character 983 * Returns width of character
1021 */ 984 */