diff options
-rw-r--r-- | firmware/export/font.h | 2 | ||||
-rw-r--r-- | firmware/font.c | 51 |
2 files changed, 23 insertions, 30 deletions
diff --git a/firmware/export/font.h b/firmware/export/font.h index a0a7c37ba9..2334a8bd1a 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*/ |
119 | void font_init(void) INIT_ATTR; | 119 | void font_init(void) INIT_ATTR; |
120 | bool font_filename_matches_loaded_id(int font_id, char *filename); | 120 | bool font_filename_matches_loaded_id(int font_id, const char *filename); |
121 | int font_load(const char *path); | 121 | int font_load(const char *path); |
122 | int font_load_ex(const char *path, size_t buffer_size, int glyphs); | 122 | int font_load_ex(const char *path, size_t buffer_size, int glyphs); |
123 | void font_unload(int font_id); | 123 | void font_unload(int font_id); |
diff --git a/firmware/font.c b/firmware/font.c index 97fee16dc2..01f187df45 100644 --- a/firmware/font.c +++ b/firmware/font.c | |||
@@ -326,44 +326,36 @@ static struct font* font_load_cached(struct font* pf, | |||
326 | return pf; | 326 | return pf; |
327 | } | 327 | } |
328 | 328 | ||
329 | 329 | bool font_filename_matches_loaded_id(int font_id, const char *filename) | |
330 | static int find_font_index(const char* path) | ||
331 | { | 330 | { |
332 | int index = 0, handle; | 331 | if ( font_id >= 0 && font_id < MAXFONTS ) |
333 | |||
334 | while (index < MAXFONTS) | ||
335 | { | 332 | { |
336 | handle = buflib_allocations[index]; | 333 | int handle = buflib_allocations[font_id]; |
337 | if (handle > 0) | 334 | if (handle > 0) |
338 | { | 335 | { |
339 | struct buflib_alloc_data *data = core_get_data(handle); | 336 | struct buflib_alloc_data *data = core_get_data(handle); |
340 | if(!strcmp(data->path, path)) | 337 | logf("%s id: [%d], %s", __func__, font_id, data->path); |
341 | { | 338 | return strcmp(data->path, filename) == 0; |
342 | logf("%s Found id: [%d], %s", __func__, index, path); | ||
343 | return index; | ||
344 | } | ||
345 | } | 339 | } |
346 | |||
347 | index++; | ||
348 | } | 340 | } |
349 | logf("%s %s Not found using id: [%d], FONT_SYSFIXED", | 341 | return false; |
350 | __func__, path, FONT_SYSFIXED); | ||
351 | return FONT_SYSFIXED; | ||
352 | } | 342 | } |
353 | 343 | ||
354 | bool font_filename_matches_loaded_id(int font_id, char *filename) | 344 | static int find_font_index(const char* path) |
355 | { | 345 | { |
356 | if ( font_id >= 0 && font_id < MAXFONTS ) | 346 | for(int index = 0; index < MAXFONTS; index++) |
357 | { | 347 | { |
358 | int handle = buflib_allocations[font_id]; | 348 | if(font_filename_matches_loaded_id(index, path)) |
359 | if (handle > 0) | ||
360 | { | 349 | { |
361 | struct buflib_alloc_data *data = core_get_data(handle); | 350 | logf("%s Found id: [%d], %s", __func__, index, path); |
362 | logf("%s id: [%d], %s", __func__, font_id, data->path); | 351 | return index; |
363 | return strcmp(data->path, filename) == 0; | ||
364 | } | 352 | } |
353 | |||
354 | index++; | ||
365 | } | 355 | } |
366 | return false; | 356 | logf("%s %s Not found using id: [%d], FONT_SYSFIXED", |
357 | __func__, path, FONT_SYSFIXED); | ||
358 | return FONT_SYSFIXED; | ||
367 | } | 359 | } |
368 | 360 | ||
369 | static size_t font_glyphs_to_bufsize(struct font *pf, int glyphs) | 361 | static size_t font_glyphs_to_bufsize(struct font *pf, int glyphs) |
@@ -541,8 +533,8 @@ int font_load_ex( const char *path, size_t buf_size, int glyphs ) | |||
541 | return -1; | 533 | return -1; |
542 | } | 534 | } |
543 | struct buflib_alloc_data *pdata; | 535 | struct buflib_alloc_data *pdata; |
544 | core_pin(handle); | 536 | |
545 | pdata = core_get_data(handle); | 537 | pdata = core_get_data_pinned(handle); |
546 | pdata->refcount = 1; | 538 | pdata->refcount = 1; |
547 | pdata->path = pdata->buffer + bufsize; | 539 | pdata->path = pdata->buffer + bufsize; |
548 | /* save load path so we can recognize this font later */ | 540 | /* save load path so we can recognize this font later */ |
@@ -599,7 +591,7 @@ int font_load_ex( const char *path, size_t buf_size, int glyphs ) | |||
599 | } | 591 | } |
600 | buflib_allocations[font_id] = handle; | 592 | buflib_allocations[font_id] = handle; |
601 | //printf("%s -> [%d] -> %d\n", path, font_id, *handle); | 593 | //printf("%s -> [%d] -> %d\n", path, font_id, *handle); |
602 | lock_font_handle( handle, false ); | 594 | core_put_data_pinned(pdata); |
603 | logf("%s id: [%d], %s", __func__, font_id, path); | 595 | logf("%s id: [%d], %s", __func__, font_id, path); |
604 | return font_id; /* success!*/ | 596 | return font_id; /* success!*/ |
605 | } | 597 | } |
@@ -882,8 +874,9 @@ static void font_path_to_glyph_path( const char *font_path, char *glyph_path) | |||
882 | { | 874 | { |
883 | /* take full file name, cut extension, and add .glyphcache */ | 875 | /* take full file name, cut extension, and add .glyphcache */ |
884 | strmemccpy(glyph_path, font_path, MAX_PATH); | 876 | strmemccpy(glyph_path, font_path, MAX_PATH); |
885 | glyph_path[strlen(glyph_path)- sizeof(FONT_EXT)] = '\0'; | 877 | int dotidx = strlen(glyph_path) - sizeof(FONT_EXT); |
886 | strcat(glyph_path, "." GLYPH_CACHE_EXT); | 878 | strmemccpy(glyph_path + dotidx, "." GLYPH_CACHE_EXT, MAX_PATH - dotidx); |
879 | logf("%s %s", __func__, glyph_path); | ||
887 | } | 880 | } |
888 | 881 | ||
889 | /* call with NULL to flush */ | 882 | /* call with NULL to flush */ |