summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/settings.c7
-rw-r--r--firmware/export/font.h2
-rw-r--r--firmware/font.c46
3 files changed, 24 insertions, 31 deletions
diff --git a/apps/settings.c b/apps/settings.c
index c19a0b9b65..0f060a41e6 100644
--- a/apps/settings.c
+++ b/apps/settings.c
@@ -929,11 +929,9 @@ void settings_apply(bool read_disk)
929 if (global_settings.font_file[0] 929 if (global_settings.font_file[0]
930 && global_settings.font_file[0] != '-') { 930 && global_settings.font_file[0] != '-') {
931 int font_ui = screens[SCREEN_MAIN].getuifont(); 931 int font_ui = screens[SCREEN_MAIN].getuifont();
932 const char* loaded_font = font_filename(font_ui);
933
934 snprintf(buf, sizeof buf, FONT_DIR "/%s.fnt", 932 snprintf(buf, sizeof buf, FONT_DIR "/%s.fnt",
935 global_settings.font_file); 933 global_settings.font_file);
936 if (!loaded_font || strcmp(loaded_font, buf)) 934 if (!font_filename_matches_loaded_id(font_ui, buf))
937 { 935 {
938 CHART2(">font_load ", global_settings.font_file); 936 CHART2(">font_load ", global_settings.font_file);
939 if (font_ui >= 0) 937 if (font_ui >= 0)
@@ -948,10 +946,9 @@ void settings_apply(bool read_disk)
948 if ( global_settings.remote_font_file[0] 946 if ( global_settings.remote_font_file[0]
949 && global_settings.remote_font_file[0] != '-') { 947 && global_settings.remote_font_file[0] != '-') {
950 int font_ui = screens[SCREEN_REMOTE].getuifont(); 948 int font_ui = screens[SCREEN_REMOTE].getuifont();
951 const char* loaded_font = font_filename(font_ui);
952 snprintf(buf, sizeof buf, FONT_DIR "/%s.fnt", 949 snprintf(buf, sizeof buf, FONT_DIR "/%s.fnt",
953 global_settings.remote_font_file); 950 global_settings.remote_font_file);
954 if (!loaded_font || strcmp(loaded_font, buf)) 951 if (!font_filename_matches_loaded_id(font_ui, buf))
955 { 952 {
956 CHART2(">font_load_remoteui ", global_settings.remote_font_file); 953 CHART2(">font_load_remoteui ", global_settings.remote_font_file);
957 if (font_ui >= 0) 954 if (font_ui >= 0)
diff --git a/firmware/export/font.h b/firmware/export/font.h
index 38e30187b3..a0a7c37ba9 100644
--- a/firmware/export/font.h
+++ b/firmware/export/font.h
@@ -117,7 +117,7 @@ struct font {
117 117
118/* font routines*/ 118/* font routines*/
119void font_init(void) INIT_ATTR; 119void font_init(void) INIT_ATTR;
120const char* font_filename(int font_id); 120bool font_filename_matches_loaded_id(int font_id, char *filename);
121int font_load(const char *path); 121int font_load(const char *path);
122int font_load_ex(const char *path, size_t buffer_size, int glyphs); 122int font_load_ex(const char *path, size_t buffer_size, int glyphs);
123void font_unload(int font_id); 123void font_unload(int font_id);
diff --git a/firmware/font.c b/firmware/font.c
index 69c4fd40f8..8c268bea5f 100644
--- a/firmware/font.c
+++ b/firmware/font.c
@@ -152,13 +152,6 @@ void font_lock(int font_id, bool lock)
152 152
153static struct buflib_callbacks buflibops = {buflibmove_callback, NULL, NULL }; 153static struct buflib_callbacks buflibops = {buflibmove_callback, NULL, NULL };
154 154
155static inline struct font *pf_from_handle(int handle)
156{
157 struct buflib_alloc_data *alloc = core_get_data(handle);
158 struct font *pf = &alloc->font;
159 return pf;
160}
161
162static inline unsigned char *buffer_from_handle(int handle) 155static inline unsigned char *buffer_from_handle(int handle)
163{ 156{
164 struct buflib_alloc_data *alloc = core_get_data(handle); 157 struct buflib_alloc_data *alloc = core_get_data(handle);
@@ -358,7 +351,7 @@ static int find_font_index(const char* path)
358 return FONT_SYSFIXED; 351 return FONT_SYSFIXED;
359} 352}
360 353
361const char* font_filename(int font_id) 354bool font_filename_matches_loaded_id(int font_id, char *filename)
362{ 355{
363 if ( font_id < 0 || font_id >= MAXFONTS ) 356 if ( font_id < 0 || font_id >= MAXFONTS )
364 return NULL; 357 return NULL;
@@ -367,10 +360,10 @@ const char* font_filename(int font_id)
367 { 360 {
368 struct buflib_alloc_data *data = core_get_data(handle); 361 struct buflib_alloc_data *data = core_get_data(handle);
369 logf("%s id: [%d], %s", __func__, font_id, data->path); 362 logf("%s id: [%d], %s", __func__, font_id, data->path);
370 return data->path; 363 return strcmp(data->path, filename) == 0;
371 } 364 }
372 365
373 return NULL; 366 return false;
374} 367}
375 368
376static size_t font_glyphs_to_bufsize(struct font *pf, int glyphs) 369static size_t font_glyphs_to_bufsize(struct font *pf, int glyphs)
@@ -688,15 +681,15 @@ static void font_enable(int font_id)
688 int handle = buflib_allocations[font_id]; 681 int handle = buflib_allocations[font_id];
689 if ( handle < 0 ) 682 if ( handle < 0 )
690 return; 683 return;
691 struct buflib_alloc_data *pdata = core_get_data(handle); 684 struct buflib_alloc_data *pdata = core_get_data_pinned(handle);
692 struct font *pf = &pdata->font; 685 struct font *pf = &pdata->font;
693 686
694 if (pf->disabled && pf->fd < 0) 687 if (pf->disabled && pf->fd < 0)
695 { 688 {
696 const char *filename = font_filename(font_id); 689 pf->fd = open(pdata->path, O_RDONLY);
697 pf->fd = open(filename, O_RDONLY);
698 pf->disabled = false; 690 pf->disabled = false;
699 } 691 }
692 core_put_data_pinned(pdata);
700} 693}
701 694
702void font_enable_all(void) 695void font_enable_all(void)
@@ -932,25 +925,28 @@ static void glyph_cache_save(int font_id)
932 if ( handle < 0 ) 925 if ( handle < 0 )
933 return; 926 return;
934 927
935 struct font *pf = pf_from_handle(handle); 928 struct buflib_alloc_data *pdata = core_get_data_pinned(handle);
929 struct font *pf = &pdata->font;
930
936 if(pf && pf->fd >= 0) 931 if(pf && pf->fd >= 0)
937 { 932 {
938 char filename[MAX_PATH]; 933 char filename[MAX_PATH];
939 font_path_to_glyph_path(font_filename(font_id), filename); 934 font_path_to_glyph_path(pdata->path, filename);
940 fd = open(filename, O_WRONLY|O_CREAT|O_TRUNC, 0666); 935 fd = open(filename, O_WRONLY|O_CREAT|O_TRUNC, 0666);
941 if (fd < 0) 936 if (fd >= 0)
942 return;
943
944 cache_pf = pf;
945 cache_fd = fd;
946 lru_traverse(&cache_pf->cache._lru, glyph_file_write);
947 glyph_file_write(NULL);
948 if (cache_fd >= 0)
949 { 937 {
950 close(cache_fd); 938 cache_pf = pf;
951 cache_fd = -1; 939 cache_fd = fd;
940 lru_traverse(&cache_pf->cache._lru, glyph_file_write);
941 glyph_file_write(NULL);
942 if (cache_fd >= 0)
943 {
944 close(cache_fd);
945 cache_fd = -1;
946 }
952 } 947 }
953 } 948 }
949 core_put_data_pinned(pdata);
954 return; 950 return;
955} 951}
956 952