summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--firmware/font.c34
1 files changed, 18 insertions, 16 deletions
diff --git a/firmware/font.c b/firmware/font.c
index 8cd9be1ad5..dfc8abacb7 100644
--- a/firmware/font.c
+++ b/firmware/font.c
@@ -352,10 +352,12 @@ static void font_reset(int font_id)
352 352
353 353
354static bool internal_load_font(int font_id, const char *path, 354static bool internal_load_font(int font_id, const char *path,
355 char *buf, size_t buf_size) 355 char *buf, size_t buf_size,
356 int handle
357 )
356{ 358{
357 size_t size; 359 size_t size;
358 struct font* pf = pf_from_handle(buflib_allocations[font_id]); 360 struct font* pf = pf_from_handle(handle);
359 /* save loaded glyphs */ 361 /* save loaded glyphs */
360 glyph_cache_save(pf); 362 glyph_cache_save(pf);
361 /* Close font file handle */ 363 /* Close font file handle */
@@ -475,7 +477,7 @@ int font_load_ex(const char *path, size_t buffer_size)
475{ 477{
476 int font_id = find_font_index(path); 478 int font_id = find_font_index(path);
477 char *buffer; 479 char *buffer;
478 int *handle; 480 int handle;
479 481
480 if (font_id > FONT_SYSFIXED) 482 if (font_id > FONT_SYSFIXED)
481 { 483 {
@@ -516,32 +518,32 @@ int font_load_ex(const char *path, size_t buffer_size)
516 518
517 for (font_id = FONT_FIRSTUSERFONT; font_id < MAXFONTS; font_id++) 519 for (font_id = FONT_FIRSTUSERFONT; font_id < MAXFONTS; font_id++)
518 { 520 {
519 handle = &buflib_allocations[font_id]; 521 handle = buflib_allocations[font_id];
520 if (*handle < 0) 522 if (handle < 0)
521 { 523 {
522 break; 524 break;
523 } 525 }
524 } 526 }
525 handle = &buflib_allocations[font_id]; 527 handle = alloc_and_init(font_id, path, buffer_size);
526 *handle = alloc_and_init(font_id, path, buffer_size); 528 if (handle < 0)
527 if (*handle < 0)
528 return -1; 529 return -1;
529 530
530 if (handle_for_glyphcache < 0) 531 if (handle_for_glyphcache < 0)
531 handle_for_glyphcache = *handle; 532 handle_for_glyphcache = handle;
532 533
533 buffer = buffer_from_handle(*handle); 534 buffer = buffer_from_handle(handle);
534 lock_font_handle(*handle, true); 535 lock_font_handle(handle, true);
535 536
536 if (!internal_load_font(font_id, path, buffer, buffer_size)) 537 if (!internal_load_font(font_id, path, buffer, buffer_size, handle))
537 { 538 {
538 lock_font_handle(*handle, false); 539 lock_font_handle(handle, false);
539 core_free(*handle); 540 core_free(handle);
540 *handle = -1; 541 buflib_allocations[font_id] = -1;
541 return -1; 542 return -1;
542 } 543 }
543 544
544 lock_font_handle(*handle, false); 545 lock_font_handle(handle, false);
546 buflib_allocations[font_id] = handle;
545 //printf("%s -> [%d] -> %d\n", path, font_id, *handle); 547 //printf("%s -> [%d] -> %d\n", path, font_id, *handle);
546 return font_id; /* success!*/ 548 return font_id; /* success!*/
547} 549}