diff options
37 files changed, 406 insertions, 400 deletions
diff --git a/apps/SOURCES b/apps/SOURCES index 6b72d6ad09..443b42fedc 100644 --- a/apps/SOURCES +++ b/apps/SOURCES | |||
@@ -105,9 +105,6 @@ gui/viewport.c | |||
105 | gui/skin_engine/skin_backdrops.c | 105 | gui/skin_engine/skin_backdrops.c |
106 | gui/skin_engine/skin_display.c | 106 | gui/skin_engine/skin_display.c |
107 | gui/skin_engine/skin_engine.c | 107 | gui/skin_engine/skin_engine.c |
108 | #ifdef HAVE_LCD_BITMAP | ||
109 | gui/skin_engine/skin_fonts.c | ||
110 | #endif | ||
111 | gui/skin_engine/skin_parser.c | 108 | gui/skin_engine/skin_parser.c |
112 | gui/skin_engine/skin_render.c | 109 | gui/skin_engine/skin_render.c |
113 | gui/skin_engine/skin_tokens.c | 110 | gui/skin_engine/skin_tokens.c |
diff --git a/apps/filetree.c b/apps/filetree.c index 35bb2a8fd0..59e7343600 100644 --- a/apps/filetree.c +++ b/apps/filetree.c | |||
@@ -404,27 +404,31 @@ int ft_load(struct tree_context* c, const char* tempdir) | |||
404 | #ifdef HAVE_LCD_BITMAP | 404 | #ifdef HAVE_LCD_BITMAP |
405 | static void ft_load_font(char *file) | 405 | static void ft_load_font(char *file) |
406 | { | 406 | { |
407 | int current_font_id; | ||
408 | enum screen_type screen = SCREEN_MAIN; | ||
407 | #if NB_SCREENS > 1 | 409 | #if NB_SCREENS > 1 |
408 | MENUITEM_STRINGLIST(menu, ID2P(LANG_CUSTOM_FONT), NULL, | 410 | MENUITEM_STRINGLIST(menu, ID2P(LANG_CUSTOM_FONT), NULL, |
409 | ID2P(LANG_MAIN_SCREEN), ID2P(LANG_REMOTE_SCREEN)) | 411 | ID2P(LANG_MAIN_SCREEN), ID2P(LANG_REMOTE_SCREEN)) |
410 | switch (do_menu(&menu, NULL, NULL, false)) | 412 | switch (do_menu(&menu, NULL, NULL, false)) |
411 | { | 413 | { |
412 | case 0: /* main lcd */ | 414 | case 0: /* main lcd */ |
413 | splash(0, ID2P(LANG_WAIT)); | 415 | screen = SCREEN_MAIN; |
414 | font_load(NULL, file); | ||
415 | set_file(file, (char *)global_settings.font_file, MAX_FILENAME); | 416 | set_file(file, (char *)global_settings.font_file, MAX_FILENAME); |
416 | break; | 417 | break; |
417 | case 1: /* remote */ | 418 | case 1: /* remote */ |
418 | splash(0, ID2P(LANG_WAIT)); | 419 | screen = SCREEN_REMOTE; |
419 | font_load_remoteui(file); | ||
420 | set_file(file, (char *)global_settings.remote_font_file, MAX_FILENAME); | 420 | set_file(file, (char *)global_settings.remote_font_file, MAX_FILENAME); |
421 | break; | 421 | break; |
422 | } | 422 | } |
423 | #else | 423 | #else |
424 | splash(0, ID2P(LANG_WAIT)); | ||
425 | font_load(NULL, file); | ||
426 | set_file(file, (char *)global_settings.font_file, MAX_FILENAME); | 424 | set_file(file, (char *)global_settings.font_file, MAX_FILENAME); |
427 | #endif | 425 | #endif |
426 | splash(0, ID2P(LANG_WAIT)); | ||
427 | current_font_id = global_status.font_id[screen]; | ||
428 | if (current_font_id >= 0) | ||
429 | font_unload(current_font_id); | ||
430 | global_status.font_id[screen] = font_load(file); | ||
431 | viewportmanager_theme_changed(THEME_UI_VIEWPORT); | ||
428 | } | 432 | } |
429 | #endif | 433 | #endif |
430 | 434 | ||
diff --git a/apps/gui/skin_engine/skin_engine.c b/apps/gui/skin_engine/skin_engine.c index 7a9a10ec57..069c3467a9 100644 --- a/apps/gui/skin_engine/skin_engine.c +++ b/apps/gui/skin_engine/skin_engine.c | |||
@@ -107,9 +107,9 @@ void settings_apply_skins(void) | |||
107 | { | 107 | { |
108 | int i, j; | 108 | int i, j; |
109 | 109 | ||
110 | for (i=0; i<SKINNABLE_SCREENS_COUNT; i++) | 110 | for(j=0; j<SKINNABLE_SCREENS_COUNT; j++) |
111 | { | 111 | { |
112 | FOR_NB_SCREENS(j) | 112 | FOR_NB_SCREENS(i) |
113 | skin_data_free_buflib_allocs(&skins[j][i].data); | 113 | skin_data_free_buflib_allocs(&skins[j][i].data); |
114 | } | 114 | } |
115 | 115 | ||
@@ -117,7 +117,6 @@ void settings_apply_skins(void) | |||
117 | 117 | ||
118 | #ifdef HAVE_LCD_BITMAP | 118 | #ifdef HAVE_LCD_BITMAP |
119 | skin_backdrop_init(); | 119 | skin_backdrop_init(); |
120 | skin_font_init(); | ||
121 | #endif | 120 | #endif |
122 | gui_sync_skin_init(); | 121 | gui_sync_skin_init(); |
123 | 122 | ||
diff --git a/apps/gui/skin_engine/skin_engine.h b/apps/gui/skin_engine/skin_engine.h index c8104f9304..310411bb1d 100644 --- a/apps/gui/skin_engine/skin_engine.h +++ b/apps/gui/skin_engine/skin_engine.h | |||
@@ -25,7 +25,6 @@ | |||
25 | 25 | ||
26 | #ifndef PLUGIN | 26 | #ifndef PLUGIN |
27 | 27 | ||
28 | #include "skin_fonts.h" | ||
29 | #include "tag_table.h" | 28 | #include "tag_table.h" |
30 | 29 | ||
31 | #include "wps_internals.h" /* TODO: remove this line.. shoudlnt be needed */ | 30 | #include "wps_internals.h" /* TODO: remove this line.. shoudlnt be needed */ |
@@ -44,8 +43,7 @@ enum skinnable_screens { | |||
44 | 43 | ||
45 | #ifdef HAVE_LCD_BITMAP | 44 | #ifdef HAVE_LCD_BITMAP |
46 | 45 | ||
47 | #define SKIN_BUFFER_SIZE (2048 + SKIN_FONT_SIZE) + \ | 46 | #define SKIN_BUFFER_SIZE (WPS_MAX_TOKENS * \ |
48 | (WPS_MAX_TOKENS * \ | ||
49 | (sizeof(struct wps_token) + (sizeof(struct skin_element)))) | 47 | (sizeof(struct wps_token) + (sizeof(struct skin_element)))) |
50 | #endif | 48 | #endif |
51 | 49 | ||
diff --git a/apps/gui/skin_engine/skin_fonts.c b/apps/gui/skin_engine/skin_fonts.c deleted file mode 100644 index a89b76281b..0000000000 --- a/apps/gui/skin_engine/skin_fonts.c +++ /dev/null | |||
@@ -1,142 +0,0 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2010 Jonathan Gordon | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #include "config.h" | ||
23 | #include <stdio.h> | ||
24 | #include <string.h> | ||
25 | #include <stdlib.h> | ||
26 | |||
27 | #include "file.h" | ||
28 | #include "settings.h" | ||
29 | #include "font.h" | ||
30 | #include "skin_buffer.h" | ||
31 | #include "skin_fonts.h" | ||
32 | |||
33 | static struct skin_font_info { | ||
34 | struct font font; | ||
35 | int font_id; | ||
36 | char name[MAX_PATH]; | ||
37 | char *buffer; | ||
38 | int ref_count; /* how many times has this font been loaded? */ | ||
39 | } font_table[MAXUSERFONTS]; | ||
40 | |||
41 | /* need this to know if we should be closing font fd's on the next init */ | ||
42 | static bool first_load = true; | ||
43 | |||
44 | void skin_font_init(void) | ||
45 | { | ||
46 | int i; | ||
47 | for(i=0;i<MAXUSERFONTS;i++) | ||
48 | { | ||
49 | if (!first_load) | ||
50 | font_unload(font_table[i].font_id); | ||
51 | font_table[i].font_id = -1; | ||
52 | font_table[i].name[0] = '\0'; | ||
53 | font_table[i].buffer = NULL; | ||
54 | font_table[i].ref_count = 0; | ||
55 | } | ||
56 | first_load = false; | ||
57 | } | ||
58 | |||
59 | /* load a font into the skin buffer. return the font id. */ | ||
60 | int skin_font_load(char* font_name, int glyphs) | ||
61 | { | ||
62 | int i; | ||
63 | int skin_font_size = 0; | ||
64 | struct font *pf; | ||
65 | struct skin_font_info *font = NULL; | ||
66 | char filename[MAX_PATH]; | ||
67 | |||
68 | if (!strcmp(font_name, global_settings.font_file)) | ||
69 | return FONT_UI; | ||
70 | #ifdef HAVE_REMOTE_LCD | ||
71 | if (!strcmp(font_name, global_settings.remote_font_file)) | ||
72 | return FONT_UI_REMOTE; | ||
73 | #endif | ||
74 | snprintf(filename, MAX_PATH, FONT_DIR "/%s.fnt", font_name); | ||
75 | |||
76 | for(i=0;i<MAXUSERFONTS;i++) | ||
77 | { | ||
78 | if (font_table[i].font_id >= 0 && !strcmp(font_table[i].name, filename)) | ||
79 | { | ||
80 | font_table[i].ref_count++; | ||
81 | return font_table[i].font_id; | ||
82 | } | ||
83 | else if (!font && font_table[i].font_id == -1) | ||
84 | { | ||
85 | font = &font_table[i]; | ||
86 | strcpy(font_table[i].name, filename); | ||
87 | } | ||
88 | } | ||
89 | if (!font) | ||
90 | return -1; /* too many fonts loaded */ | ||
91 | |||
92 | pf = &font->font; | ||
93 | if (!font->buffer) | ||
94 | { | ||
95 | if (!glyphs) | ||
96 | glyphs = GLYPHS_TO_CACHE; | ||
97 | #ifndef __PCTOOL__ | ||
98 | skin_font_size = font_glyphs_to_bufsize(filename, glyphs); | ||
99 | #else | ||
100 | skin_font_size = 1; | ||
101 | #endif | ||
102 | if ( !skin_font_size ) | ||
103 | return -1; | ||
104 | pf->buffer_start = (char*)skin_buffer_alloc(skin_font_size); | ||
105 | if (!pf->buffer_start) | ||
106 | return -1; | ||
107 | font->buffer = pf->buffer_start; | ||
108 | pf->buffer_size = skin_font_size; | ||
109 | } | ||
110 | else | ||
111 | { | ||
112 | pf->buffer_start = font->buffer; | ||
113 | } | ||
114 | |||
115 | pf->fd = -1; | ||
116 | font->font_id = font_load(pf, filename); | ||
117 | |||
118 | if (font->font_id < 0) | ||
119 | return -1; | ||
120 | font->ref_count = 1; | ||
121 | |||
122 | return font->font_id; | ||
123 | } | ||
124 | /* unload a skin font. If a font has been loaded more than once it wont actually | ||
125 | * be unloaded untill all references have been unloaded */ | ||
126 | void skin_font_unload(int font_id) | ||
127 | { | ||
128 | int i; | ||
129 | for(i=0;i<MAXUSERFONTS;i++) | ||
130 | { | ||
131 | if (font_table[i].font_id == font_id) | ||
132 | { | ||
133 | if (--font_table[i].ref_count == 0) | ||
134 | { | ||
135 | font_unload(font_id); | ||
136 | font_table[i].font_id = -1; | ||
137 | font_table[i].name[0] = '\0'; | ||
138 | } | ||
139 | return; | ||
140 | } | ||
141 | } | ||
142 | } | ||
diff --git a/apps/gui/skin_engine/skin_fonts.h b/apps/gui/skin_engine/skin_fonts.h deleted file mode 100644 index 698ed4fe7c..0000000000 --- a/apps/gui/skin_engine/skin_fonts.h +++ /dev/null | |||
@@ -1,50 +0,0 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2010 Jonathan Gordon | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #include "config.h" | ||
23 | #include <stdio.h> | ||
24 | #include <string.h> | ||
25 | #include <stdlib.h> | ||
26 | |||
27 | #include "file.h" | ||
28 | #include "settings.h" | ||
29 | #include "font.h" | ||
30 | |||
31 | #ifndef _SKINFONTS_H_ | ||
32 | #define _SKINFONTS_H_ | ||
33 | |||
34 | #if LCD_HEIGHT > 160 | ||
35 | #define SKIN_FONT_SIZE (1024*10) | ||
36 | #else | ||
37 | #define SKIN_FONT_SIZE (1024*3) | ||
38 | #endif | ||
39 | #define GLYPHS_TO_CACHE 256 | ||
40 | |||
41 | void skin_font_init(void); | ||
42 | |||
43 | /* load a font into the skin buffer. return the font id. | ||
44 | * reserve room for glyphs glyphs */ | ||
45 | int skin_font_load(char* font_name, int glyphs); | ||
46 | |||
47 | /* unload a skin font. If a font has been loaded more than once it wont actually | ||
48 | * be unloaded untill all references have been unloaded */ | ||
49 | void skin_font_unload(int font_id); | ||
50 | #endif | ||
diff --git a/apps/gui/skin_engine/skin_parser.c b/apps/gui/skin_engine/skin_parser.c index 9c73c3e682..8c87553be3 100644 --- a/apps/gui/skin_engine/skin_parser.c +++ b/apps/gui/skin_engine/skin_parser.c | |||
@@ -62,7 +62,6 @@ | |||
62 | #include "radio.h" | 62 | #include "radio.h" |
63 | #include "tuner.h" | 63 | #include "tuner.h" |
64 | #endif | 64 | #endif |
65 | #include "skin_fonts.h" | ||
66 | 65 | ||
67 | #ifdef HAVE_LCD_BITMAP | 66 | #ifdef HAVE_LCD_BITMAP |
68 | #include "bmp.h" | 67 | #include "bmp.h" |
@@ -77,6 +76,12 @@ | |||
77 | 76 | ||
78 | #define WPS_ERROR_INVALID_PARAM -1 | 77 | #define WPS_ERROR_INVALID_PARAM -1 |
79 | 78 | ||
79 | #if LCD_HEIGHT > 160 | ||
80 | #define SKIN_FONT_SIZE (1024*10) | ||
81 | #else | ||
82 | #define SKIN_FONT_SIZE (1024*3) | ||
83 | #endif | ||
84 | #define GLYPHS_TO_CACHE 256 | ||
80 | 85 | ||
81 | static bool isdefault(struct skin_tag_parameter *param) | 86 | static bool isdefault(struct skin_tag_parameter *param) |
82 | { | 87 | { |
@@ -415,8 +420,13 @@ static int parse_font_load(struct skin_element *element, | |||
415 | glyphs = element->params[2].data.number; | 420 | glyphs = element->params[2].data.number; |
416 | else | 421 | else |
417 | glyphs = GLYPHS_TO_CACHE; | 422 | glyphs = GLYPHS_TO_CACHE; |
423 | if (id < 2) | ||
424 | { | ||
425 | DEBUGF("font id must be >= 2\n"); | ||
426 | return 1; | ||
427 | } | ||
418 | #if defined(DEBUG) || defined(SIMULATOR) | 428 | #if defined(DEBUG) || defined(SIMULATOR) |
419 | if (skinfonts[id-FONT_FIRSTUSERFONT].name != NULL) | 429 | if (skinfonts[id-2].name != NULL) |
420 | { | 430 | { |
421 | DEBUGF("font id %d already being used\n", id); | 431 | DEBUGF("font id %d already being used\n", id); |
422 | } | 432 | } |
@@ -426,9 +436,9 @@ static int parse_font_load(struct skin_element *element, | |||
426 | ptr = strchr(filename, '.'); | 436 | ptr = strchr(filename, '.'); |
427 | if (!ptr || strncmp(ptr, ".fnt", 4)) | 437 | if (!ptr || strncmp(ptr, ".fnt", 4)) |
428 | return WPS_ERROR_INVALID_PARAM; | 438 | return WPS_ERROR_INVALID_PARAM; |
429 | skinfonts[id-FONT_FIRSTUSERFONT].id = -1; | 439 | skinfonts[id-2].id = -1; |
430 | skinfonts[id-FONT_FIRSTUSERFONT].name = filename; | 440 | skinfonts[id-2].name = filename; |
431 | skinfonts[id-FONT_FIRSTUSERFONT].glyphs = glyphs; | 441 | skinfonts[id-2].glyphs = glyphs; |
432 | 442 | ||
433 | return 0; | 443 | return 0; |
434 | } | 444 | } |
@@ -1442,6 +1452,11 @@ void skin_data_free_buflib_allocs(struct wps_data *wps_data) | |||
1442 | core_free(img->buflib_handle); | 1452 | core_free(img->buflib_handle); |
1443 | list = list->next; | 1453 | list = list->next; |
1444 | } | 1454 | } |
1455 | if (wps_data->font_ids != NULL) | ||
1456 | { | ||
1457 | while (wps_data->font_count > 0) | ||
1458 | font_unload(wps_data->font_ids[--wps_data->font_count]); | ||
1459 | } | ||
1445 | #endif | 1460 | #endif |
1446 | #endif | 1461 | #endif |
1447 | } | 1462 | } |
@@ -1617,6 +1632,8 @@ static bool load_skin_bitmaps(struct wps_data *wps_data, char *bmpdir) | |||
1617 | static bool skin_load_fonts(struct wps_data *data) | 1632 | static bool skin_load_fonts(struct wps_data *data) |
1618 | { | 1633 | { |
1619 | /* don't spit out after the first failue to aid debugging */ | 1634 | /* don't spit out after the first failue to aid debugging */ |
1635 | int id_array[MAXUSERFONTS]; | ||
1636 | int font_count = 0; | ||
1620 | bool success = true; | 1637 | bool success = true; |
1621 | struct skin_element *vp_list; | 1638 | struct skin_element *vp_list; |
1622 | int font_id; | 1639 | int font_id; |
@@ -1628,19 +1645,20 @@ static bool skin_load_fonts(struct wps_data *data) | |||
1628 | (struct skin_viewport*)vp_list->data; | 1645 | (struct skin_viewport*)vp_list->data; |
1629 | struct viewport *vp = &skin_vp->vp; | 1646 | struct viewport *vp = &skin_vp->vp; |
1630 | 1647 | ||
1631 | 1648 | font_id = skin_vp->parsed_fontid; | |
1632 | if (vp->font <= FONT_UI) | 1649 | if (font_id == 1) |
1633 | { /* the usual case -> built-in fonts */ | 1650 | { /* the usual case -> built-in fonts */ |
1634 | #ifdef HAVE_REMOTE_LCD | 1651 | vp->font = global_status.font_id[curr_screen]; |
1635 | if (vp->font == FONT_UI) | 1652 | continue; |
1636 | vp->font += curr_screen; | 1653 | } |
1637 | #endif | 1654 | else if (font_id <= 0) |
1655 | { | ||
1656 | vp->font = FONT_SYSFIXED; | ||
1638 | continue; | 1657 | continue; |
1639 | } | 1658 | } |
1640 | font_id = vp->font; | ||
1641 | 1659 | ||
1642 | /* now find the corresponding skin_font */ | 1660 | /* now find the corresponding skin_font */ |
1643 | struct skin_font *font = &skinfonts[font_id-FONT_FIRSTUSERFONT]; | 1661 | struct skin_font *font = &skinfonts[font_id-2]; |
1644 | if (!font->name) | 1662 | if (!font->name) |
1645 | { | 1663 | { |
1646 | if (success) | 1664 | if (success) |
@@ -1655,10 +1673,12 @@ static bool skin_load_fonts(struct wps_data *data) | |||
1655 | * multiple viewports use the same */ | 1673 | * multiple viewports use the same */ |
1656 | if (font->id < 0) | 1674 | if (font->id < 0) |
1657 | { | 1675 | { |
1658 | char *dot = strchr(font->name, '.'); | 1676 | char path[MAX_PATH]; |
1659 | *dot = '\0'; | 1677 | snprintf(path, sizeof path, FONT_DIR "/%s", font->name); |
1660 | font->id = skin_font_load(font->name, | 1678 | font->id = font_load(path/*, |
1661 | skinfonts[font_id-FONT_FIRSTUSERFONT].glyphs); | 1679 | skinfonts[font_id-FONT_FIRSTUSERFONT].glyphs*/); |
1680 | //printf("[%d] %s -> %d\n",font_id, font->name, font->id); | ||
1681 | id_array[font_count++] = font->id; | ||
1662 | } | 1682 | } |
1663 | 1683 | ||
1664 | if (font->id < 0) | 1684 | if (font->id < 0) |
@@ -1667,13 +1687,24 @@ static bool skin_load_fonts(struct wps_data *data) | |||
1667 | font_id, font->name); | 1687 | font_id, font->name); |
1668 | font->name = NULL; /* to stop trying to load it again if we fail */ | 1688 | font->name = NULL; /* to stop trying to load it again if we fail */ |
1669 | success = false; | 1689 | success = false; |
1670 | font->name = NULL; | ||
1671 | continue; | 1690 | continue; |
1672 | } | 1691 | } |
1673 | 1692 | ||
1674 | /* finally, assign the font_id to the viewport */ | 1693 | /* finally, assign the font_id to the viewport */ |
1675 | vp->font = font->id; | 1694 | vp->font = font->id; |
1676 | } | 1695 | } |
1696 | if (success) | ||
1697 | { | ||
1698 | data->font_ids = skin_buffer_alloc(font_count * sizeof(int)); | ||
1699 | if (data->font_ids == NULL) | ||
1700 | { | ||
1701 | while (font_count > 0) | ||
1702 | font_unload(id_array[--font_count]); | ||
1703 | return false; | ||
1704 | } | ||
1705 | memcpy(data->font_ids, id_array, sizeof(int)*font_count); | ||
1706 | data->font_count = font_count; | ||
1707 | } | ||
1677 | return success; | 1708 | return success; |
1678 | } | 1709 | } |
1679 | 1710 | ||
@@ -1690,17 +1721,12 @@ static int convert_viewport(struct wps_data *data, struct skin_element* element) | |||
1690 | skin_vp->hidden_flags = 0; | 1721 | skin_vp->hidden_flags = 0; |
1691 | skin_vp->label = NULL; | 1722 | skin_vp->label = NULL; |
1692 | skin_vp->is_infovp = false; | 1723 | skin_vp->is_infovp = false; |
1724 | skin_vp->parsed_fontid = 1; | ||
1693 | element->data = skin_vp; | 1725 | element->data = skin_vp; |
1694 | curr_vp = skin_vp; | 1726 | curr_vp = skin_vp; |
1695 | curr_viewport_element = element; | 1727 | curr_viewport_element = element; |
1696 | 1728 | ||
1697 | viewport_set_defaults(&skin_vp->vp, curr_screen); | 1729 | viewport_set_defaults(&skin_vp->vp, curr_screen); |
1698 | #ifdef HAVE_REMOTE_LCD | ||
1699 | /* viewport_set_defaults() sets the font to FONT_UI+curr_screen. | ||
1700 | * This parser requires font 1 to always be the UI font, | ||
1701 | * so force it back to FONT_UI and handle the screen number at the end */ | ||
1702 | skin_vp->vp.font = FONT_UI; | ||
1703 | #endif | ||
1704 | 1730 | ||
1705 | #if (LCD_DEPTH > 1) || (defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)) | 1731 | #if (LCD_DEPTH > 1) || (defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)) |
1706 | skin_vp->start_fgcolour = skin_vp->vp.fg_pattern; | 1732 | skin_vp->start_fgcolour = skin_vp->vp.fg_pattern; |
@@ -1788,9 +1814,7 @@ static int convert_viewport(struct wps_data *data, struct skin_element* element) | |||
1788 | #ifdef HAVE_LCD_BITMAP | 1814 | #ifdef HAVE_LCD_BITMAP |
1789 | /* font */ | 1815 | /* font */ |
1790 | if (!isdefault(param)) | 1816 | if (!isdefault(param)) |
1791 | { | 1817 | skin_vp->parsed_fontid = param->data.number; |
1792 | skin_vp->vp.font = param->data.number; | ||
1793 | } | ||
1794 | #endif | 1818 | #endif |
1795 | if ((unsigned) skin_vp->vp.x >= (unsigned) display->lcdwidth || | 1819 | if ((unsigned) skin_vp->vp.x >= (unsigned) display->lcdwidth || |
1796 | skin_vp->vp.width + skin_vp->vp.x > display->lcdwidth || | 1820 | skin_vp->vp.width + skin_vp->vp.x > display->lcdwidth || |
diff --git a/apps/gui/skin_engine/skin_render.c b/apps/gui/skin_engine/skin_render.c index 994ca23553..5a64be17dc 100644 --- a/apps/gui/skin_engine/skin_render.c +++ b/apps/gui/skin_engine/skin_render.c | |||
@@ -31,6 +31,7 @@ | |||
31 | #ifdef HAVE_ALBUMART | 31 | #ifdef HAVE_ALBUMART |
32 | #include "albumart.h" | 32 | #include "albumart.h" |
33 | #endif | 33 | #endif |
34 | #include "settings.h" | ||
34 | #include "skin_display.h" | 35 | #include "skin_display.h" |
35 | #include "skin_engine.h" | 36 | #include "skin_engine.h" |
36 | #include "skin_parser.h" | 37 | #include "skin_parser.h" |
@@ -650,6 +651,10 @@ void skin_render_viewport(struct skin_element* viewport, struct gui_wps *gwps, | |||
650 | img->display = -1; | 651 | img->display = -1; |
651 | imglist = imglist->next; | 652 | imglist = imglist->next; |
652 | } | 653 | } |
654 | |||
655 | /* fix font ID's */ | ||
656 | if (skin_viewport->parsed_fontid == 1) | ||
657 | skin_viewport->vp.font = global_status.font_id[display->screen_type]; | ||
653 | #endif | 658 | #endif |
654 | 659 | ||
655 | while (line) | 660 | while (line) |
diff --git a/apps/gui/skin_engine/wps_internals.h b/apps/gui/skin_engine/wps_internals.h index 244d08595e..c16191c41d 100644 --- a/apps/gui/skin_engine/wps_internals.h +++ b/apps/gui/skin_engine/wps_internals.h | |||
@@ -182,6 +182,7 @@ struct skin_viewport { | |||
182 | char hidden_flags; | 182 | char hidden_flags; |
183 | bool is_infovp; | 183 | bool is_infovp; |
184 | char* label; | 184 | char* label; |
185 | int parsed_fontid; | ||
185 | #if LCD_DEPTH > 1 | 186 | #if LCD_DEPTH > 1 |
186 | unsigned start_fgcolour; | 187 | unsigned start_fgcolour; |
187 | unsigned start_bgcolour; | 188 | unsigned start_bgcolour; |
@@ -325,6 +326,8 @@ struct wps_data | |||
325 | struct skin_element *tree; | 326 | struct skin_element *tree; |
326 | #ifdef HAVE_LCD_BITMAP | 327 | #ifdef HAVE_LCD_BITMAP |
327 | struct skin_token_list *images; | 328 | struct skin_token_list *images; |
329 | int *font_ids; | ||
330 | int font_count; | ||
328 | #endif | 331 | #endif |
329 | #if LCD_DEPTH > 1 || defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1 | 332 | #if LCD_DEPTH > 1 || defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1 |
330 | struct { | 333 | struct { |
diff --git a/apps/gui/statusbar-skinned.c b/apps/gui/statusbar-skinned.c index 3f914bd922..ad9a391e4c 100644 --- a/apps/gui/statusbar-skinned.c +++ b/apps/gui/statusbar-skinned.c | |||
@@ -125,6 +125,10 @@ struct viewport *sb_skin_get_info_vp(enum screen_type screen) | |||
125 | viewportmanager_theme_undo(screen, true); | 125 | viewportmanager_theme_undo(screen, true); |
126 | } | 126 | } |
127 | vp = skin_find_item(infovp_label[screen], SKIN_FIND_UIVP, data); | 127 | vp = skin_find_item(infovp_label[screen], SKIN_FIND_UIVP, data); |
128 | if (!vp) | ||
129 | return NULL; | ||
130 | if (vp->parsed_fontid == 1) | ||
131 | vp->vp.font = global_status.font_id[screen]; | ||
128 | return &vp->vp; | 132 | return &vp->vp; |
129 | } | 133 | } |
130 | 134 | ||
diff --git a/apps/gui/usb_screen.c b/apps/gui/usb_screen.c index 66b7094760..2b3355021d 100644 --- a/apps/gui/usb_screen.c +++ b/apps/gui/usb_screen.c | |||
@@ -41,7 +41,6 @@ | |||
41 | 41 | ||
42 | #ifdef HAVE_LCD_BITMAP | 42 | #ifdef HAVE_LCD_BITMAP |
43 | #include "bitmaps/usblogo.h" | 43 | #include "bitmaps/usblogo.h" |
44 | #include "skin_engine/skin_fonts.h" | ||
45 | #endif | 44 | #endif |
46 | 45 | ||
47 | #ifdef HAVE_REMOTE_LCD | 46 | #ifdef HAVE_REMOTE_LCD |
@@ -265,11 +264,9 @@ void gui_usb_screen_run(bool early_usb) | |||
265 | { | 264 | { |
266 | /* The font system leaves the .fnt fd's open, so we need for force close them all */ | 265 | /* The font system leaves the .fnt fd's open, so we need for force close them all */ |
267 | #ifdef HAVE_LCD_BITMAP | 266 | #ifdef HAVE_LCD_BITMAP |
268 | font_reset(NULL); | 267 | FOR_NB_SCREENS(i) |
269 | #ifdef HAVE_REMOTE_LCD | 268 | font_unload(global_status.font_id[i]); |
270 | font_load_remoteui(NULL); | 269 | // FIXME skin_font_init(); /* unload all the skin fonts */ |
271 | #endif | ||
272 | skin_font_init(); /* unload all the skin fonts */ | ||
273 | #endif | 270 | #endif |
274 | } | 271 | } |
275 | 272 | ||
diff --git a/apps/gui/viewport.c b/apps/gui/viewport.c index 34ebbf9043..df8093d581 100644 --- a/apps/gui/viewport.c +++ b/apps/gui/viewport.c | |||
@@ -272,13 +272,10 @@ void viewportmanager_theme_changed(const int which) | |||
272 | screens[SCREEN_MAIN].has_buttonbar = global_settings.buttonbar; | 272 | screens[SCREEN_MAIN].has_buttonbar = global_settings.buttonbar; |
273 | } | 273 | } |
274 | #endif | 274 | #endif |
275 | if (which & THEME_UI_VIEWPORT) | ||
276 | { | ||
277 | } | ||
278 | if (which & THEME_LANGUAGE) | 275 | if (which & THEME_LANGUAGE) |
279 | { | 276 | { |
280 | } | 277 | } |
281 | if (which & THEME_STATUSBAR) | 278 | if (which & (THEME_STATUSBAR|THEME_UI_VIEWPORT)) |
282 | { | 279 | { |
283 | FOR_NB_SCREENS(i) | 280 | FOR_NB_SCREENS(i) |
284 | { | 281 | { |
@@ -324,7 +321,7 @@ void viewport_set_fullscreen(struct viewport *vp, | |||
324 | #ifndef __PCTOOL__ | 321 | #ifndef __PCTOOL__ |
325 | set_default_align_flags(vp); | 322 | set_default_align_flags(vp); |
326 | #endif | 323 | #endif |
327 | vp->font = FONT_UI + screen; /* default to UI to discourage SYSFONT use */ | 324 | vp->font = global_status.font_id[screen]; |
328 | vp->drawmode = DRMODE_SOLID; | 325 | vp->drawmode = DRMODE_SOLID; |
329 | #if LCD_DEPTH > 1 | 326 | #if LCD_DEPTH > 1 |
330 | #ifdef HAVE_REMOTE_LCD | 327 | #ifdef HAVE_REMOTE_LCD |
diff --git a/apps/main.c b/apps/main.c index 07a8bba44c..ae666adc06 100644 --- a/apps/main.c +++ b/apps/main.c | |||
@@ -336,6 +336,7 @@ static void init_tagcache(void) | |||
336 | 336 | ||
337 | static void init(void) | 337 | static void init(void) |
338 | { | 338 | { |
339 | int i; | ||
339 | system_init(); | 340 | system_init(); |
340 | core_allocator_init(); | 341 | core_allocator_init(); |
341 | kernel_init(); | 342 | kernel_init(); |
@@ -347,7 +348,11 @@ static void init(void) | |||
347 | #ifdef HAVE_REMOTE_LCD | 348 | #ifdef HAVE_REMOTE_LCD |
348 | lcd_remote_init(); | 349 | lcd_remote_init(); |
349 | #endif | 350 | #endif |
351 | #ifdef HAVE_LCD_BITMAP | ||
352 | FOR_NB_SCREENS(i) | ||
353 | global_status.font_id[i] = FONT_SYSFIXED; | ||
350 | font_init(); | 354 | font_init(); |
355 | #endif | ||
351 | show_logo(); | 356 | show_logo(); |
352 | button_init(); | 357 | button_init(); |
353 | powermgmt_init(); | 358 | powermgmt_init(); |
@@ -451,7 +456,11 @@ static void init(void) | |||
451 | #ifdef HAVE_REMOTE_LCD | 456 | #ifdef HAVE_REMOTE_LCD |
452 | lcd_remote_init(); | 457 | lcd_remote_init(); |
453 | #endif | 458 | #endif |
459 | #ifdef HAVE_LCD_BITMAP | ||
460 | FOR_NB_SCREENS(rc) | ||
461 | global_status.font_id[rc] = FONT_SYSFIXED; | ||
454 | font_init(); | 462 | font_init(); |
463 | #endif | ||
455 | 464 | ||
456 | CHART(">show_logo"); | 465 | CHART(">show_logo"); |
457 | show_logo(); | 466 | show_logo(); |
diff --git a/apps/menus/theme_menu.c b/apps/menus/theme_menu.c index b483a7ef11..078691e1a8 100644 --- a/apps/menus/theme_menu.c +++ b/apps/menus/theme_menu.c | |||
@@ -19,6 +19,7 @@ | |||
19 | * | 19 | * |
20 | ****************************************************************************/ | 20 | ****************************************************************************/ |
21 | 21 | ||
22 | #include <stdio.h> | ||
22 | #include <stdbool.h> | 23 | #include <stdbool.h> |
23 | #include <stddef.h> | 24 | #include <stddef.h> |
24 | #include <limits.h> | 25 | #include <limits.h> |
diff --git a/apps/plugin.c b/apps/plugin.c index 2517a7183f..7c75a43080 100644 --- a/apps/plugin.c +++ b/apps/plugin.c | |||
@@ -174,7 +174,7 @@ static const struct plugin_api rockbox_api = { | |||
174 | lcd_update_rect, | 174 | lcd_update_rect, |
175 | lcd_set_drawmode, | 175 | lcd_set_drawmode, |
176 | lcd_get_drawmode, | 176 | lcd_get_drawmode, |
177 | lcd_setfont, | 177 | screen_helper_setfont, |
178 | lcd_drawpixel, | 178 | lcd_drawpixel, |
179 | lcd_drawline, | 179 | lcd_drawline, |
180 | lcd_hline, | 180 | lcd_hline, |
@@ -230,6 +230,7 @@ static const struct plugin_api rockbox_api = { | |||
230 | #endif | 230 | #endif |
231 | font_get_bits, | 231 | font_get_bits, |
232 | font_load, | 232 | font_load, |
233 | font_unload, | ||
233 | font_get, | 234 | font_get, |
234 | font_getstringsize, | 235 | font_getstringsize, |
235 | font_get_width, | 236 | font_get_width, |
@@ -905,7 +906,7 @@ int plugin_load(const char* plugin, const void* parameter) | |||
905 | #endif | 906 | #endif |
906 | 907 | ||
907 | #ifdef HAVE_LCD_BITMAP | 908 | #ifdef HAVE_LCD_BITMAP |
908 | lcd_setfont(FONT_UI); | 909 | screen_helper_setfont(FONT_UI); |
909 | #if LCD_DEPTH > 1 | 910 | #if LCD_DEPTH > 1 |
910 | #ifdef HAVE_LCD_COLOR | 911 | #ifdef HAVE_LCD_COLOR |
911 | lcd_set_drawinfo(DRMODE_SOLID, global_settings.fg_color, | 912 | lcd_set_drawinfo(DRMODE_SOLID, global_settings.fg_color, |
diff --git a/apps/plugin.h b/apps/plugin.h index a33089bece..e0ee951185 100644 --- a/apps/plugin.h +++ b/apps/plugin.h | |||
@@ -272,7 +272,8 @@ struct plugin_api { | |||
272 | bool (*is_diacritic)(const unsigned short char_code, bool *is_rtl); | 272 | bool (*is_diacritic)(const unsigned short char_code, bool *is_rtl); |
273 | #endif | 273 | #endif |
274 | const unsigned char *(*font_get_bits)( struct font *pf, unsigned short char_code ); | 274 | const unsigned char *(*font_get_bits)( struct font *pf, unsigned short char_code ); |
275 | int (*font_load)(struct font*, const char *path); | 275 | int (*font_load)(const char *path); |
276 | void (*font_unload)(int font_id); | ||
276 | struct font* (*font_get)(int font); | 277 | struct font* (*font_get)(int font); |
277 | int (*font_getstringsize)(const unsigned char *str, int *w, int *h, | 278 | int (*font_getstringsize)(const unsigned char *str, int *w, int *h, |
278 | int fontnumber); | 279 | int fontnumber); |
diff --git a/apps/plugins/beatbox/beatbox.c b/apps/plugins/beatbox/beatbox.c index b09464ab14..8ecbabd1e5 100644 --- a/apps/plugins/beatbox/beatbox.c +++ b/apps/plugins/beatbox/beatbox.c | |||
@@ -265,7 +265,7 @@ enum plugin_status plugin_start(const void* parameter) | |||
265 | { | 265 | { |
266 | int retval = 0; | 266 | int retval = 0; |
267 | 267 | ||
268 | rb->lcd_setfont(0); | 268 | rb->lcd_setfont(FONT_SYSFIXED); |
269 | 269 | ||
270 | #if defined(HAVE_ADJUSTABLE_CPU_FREQ) | 270 | #if defined(HAVE_ADJUSTABLE_CPU_FREQ) |
271 | rb->cpu_boost(true); | 271 | rb->cpu_boost(true); |
diff --git a/apps/plugins/doom/rockdoom.c b/apps/plugins/doom/rockdoom.c index 1c2777a8ad..85e3225af8 100644 --- a/apps/plugins/doom/rockdoom.c +++ b/apps/plugins/doom/rockdoom.c | |||
@@ -667,7 +667,7 @@ enum plugin_status plugin_start(const void* parameter) | |||
667 | rb->cpu_boost(true); | 667 | rb->cpu_boost(true); |
668 | #endif | 668 | #endif |
669 | 669 | ||
670 | rb->lcd_setfont(0); | 670 | rb->lcd_setfont(FONT_SYSFIXED); |
671 | 671 | ||
672 | // We're using doom's memory management since it implements a proper free (and re-uses the memory) | 672 | // We're using doom's memory management since it implements a proper free (and re-uses the memory) |
673 | // and now with prboom's code: realloc and calloc | 673 | // and now with prboom's code: realloc and calloc |
@@ -712,7 +712,7 @@ enum plugin_status plugin_start(const void* parameter) | |||
712 | 712 | ||
713 | Dhandle_ver( namemap[ result ] ); | 713 | Dhandle_ver( namemap[ result ] ); |
714 | 714 | ||
715 | rb->lcd_setfont(0); | 715 | rb->lcd_setfont(FONT_SYSFIXED); |
716 | 716 | ||
717 | rb->lcd_clear_display(); | 717 | rb->lcd_clear_display(); |
718 | 718 | ||
diff --git a/apps/plugins/lua/rocklib.c b/apps/plugins/lua/rocklib.c index 46572014f0..ddd4081371 100644 --- a/apps/plugins/lua/rocklib.c +++ b/apps/plugins/lua/rocklib.c | |||
@@ -433,6 +433,11 @@ RB_WRAP(font_getstringsize) | |||
433 | int fontnumber = luaL_checkint(L, 2); | 433 | int fontnumber = luaL_checkint(L, 2); |
434 | int w, h; | 434 | int w, h; |
435 | 435 | ||
436 | if (fontnumber == FONT_UI) | ||
437 | fontnumber = rb->global_status->font_id[SCREEN_MAIN]; | ||
438 | else | ||
439 | fontnumber = FONT_SYSFIXED; | ||
440 | |||
436 | int result = rb->font_getstringsize(str, &w, &h, fontnumber); | 441 | int result = rb->font_getstringsize(str, &w, &h, fontnumber); |
437 | lua_pushinteger(L, result); | 442 | lua_pushinteger(L, result); |
438 | lua_pushinteger(L, w); | 443 | lua_pushinteger(L, w); |
diff --git a/apps/plugins/midi/midiplay.c b/apps/plugins/midi/midiplay.c index 9bf4d50822..16d153a1ba 100644 --- a/apps/plugins/midi/midiplay.c +++ b/apps/plugins/midi/midiplay.c | |||
@@ -470,7 +470,7 @@ enum plugin_status plugin_start(const void* parameter) | |||
470 | rb->splash(HZ*2, " Play .MID file "); | 470 | rb->splash(HZ*2, " Play .MID file "); |
471 | return PLUGIN_OK; | 471 | return PLUGIN_OK; |
472 | } | 472 | } |
473 | rb->lcd_setfont(0); | 473 | rb->lcd_setfont(FONT_SYSFIXED); |
474 | 474 | ||
475 | #if defined(HAVE_ADJUSTABLE_CPU_FREQ) | 475 | #if defined(HAVE_ADJUSTABLE_CPU_FREQ) |
476 | rb->cpu_boost(true); | 476 | rb->cpu_boost(true); |
diff --git a/apps/plugins/mikmod/mikmod.c b/apps/plugins/mikmod/mikmod.c index 5f19b43759..a7eeb5019f 100644 --- a/apps/plugins/mikmod/mikmod.c +++ b/apps/plugins/mikmod/mikmod.c | |||
@@ -823,7 +823,7 @@ int playfile(char* filename) | |||
823 | retval = menureturn; | 823 | retval = menureturn; |
824 | } | 824 | } |
825 | } | 825 | } |
826 | rb->lcd_setfont(0); | 826 | rb->lcd_setfont(FONT_SYSFIXED); |
827 | screenupdated = false; | 827 | screenupdated = false; |
828 | break; | 828 | break; |
829 | 829 | ||
@@ -877,7 +877,7 @@ enum plugin_status plugin_start(const void* parameter) | |||
877 | return PLUGIN_OK; | 877 | return PLUGIN_OK; |
878 | } | 878 | } |
879 | 879 | ||
880 | rb->lcd_setfont(0); | 880 | rb->lcd_setfont(FONT_SYSFIXED); |
881 | 881 | ||
882 | rb->pcm_play_stop(); | 882 | rb->pcm_play_stop(); |
883 | #if INPUT_SRC_CAPS != 0 | 883 | #if INPUT_SRC_CAPS != 0 |
diff --git a/apps/plugins/rockboy/menu.c b/apps/plugins/rockboy/menu.c index 54a0db76f5..3cd231c06c 100644 --- a/apps/plugins/rockboy/menu.c +++ b/apps/plugins/rockboy/menu.c | |||
@@ -125,7 +125,7 @@ int do_user_menu(void) { | |||
125 | } | 125 | } |
126 | } | 126 | } |
127 | 127 | ||
128 | rb->lcd_setfont(0); /* Reset the font */ | 128 | rb->lcd_setfont(FONT_SYSFIXED); /* Reset the font */ |
129 | rb->lcd_clear_display(); /* Clear display for screen size changes */ | 129 | rb->lcd_clear_display(); /* Clear display for screen size changes */ |
130 | 130 | ||
131 | /* Keep the RTC in sync */ | 131 | /* Keep the RTC in sync */ |
diff --git a/apps/plugins/rockboy/rockboy.c b/apps/plugins/rockboy/rockboy.c index 4dc88fdf5a..88828815aa 100644 --- a/apps/plugins/rockboy/rockboy.c +++ b/apps/plugins/rockboy/rockboy.c | |||
@@ -409,7 +409,7 @@ static int gnuboy_main(const char *rom) | |||
409 | /* this is the plugin entry point */ | 409 | /* this is the plugin entry point */ |
410 | enum plugin_status plugin_start(const void* parameter) | 410 | enum plugin_status plugin_start(const void* parameter) |
411 | { | 411 | { |
412 | rb->lcd_setfont(0); | 412 | rb->lcd_setfont(FONT_SYSFIXED); |
413 | 413 | ||
414 | rb->lcd_clear_display(); | 414 | rb->lcd_clear_display(); |
415 | 415 | ||
diff --git a/apps/plugins/rockpaint.c b/apps/plugins/rockpaint.c index d1cc8f272a..7938273ba0 100644 --- a/apps/plugins/rockpaint.c +++ b/apps/plugins/rockpaint.c | |||
@@ -1016,7 +1016,6 @@ static bool browse_fonts( char *dst, int dst_size ) | |||
1016 | size_t siz; | 1016 | size_t siz; |
1017 | reset_font = true; | 1017 | reset_font = true; |
1018 | rb->snprintf( bbuf, MAX_PATH, FONT_DIR "/%s", e->name ); | 1018 | rb->snprintf( bbuf, MAX_PATH, FONT_DIR "/%s", e->name ); |
1019 | rb->font_load(NULL, bbuf ); | ||
1020 | rb->font_getstringsize( e->name, &fw, &fh, FONT_UI ); | 1019 | rb->font_getstringsize( e->name, &fw, &fh, FONT_UI ); |
1021 | if( fw > LCD_WIDTH ) fw = LCD_WIDTH; | 1020 | if( fw > LCD_WIDTH ) fw = LCD_WIDTH; |
1022 | siz = (sizeof(struct font_preview) + fw*fh*FB_DATA_SZ+3) & ~3; | 1021 | siz = (sizeof(struct font_preview) + fw*fh*FB_DATA_SZ+3) & ~3; |
@@ -1083,7 +1082,7 @@ static bool browse_fonts( char *dst, int dst_size ) | |||
1083 | li = tree->filesindir-1; | 1082 | li = tree->filesindir-1; |
1084 | if( reset_font ) | 1083 | if( reset_font ) |
1085 | { | 1084 | { |
1086 | rb->font_load(NULL, bbuf_s ); | 1085 | // fixme rb->font_load(NULL, bbuf_s ); |
1087 | reset_font = false; | 1086 | reset_font = false; |
1088 | } | 1087 | } |
1089 | if( lvi-fvi+1 < tree->filesindir ) | 1088 | if( lvi-fvi+1 < tree->filesindir ) |
@@ -1636,6 +1635,7 @@ static void show_grid( bool update ) | |||
1636 | static void draw_text( int x, int y ) | 1635 | static void draw_text( int x, int y ) |
1637 | { | 1636 | { |
1638 | int selected = 0; | 1637 | int selected = 0; |
1638 | int current_font_id = rb->global_status->font_id[SCREEN_MAIN]; | ||
1639 | buffer->text.text[0] = '\0'; | 1639 | buffer->text.text[0] = '\0'; |
1640 | buffer->text.font[0] = '\0'; | 1640 | buffer->text.font[0] = '\0'; |
1641 | while( 1 ) | 1641 | while( 1 ) |
@@ -1648,9 +1648,12 @@ static void draw_text( int x, int y ) | |||
1648 | break; | 1648 | break; |
1649 | 1649 | ||
1650 | case TEXT_MENU_FONT: | 1650 | case TEXT_MENU_FONT: |
1651 | if( browse_fonts( buffer->text.font, MAX_PATH ) ) | 1651 | if (current_font_id != rb->global_status->font_id[SCREEN_MAIN]) |
1652 | rb->font_unload(current_font_id); | ||
1653 | if(browse_fonts( buffer->text.font, MAX_PATH ) ) | ||
1652 | { | 1654 | { |
1653 | rb->font_load(NULL, buffer->text.font ); | 1655 | current_font_id = rb->font_load(buffer->text.font ); |
1656 | rb->lcd_setfont(current_font_id); | ||
1654 | } | 1657 | } |
1655 | break; | 1658 | break; |
1656 | 1659 | ||
@@ -1704,7 +1707,9 @@ static void draw_text( int x, int y ) | |||
1704 | rb->snprintf( buffer->text.font, MAX_PATH, | 1707 | rb->snprintf( buffer->text.font, MAX_PATH, |
1705 | FONT_DIR "/%s.fnt", | 1708 | FONT_DIR "/%s.fnt", |
1706 | rb->global_settings->font_file ); | 1709 | rb->global_settings->font_file ); |
1707 | rb->font_load(NULL, buffer->text.font ); | 1710 | if (current_font_id != rb->global_status->font_id[SCREEN_MAIN]) |
1711 | rb->font_unload(current_font_id); | ||
1712 | rb->lcd_setfont(FONT_UI); | ||
1708 | } | 1713 | } |
1709 | return; | 1714 | return; |
1710 | } | 1715 | } |
diff --git a/apps/plugins/text_viewer/tv_display.c b/apps/plugins/text_viewer/tv_display.c index d38f1b514c..2cf240db0e 100644 --- a/apps/plugins/text_viewer/tv_display.c +++ b/apps/plugins/text_viewer/tv_display.c | |||
@@ -255,7 +255,7 @@ void tv_set_layout(bool show_scrollbar) | |||
255 | int scrollbar_height = (show_scrollbar && preferences->horizontal_scrollbar)? | 255 | int scrollbar_height = (show_scrollbar && preferences->horizontal_scrollbar)? |
256 | TV_SCROLLBAR_HEIGHT + 1 : 0; | 256 | TV_SCROLLBAR_HEIGHT + 1 : 0; |
257 | 257 | ||
258 | row_height = preferences->font->height; | 258 | row_height = rb->font_get(preferences->font_id)->height; |
259 | 259 | ||
260 | header.x = 0; | 260 | header.x = 0; |
261 | header.y = 0; | 261 | header.y = 0; |
@@ -282,6 +282,7 @@ void tv_set_layout(bool show_scrollbar) | |||
282 | vp_text.y += vertical_scrollbar.y; | 282 | vp_text.y += vertical_scrollbar.y; |
283 | vp_text.width = horizontal_scrollbar.w; | 283 | vp_text.width = horizontal_scrollbar.w; |
284 | vp_text.height = vertical_scrollbar.h; | 284 | vp_text.height = vertical_scrollbar.h; |
285 | vp_text.font = preferences->font_id; | ||
285 | #else | 286 | #else |
286 | (void) show_scrollbar; | 287 | (void) show_scrollbar; |
287 | 288 | ||
@@ -334,16 +335,20 @@ static void tv_change_viewport(void) | |||
334 | static bool tv_set_font(const unsigned char *font) | 335 | static bool tv_set_font(const unsigned char *font) |
335 | { | 336 | { |
336 | unsigned char path[MAX_PATH]; | 337 | unsigned char path[MAX_PATH]; |
337 | |||
338 | if (font != NULL && *font != '\0') | 338 | if (font != NULL && *font != '\0') |
339 | { | 339 | { |
340 | rb->snprintf(path, MAX_PATH, "%s/%s.fnt", FONT_DIR, font); | 340 | rb->snprintf(path, MAX_PATH, "%s/%s.fnt", FONT_DIR, font); |
341 | if (rb->font_load(NULL, path) < 0) | 341 | if (preferences->font_id >= 0 && |
342 | (preferences->font_id != rb->global_status->font_id[SCREEN_MAIN])) | ||
343 | rb->font_unload(preferences->font_id); | ||
344 | tv_change_fontid(rb->font_load(path)); | ||
345 | if (preferences->font_id < 0) | ||
342 | { | 346 | { |
343 | rb->splash(HZ/2, "font load failed"); | 347 | rb->splash(HZ/2, "font load failed"); |
344 | return false; | 348 | return false; |
345 | } | 349 | } |
346 | } | 350 | } |
351 | vp_text.font = preferences->font_id; | ||
347 | return true; | 352 | return true; |
348 | } | 353 | } |
349 | #endif | 354 | #endif |
@@ -375,7 +380,7 @@ static int tv_change_preferences(const struct tv_preferences *oldp) | |||
375 | 380 | ||
376 | return (tv_set_preferences(&new_prefs))? TV_CALLBACK_STOP : TV_CALLBACK_ERROR; | 381 | return (tv_set_preferences(&new_prefs))? TV_CALLBACK_STOP : TV_CALLBACK_ERROR; |
377 | } | 382 | } |
378 | col_width = 2 * rb->font_get_width(preferences->font, ' '); | 383 | col_width = 2 * rb->font_get_width(rb->font_get(preferences->font_id), ' '); |
379 | font_changing = false; | 384 | font_changing = false; |
380 | } | 385 | } |
381 | #else | 386 | #else |
@@ -402,9 +407,10 @@ void tv_finalize_display(void) | |||
402 | { | 407 | { |
403 | #ifdef HAVE_LCD_BITMAP | 408 | #ifdef HAVE_LCD_BITMAP |
404 | /* restore font */ | 409 | /* restore font */ |
405 | if (rb->strcmp(rb->global_settings->font_file, preferences->font_name)) | 410 | if (preferences->font_id >= 0 && |
411 | (preferences->font_id != rb->global_status->font_id[SCREEN_MAIN])) | ||
406 | { | 412 | { |
407 | tv_set_font(rb->global_settings->font_file); | 413 | rb->font_unload(preferences->font_id); |
408 | } | 414 | } |
409 | 415 | ||
410 | /* undo viewport */ | 416 | /* undo viewport */ |
diff --git a/apps/plugins/text_viewer/tv_preferences.c b/apps/plugins/text_viewer/tv_preferences.c index 6d5c1127fc..86719ae16b 100644 --- a/apps/plugins/text_viewer/tv_preferences.c +++ b/apps/plugins/text_viewer/tv_preferences.c | |||
@@ -114,7 +114,7 @@ void tv_set_default_preferences(struct tv_preferences *p) | |||
114 | p->footer_mode = true; | 114 | p->footer_mode = true; |
115 | p->statusbar = true; | 115 | p->statusbar = true; |
116 | rb->strlcpy(p->font_name, rb->global_settings->font_file, MAX_PATH); | 116 | rb->strlcpy(p->font_name, rb->global_settings->font_file, MAX_PATH); |
117 | p->font = rb->font_get(FONT_UI); | 117 | p->font_id = rb->global_status->font_id[SCREEN_MAIN]; |
118 | #else | 118 | #else |
119 | p->header_mode = false; | 119 | p->header_mode = false; |
120 | p->footer_mode = false; | 120 | p->footer_mode = false; |
@@ -133,3 +133,11 @@ void tv_add_preferences_change_listner(int (*listner)(const struct tv_preference | |||
133 | if (listner_count < TV_MAX_LISTNERS) | 133 | if (listner_count < TV_MAX_LISTNERS) |
134 | listners[listner_count++] = listner; | 134 | listners[listner_count++] = listner; |
135 | } | 135 | } |
136 | |||
137 | void tv_change_fontid(int id) | ||
138 | { | ||
139 | (void)id; | ||
140 | #ifdef HAVE_LCD_BITMAP | ||
141 | prefs.font_id = id; | ||
142 | #endif | ||
143 | } | ||
diff --git a/apps/plugins/text_viewer/tv_preferences.h b/apps/plugins/text_viewer/tv_preferences.h index bb448b0f4b..f3b2aebfa6 100644 --- a/apps/plugins/text_viewer/tv_preferences.h +++ b/apps/plugins/text_viewer/tv_preferences.h | |||
@@ -95,7 +95,7 @@ struct tv_preferences { | |||
95 | 95 | ||
96 | #ifdef HAVE_LCD_BITMAP | 96 | #ifdef HAVE_LCD_BITMAP |
97 | unsigned char font_name[MAX_PATH]; | 97 | unsigned char font_name[MAX_PATH]; |
98 | struct font *font; | 98 | int font_id; |
99 | #endif | 99 | #endif |
100 | unsigned char file_name[MAX_PATH]; | 100 | unsigned char file_name[MAX_PATH]; |
101 | }; | 101 | }; |
@@ -151,4 +151,6 @@ void tv_set_default_preferences(struct tv_preferences *p); | |||
151 | */ | 151 | */ |
152 | void tv_add_preferences_change_listner(int (*listner)(const struct tv_preferences *oldp)); | 152 | void tv_add_preferences_change_listner(int (*listner)(const struct tv_preferences *oldp)); |
153 | 153 | ||
154 | |||
155 | void tv_change_fontid(int id); | ||
154 | #endif | 156 | #endif |
diff --git a/apps/plugins/text_viewer/tv_settings.c b/apps/plugins/text_viewer/tv_settings.c index 3ed1576dc5..895f162ebb 100644 --- a/apps/plugins/text_viewer/tv_settings.c +++ b/apps/plugins/text_viewer/tv_settings.c | |||
@@ -218,7 +218,7 @@ static bool tv_read_preferences(int pfd, int version, struct tv_preferences *pre | |||
218 | #ifdef HAVE_LCD_BITMAP | 218 | #ifdef HAVE_LCD_BITMAP |
219 | rb->strlcpy(prefs->font_name, buf + read_size - MAX_PATH, MAX_PATH); | 219 | rb->strlcpy(prefs->font_name, buf + read_size - MAX_PATH, MAX_PATH); |
220 | 220 | ||
221 | prefs->font = rb->font_get(FONT_UI); | 221 | prefs->font_id = rb->global_status->font_id[SCREEN_MAIN]; |
222 | #endif | 222 | #endif |
223 | 223 | ||
224 | return true; | 224 | return true; |
diff --git a/apps/plugins/text_viewer/tv_text_processor.c b/apps/plugins/text_viewer/tv_text_processor.c index edb2ad0483..d027a9a13a 100644 --- a/apps/plugins/text_viewer/tv_text_processor.c +++ b/apps/plugins/text_viewer/tv_text_processor.c | |||
@@ -95,7 +95,7 @@ static int tv_glyph_width(int ch) | |||
95 | if (rb->is_diacritic(ch, NULL)) | 95 | if (rb->is_diacritic(ch, NULL)) |
96 | return 0; | 96 | return 0; |
97 | 97 | ||
98 | return rb->font_get_width(preferences->font, ch); | 98 | return rb->font_get_width(rb->font_get(preferences->font_id), ch); |
99 | #else | 99 | #else |
100 | return 1; | 100 | return 1; |
101 | #endif | 101 | #endif |
diff --git a/apps/recorder/albumart.c b/apps/recorder/albumart.c index 5acb492412..43f18cd163 100644 --- a/apps/recorder/albumart.c +++ b/apps/recorder/albumart.c | |||
@@ -19,6 +19,7 @@ | |||
19 | * | 19 | * |
20 | ****************************************************************************/ | 20 | ****************************************************************************/ |
21 | 21 | ||
22 | #include <stdio.h> | ||
22 | #include "string-extra.h" | 23 | #include "string-extra.h" |
23 | #include "system.h" | 24 | #include "system.h" |
24 | #include "albumart.h" | 25 | #include "albumart.h" |
diff --git a/apps/screen_access.c b/apps/screen_access.c index b83e842de8..0b206a668a 100644 --- a/apps/screen_access.c +++ b/apps/screen_access.c | |||
@@ -67,6 +67,15 @@ static int screen_helper_getnblines(void) | |||
67 | return height / screens[0].getcharheight(); | 67 | return height / screens[0].getcharheight(); |
68 | } | 68 | } |
69 | 69 | ||
70 | void screen_helper_setfont(int font) | ||
71 | { | ||
72 | #ifdef HAVE_LCD_BITMAP | ||
73 | if (font == FONT_UI) | ||
74 | font = global_status.font_id[SCREEN_MAIN]; | ||
75 | lcd_setfont(font); | ||
76 | #endif | ||
77 | } | ||
78 | |||
70 | #if NB_SCREENS == 2 | 79 | #if NB_SCREENS == 2 |
71 | static int screen_helper_remote_getcharwidth(void) | 80 | static int screen_helper_remote_getcharwidth(void) |
72 | { | 81 | { |
@@ -99,6 +108,13 @@ static int screen_helper_remote_getnblines(void) | |||
99 | #endif | 108 | #endif |
100 | return height / screens[1].getcharheight(); | 109 | return height / screens[1].getcharheight(); |
101 | } | 110 | } |
111 | |||
112 | void screen_helper_remote_setfont(int font) | ||
113 | { | ||
114 | if (font == FONT_UI) | ||
115 | font = global_status.font_id[SCREEN_REMOTE]; | ||
116 | lcd_remote_setfont(font); | ||
117 | } | ||
102 | #endif | 118 | #endif |
103 | 119 | ||
104 | struct screen screens[NB_SCREENS] = | 120 | struct screen screens[NB_SCREENS] = |
@@ -129,7 +145,7 @@ struct screen screens[NB_SCREENS] = | |||
129 | .getheight=&lcd_getheight, | 145 | .getheight=&lcd_getheight, |
130 | .getstringsize=&lcd_getstringsize, | 146 | .getstringsize=&lcd_getstringsize, |
131 | #ifdef HAVE_LCD_BITMAP | 147 | #ifdef HAVE_LCD_BITMAP |
132 | .setfont=&lcd_setfont, | 148 | .setfont=screen_helper_setfont, |
133 | .getfont=&lcd_getfont, | 149 | .getfont=&lcd_getfont, |
134 | .mono_bitmap=&lcd_mono_bitmap, | 150 | .mono_bitmap=&lcd_mono_bitmap, |
135 | .mono_bitmap_part=&lcd_mono_bitmap_part, | 151 | .mono_bitmap_part=&lcd_mono_bitmap_part, |
@@ -229,7 +245,7 @@ struct screen screens[NB_SCREENS] = | |||
229 | .getheight=&lcd_remote_getheight, | 245 | .getheight=&lcd_remote_getheight, |
230 | .getstringsize=&lcd_remote_getstringsize, | 246 | .getstringsize=&lcd_remote_getstringsize, |
231 | #if 1 /* all remote LCDs are bitmapped so far */ | 247 | #if 1 /* all remote LCDs are bitmapped so far */ |
232 | .setfont=&lcd_remote_setfont, | 248 | .setfont=screen_helper_setfont, |
233 | .getfont=&lcd_remote_getfont, | 249 | .getfont=&lcd_remote_getfont, |
234 | .mono_bitmap=&lcd_remote_mono_bitmap, | 250 | .mono_bitmap=&lcd_remote_mono_bitmap, |
235 | .mono_bitmap_part=&lcd_remote_mono_bitmap_part, | 251 | .mono_bitmap_part=&lcd_remote_mono_bitmap_part, |
diff --git a/apps/screen_access.h b/apps/screen_access.h index efe232b50e..31ec34f2b6 100644 --- a/apps/screen_access.h +++ b/apps/screen_access.h | |||
@@ -28,9 +28,11 @@ | |||
28 | 28 | ||
29 | #if defined(HAVE_REMOTE_LCD) && !defined (ROCKBOX_HAS_LOGF) | 29 | #if defined(HAVE_REMOTE_LCD) && !defined (ROCKBOX_HAS_LOGF) |
30 | #define NB_SCREENS 2 | 30 | #define NB_SCREENS 2 |
31 | void screen_helper_remote_setfont(int font); | ||
31 | #else | 32 | #else |
32 | #define NB_SCREENS 1 | 33 | #define NB_SCREENS 1 |
33 | #endif | 34 | #endif |
35 | void screen_helper_setfont(int font); | ||
34 | 36 | ||
35 | #if NB_SCREENS == 1 | 37 | #if NB_SCREENS == 1 |
36 | #define FOR_NB_SCREENS(i) i = 0; | 38 | #define FOR_NB_SCREENS(i) i = 0; |
diff --git a/apps/settings.c b/apps/settings.c index 258facee38..14217ed1ae 100644 --- a/apps/settings.c +++ b/apps/settings.c | |||
@@ -876,30 +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 | 880 | ||
880 | snprintf(buf, sizeof buf, FONT_DIR "/%s.fnt", | 881 | snprintf(buf, sizeof buf, FONT_DIR "/%s.fnt", |
881 | global_settings.font_file); | 882 | global_settings.font_file); |
882 | CHART2(">font_load ", global_settings.font_file); | 883 | if (!loaded_font || strcmp(loaded_font, buf)) |
883 | rc = font_load(NULL, buf); | 884 | { |
884 | CHART2("<font_load ", global_settings.font_file); | 885 | CHART2(">font_load ", global_settings.font_file); |
885 | if (rc < 0) | 886 | if (global_status.font_id[SCREEN_MAIN] >= 0) |
886 | font_reset(NULL); | 887 | font_unload(global_status.font_id[SCREEN_MAIN]); |
888 | rc = font_load(buf); | ||
889 | CHART2("<font_load ", global_settings.font_file); | ||
890 | global_status.font_id[SCREEN_MAIN] = rc; | ||
891 | lcd_setfont(rc); | ||
892 | } | ||
887 | } | 893 | } |
888 | else | ||
889 | font_reset(NULL); | ||
890 | #ifdef HAVE_REMOTE_LCD | 894 | #ifdef HAVE_REMOTE_LCD |
891 | if ( global_settings.remote_font_file[0] | 895 | if ( global_settings.remote_font_file[0] |
892 | && global_settings.remote_font_file[0] != '-') { | 896 | && global_settings.remote_font_file[0] != '-') { |
897 | const char* loaded_font = font_filename(global_status.font_id[SCREEN_REMOTE]); | ||
893 | snprintf(buf, sizeof buf, FONT_DIR "/%s.fnt", | 898 | snprintf(buf, sizeof buf, FONT_DIR "/%s.fnt", |
894 | global_settings.remote_font_file); | 899 | global_settings.remote_font_file); |
895 | CHART2(">font_load_remoteui ", global_settings.remote_font_file); | 900 | if (!loaded_font || strcmp(loaded_font, buf)) |
896 | rc = font_load_remoteui(buf); | 901 | { |
897 | CHART2("<font_load_remoteui ", global_settings.remote_font_file); | 902 | CHART2(">font_load_remoteui ", global_settings.remote_font_file); |
898 | if (rc < 0) | 903 | if (global_status.font_id[SCREEN_REMOTE] >= 0) |
899 | font_load_remoteui(NULL); | 904 | font_unload(global_status.font_id[SCREEN_REMOTE]); |
905 | rc = font_load(buf); | ||
906 | CHART2("<font_load_remoteui ", global_settings.remote_font_file); | ||
907 | global_status.font_id[SCREEN_REMOTE] = rc; | ||
908 | lcd_remote_setfont(rc); | ||
909 | } | ||
900 | } | 910 | } |
901 | else | ||
902 | font_load_remoteui(NULL); | ||
903 | #endif | 911 | #endif |
904 | if ( global_settings.kbd_file[0] | 912 | if ( global_settings.kbd_file[0] |
905 | && global_settings.kbd_file[0] != '-') { | 913 | && global_settings.kbd_file[0] != '-') { |
@@ -1070,6 +1078,16 @@ void settings_reset(void) | |||
1070 | #if defined (HAVE_RECORDING) && CONFIG_CODEC == SWCODEC | 1078 | #if defined (HAVE_RECORDING) && CONFIG_CODEC == SWCODEC |
1071 | enc_global_settings_reset(); | 1079 | enc_global_settings_reset(); |
1072 | #endif | 1080 | #endif |
1081 | #ifdef HAVE_LCD_BITMAP | ||
1082 | FOR_NB_SCREENS(i) | ||
1083 | { | ||
1084 | if (global_status.font_id[i] > FONT_SYSFIXED) | ||
1085 | { | ||
1086 | font_unload(global_status.font_id[i]); | ||
1087 | global_status.font_id[i] = FONT_SYSFIXED; | ||
1088 | } | ||
1089 | } | ||
1090 | #endif | ||
1073 | } | 1091 | } |
1074 | 1092 | ||
1075 | /** Changing setting values **/ | 1093 | /** Changing setting values **/ |
diff --git a/apps/settings.h b/apps/settings.h index d7a72268e6..36e403be1b 100644 --- a/apps/settings.h +++ b/apps/settings.h | |||
@@ -278,6 +278,9 @@ struct system_status | |||
278 | signed char last_screen; | 278 | signed char last_screen; |
279 | int viewer_icon_count; | 279 | int viewer_icon_count; |
280 | int last_volume_change; /* tick the last volume change happened. skins use this */ | 280 | int last_volume_change; /* tick the last volume change happened. skins use this */ |
281 | #ifdef HAVE_LCD_BITMAP | ||
282 | int font_id[NB_SCREENS]; /* font id of the settings font for each screen */ | ||
283 | #endif | ||
281 | }; | 284 | }; |
282 | 285 | ||
283 | struct user_settings | 286 | struct user_settings |
diff --git a/firmware/export/font.h b/firmware/export/font.h index a85f95e6ae..6c9e6163af 100644 --- a/firmware/export/font.h +++ b/firmware/export/font.h | |||
@@ -22,6 +22,7 @@ | |||
22 | #define _FONT_H | 22 | #define _FONT_H |
23 | 23 | ||
24 | #include "inttypes.h" | 24 | #include "inttypes.h" |
25 | #include "stdbool.h" | ||
25 | 26 | ||
26 | /* | 27 | /* |
27 | * Incore font and image definitions | 28 | * Incore font and image definitions |
@@ -46,18 +47,14 @@ | |||
46 | * Fonts are specified in firmware/font.c. | 47 | * Fonts are specified in firmware/font.c. |
47 | */ | 48 | */ |
48 | enum { | 49 | enum { |
49 | FONT_SYSFIXED, /* system fixed pitch font*/ | 50 | FONT_SYSFIXED = -1, /* system fixed pitch font*/ |
50 | FONT_UI, /* system porportional font*/ | 51 | FONT_FIRSTUSERFONT = 0, /* first id for the user fonts */ |
51 | #ifdef HAVE_REMOTE_LCD | ||
52 | FONT_UI_REMOTE, /* UI font for remote LCD */ | ||
53 | #endif | ||
54 | SYSTEMFONTCOUNT, /* Number of fonts reserved for the system and ui */ | ||
55 | FONT_FIRSTUSERFONT = 2 | ||
56 | }; | 52 | }; |
57 | #define MAXUSERFONTS 8 | 53 | #define MAXUSERFONTS 8 |
58 | 54 | ||
59 | /* SYSFONT, FONT_UI, FONT_UI_REMOTE + MAXUSERFONTS fonts in skins */ | 55 | /* SYSFONT, FONT_UI, FONT_UI_REMOTE + MAXUSERFONTS fonts in skins */ |
60 | #define MAXFONTS (SYSTEMFONTCOUNT + MAXUSERFONTS) | 56 | #define MAXFONTS (FONT_FIRSTUSERFONT + MAXUSERFONTS) |
57 | #define FONT_UI MAXFONTS | ||
61 | 58 | ||
62 | /* | 59 | /* |
63 | * .fnt loadable font file format definition | 60 | * .fnt loadable font file format definition |
@@ -105,7 +102,7 @@ struct font { | |||
105 | unsigned char *buffer_start; /* buffer to store the font in */ | 102 | unsigned char *buffer_start; /* buffer to store the font in */ |
106 | unsigned char *buffer_position; /* position in the buffer */ | 103 | unsigned char *buffer_position; /* position in the buffer */ |
107 | unsigned char *buffer_end; /* end of the buffer */ | 104 | unsigned char *buffer_end; /* end of the buffer */ |
108 | int buffer_size; /* size of the buffer in bytes */ | 105 | int buffer_size; /* size of the buffer in bytes */ |
109 | #ifndef __PCTOOL__ | 106 | #ifndef __PCTOOL__ |
110 | struct font_cache cache; | 107 | struct font_cache cache; |
111 | uint32_t file_width_offset; /* offset to file width data */ | 108 | uint32_t file_width_offset; /* offset to file width data */ |
@@ -117,17 +114,13 @@ struct font { | |||
117 | 114 | ||
118 | /* font routines*/ | 115 | /* font routines*/ |
119 | void font_init(void) INIT_ATTR; | 116 | void font_init(void) INIT_ATTR; |
120 | #ifdef HAVE_REMOTE_LCD | 117 | const char* font_filename(int font_id); |
121 | /* Load a font into the special remote ui font slot */ | 118 | int font_load(const char *path); |
122 | int font_load_remoteui(const char* path); | ||
123 | #endif | ||
124 | int font_load(struct font* pf, const char *path); | ||
125 | int font_glyphs_to_bufsize(const char *path, int glyphs); | 119 | int font_glyphs_to_bufsize(const char *path, int glyphs); |
126 | void font_unload(int font_id); | 120 | void font_unload(int font_id); |
127 | 121 | ||
128 | struct font* font_get(int font); | 122 | struct font* font_get(int font); |
129 | 123 | ||
130 | void font_reset(struct font *pf); | ||
131 | int font_getstringsize(const unsigned char *str, int *w, int *h, int fontnumber); | 124 | int font_getstringsize(const unsigned char *str, int *w, int *h, int fontnumber); |
132 | int font_get_width(struct font* ft, unsigned short ch); | 125 | int font_get_width(struct font* ft, unsigned short ch); |
133 | const unsigned char * font_get_bits(struct font* ft, unsigned short ch); | 126 | const unsigned char * font_get_bits(struct font* ft, unsigned short ch); |
diff --git a/firmware/font.c b/firmware/font.c index 0f9f453ae2..fea210a3f1 100644 --- a/firmware/font.c +++ b/firmware/font.c | |||
@@ -34,6 +34,7 @@ | |||
34 | #include "system.h" | 34 | #include "system.h" |
35 | #include "font.h" | 35 | #include "font.h" |
36 | #include "file.h" | 36 | #include "file.h" |
37 | #include "core_alloc.h" | ||
37 | #include "debug.h" | 38 | #include "debug.h" |
38 | #include "panic.h" | 39 | #include "panic.h" |
39 | #include "rbunicode.h" | 40 | #include "rbunicode.h" |
@@ -74,19 +75,58 @@ extern struct font sysfont; | |||
74 | 75 | ||
75 | #ifndef BOOTLOADER | 76 | #ifndef BOOTLOADER |
76 | 77 | ||
77 | /* structure filled in by font_load */ | 78 | struct buflib_alloc_data { |
78 | static struct font font_ui; | 79 | struct font font; |
79 | /* static buffer allocation structures */ | 80 | bool handle_locked; /* is the buflib handle currently locked? */ |
80 | static unsigned char main_buf[MAX_FONT_SIZE] CACHEALIGN_ATTR; | 81 | int refcount; /* how many times has this font been loaded? */ |
81 | #ifdef HAVE_REMOTE_LCD | 82 | unsigned char buffer[MAX_FONT_SIZE]; |
82 | #define REMOTE_FONT_SIZE 10000 | 83 | }; |
83 | static struct font remote_font_ui; | 84 | static int buflib_allocations[MAXFONTS]; |
84 | static unsigned char remote_buf[REMOTE_FONT_SIZE] CACHEALIGN_ATTR; | 85 | static int handle_for_glyphcache; |
85 | #endif | 86 | |
87 | static int buflibmove_callback(int handle, void* current, void* new) | ||
88 | { | ||
89 | (void)handle; | ||
90 | struct buflib_alloc_data *alloc = (struct buflib_alloc_data*)current; | ||
91 | size_t diff = new - current; | ||
92 | |||
93 | if (alloc->handle_locked) | ||
94 | return BUFLIB_CB_CANNOT_MOVE; | ||
95 | |||
96 | alloc->font.bits += diff; | ||
97 | alloc->font.offset += diff; | ||
98 | if (alloc->font.width) | ||
99 | alloc->font.width += diff; | ||
100 | |||
101 | alloc->font.buffer_start += diff; | ||
102 | alloc->font.buffer_end += diff; | ||
103 | alloc->font.buffer_position += diff; | ||
104 | |||
105 | alloc->font.cache._index += diff; | ||
106 | |||
107 | return BUFLIB_CB_OK; | ||
108 | } | ||
109 | static void lock_font_handle(int handle, bool lock) | ||
110 | { | ||
111 | struct buflib_alloc_data *alloc = core_get_data(handle); | ||
112 | alloc->handle_locked = lock; | ||
113 | } | ||
86 | 114 | ||
87 | /* system font table, in order of FONT_xxx definition */ | 115 | static struct buflib_callbacks buflibops = {buflibmove_callback, NULL }; |
88 | static struct font* sysfonts[MAXFONTS] = { &sysfont, &font_ui, NULL}; | ||
89 | 116 | ||
117 | static inline struct font *pf_from_handle(int handle) | ||
118 | { | ||
119 | struct buflib_alloc_data *alloc = core_get_data(handle); | ||
120 | struct font *pf = &alloc->font; | ||
121 | return pf; | ||
122 | } | ||
123 | |||
124 | static inline unsigned char *buffer_from_handle(int handle) | ||
125 | { | ||
126 | struct buflib_alloc_data *alloc = core_get_data(handle); | ||
127 | unsigned char* buffer = alloc->buffer; | ||
128 | return buffer; | ||
129 | } | ||
90 | 130 | ||
91 | /* Font cache structures */ | 131 | /* Font cache structures */ |
92 | static void cache_create(struct font* pf); | 132 | static void cache_create(struct font* pf); |
@@ -95,13 +135,10 @@ static void glyph_cache_load(struct font* pf); | |||
95 | 135 | ||
96 | void font_init(void) | 136 | void font_init(void) |
97 | { | 137 | { |
98 | int i = SYSTEMFONTCOUNT; | 138 | int i = 0; |
99 | while (i<MAXFONTS) | 139 | while (i<MAXFONTS) |
100 | sysfonts[i++] = NULL; | 140 | buflib_allocations[i++] = -1; |
101 | font_reset(NULL); | 141 | handle_for_glyphcache = -1; |
102 | #ifdef HAVE_REMOTE_LCD | ||
103 | font_reset(&remote_font_ui); | ||
104 | #endif | ||
105 | } | 142 | } |
106 | 143 | ||
107 | /* Check if we have x bytes left in the file buffer */ | 144 | /* Check if we have x bytes left in the file buffer */ |
@@ -139,26 +176,6 @@ static int glyph_bytes( struct font *pf, int width ) | |||
139 | width * ((pf->height + 7) / 8); | 176 | width * ((pf->height + 7) / 8); |
140 | } | 177 | } |
141 | 178 | ||
142 | void font_reset(struct font *pf) | ||
143 | { | ||
144 | unsigned char* buffer = NULL; | ||
145 | size_t buf_size = 0; | ||
146 | if (pf == NULL) | ||
147 | pf = &font_ui; | ||
148 | else | ||
149 | { | ||
150 | buffer = pf->buffer_start; | ||
151 | buf_size = pf->buffer_size; | ||
152 | } | ||
153 | memset(pf, 0, sizeof(struct font)); | ||
154 | pf->fd = -1; | ||
155 | if (buffer) | ||
156 | { | ||
157 | pf->buffer_start = buffer; | ||
158 | pf->buffer_size = buf_size; | ||
159 | } | ||
160 | } | ||
161 | |||
162 | static struct font* font_load_header(struct font *pf) | 179 | static struct font* font_load_header(struct font *pf) |
163 | { | 180 | { |
164 | /* Check we have enough data */ | 181 | /* Check we have enough data */ |
@@ -320,18 +337,27 @@ static struct font* font_load_cached(struct font* pf) | |||
320 | return pf; | 337 | return pf; |
321 | } | 338 | } |
322 | 339 | ||
323 | static bool internal_load_font(struct font* pf, const char *path, | 340 | static void font_reset(int font_id) |
341 | { | ||
342 | struct font *pf = pf_from_handle(buflib_allocations[font_id]); | ||
343 | // fixme | ||
344 | memset(pf, 0, sizeof(struct font)); | ||
345 | pf->fd = -1; | ||
346 | } | ||
347 | |||
348 | |||
349 | static bool internal_load_font(int font_id, const char *path, | ||
324 | char *buf, size_t buf_size) | 350 | char *buf, size_t buf_size) |
325 | { | 351 | { |
326 | int size; | 352 | int size; |
327 | 353 | struct font* pf = pf_from_handle(buflib_allocations[font_id]); | |
328 | /* save loaded glyphs */ | 354 | /* save loaded glyphs */ |
329 | glyph_cache_save(pf); | 355 | glyph_cache_save(pf); |
330 | /* Close font file handle */ | 356 | /* Close font file handle */ |
331 | if (pf->fd >= 0) | 357 | if (pf->fd >= 0) |
332 | close(pf->fd); | 358 | close(pf->fd); |
333 | 359 | ||
334 | font_reset(pf); | 360 | font_reset(font_id); |
335 | 361 | ||
336 | /* open and read entire font file*/ | 362 | /* open and read entire font file*/ |
337 | pf->fd = open(path, O_RDONLY|O_BINARY); | 363 | pf->fd = open(path, O_RDONLY|O_BINARY); |
@@ -393,80 +419,117 @@ static bool internal_load_font(struct font* pf, const char *path, | |||
393 | return true; | 419 | return true; |
394 | } | 420 | } |
395 | 421 | ||
396 | #ifdef HAVE_REMOTE_LCD | 422 | static int find_font_index(const char* path) |
397 | /* Load a font into the special remote ui font slot */ | ||
398 | int font_load_remoteui(const char* path) | ||
399 | { | 423 | { |
400 | struct font* pf = &remote_font_ui; | 424 | int index = 0, handle; |
401 | if (!path) | 425 | |
402 | { | 426 | while (index < MAXFONTS) |
403 | if (sysfonts[FONT_UI_REMOTE] && sysfonts[FONT_UI_REMOTE] != sysfonts[FONT_UI]) | ||
404 | font_unload(FONT_UI_REMOTE); | ||
405 | sysfonts[FONT_UI_REMOTE] = NULL; | ||
406 | return FONT_UI; | ||
407 | } | ||
408 | if (!internal_load_font(pf, path, remote_buf, REMOTE_FONT_SIZE)) | ||
409 | { | 427 | { |
410 | sysfonts[FONT_UI_REMOTE] = NULL; | 428 | handle = buflib_allocations[index]; |
411 | return -1; | 429 | if (handle > 0 && !strcmp(core_get_name(handle), path)) |
430 | return index; | ||
431 | index++; | ||
412 | } | 432 | } |
413 | 433 | return FONT_SYSFIXED; | |
414 | sysfonts[FONT_UI_REMOTE] = pf; | ||
415 | return FONT_UI_REMOTE; | ||
416 | } | 434 | } |
417 | #endif | ||
418 | 435 | ||
436 | static int alloc_and_init(int font_idx, const char* name) | ||
437 | { | ||
438 | int *phandle = &buflib_allocations[font_idx]; | ||
439 | int handle = *phandle; | ||
440 | struct buflib_alloc_data *pdata; | ||
441 | struct font *pf; | ||
442 | if (handle > 0) | ||
443 | return handle; | ||
444 | *phandle = core_alloc_ex(name, sizeof(struct buflib_alloc_data), &buflibops); | ||
445 | handle = *phandle; | ||
446 | if (handle < 0) | ||
447 | return handle; | ||
448 | pdata = core_get_data(handle); | ||
449 | pf = &pdata->font; | ||
450 | font_reset(font_idx); | ||
451 | pdata->handle_locked = false; | ||
452 | pdata->refcount = 1; | ||
453 | pf->buffer_position = pf->buffer_start = buffer_from_handle(handle); | ||
454 | pf->buffer_size = MAX_FONT_SIZE; | ||
455 | return handle; | ||
456 | } | ||
457 | |||
458 | const char* font_filename(int font_id) | ||
459 | { | ||
460 | int handle = buflib_allocations[font_id]; | ||
461 | if (handle > 0) | ||
462 | return core_get_name(handle); | ||
463 | return NULL; | ||
464 | } | ||
465 | |||
419 | /* read and load font into incore font structure, | 466 | /* read and load font into incore font structure, |
420 | * returns the font number on success, -1 on failure */ | 467 | * returns the font number on success, -1 on failure */ |
421 | int font_load(struct font* pf, const char *path) | 468 | int font_load(const char *path) |
422 | { | 469 | { |
423 | int font_id = -1; | 470 | int font_id = find_font_index(path); |
424 | char *buffer; | 471 | char *buffer; |
425 | size_t buffer_size; | 472 | size_t buffer_size; |
426 | if (pf == NULL) | 473 | int *handle; |
474 | |||
475 | if (font_id > FONT_SYSFIXED) | ||
427 | { | 476 | { |
428 | pf = &font_ui; | 477 | /* already loaded, no need to reload */ |
429 | font_id = FONT_UI; | 478 | struct buflib_alloc_data *pd = core_get_data(buflib_allocations[font_id]); |
479 | pd->refcount++; | ||
480 | //printf("reusing handle %d for %s (count: %d)\n", font_id, path, pd->refcount); | ||
481 | return font_id; | ||
430 | } | 482 | } |
431 | else | 483 | |
484 | for (font_id = FONT_FIRSTUSERFONT; font_id < MAXFONTS; font_id++) | ||
432 | { | 485 | { |
433 | for (font_id = SYSTEMFONTCOUNT; font_id < MAXFONTS; font_id++) | 486 | handle = &buflib_allocations[font_id]; |
487 | if (*handle < 0) | ||
434 | { | 488 | { |
435 | if (sysfonts[font_id] == NULL) | 489 | break; |
436 | break; | ||
437 | } | 490 | } |
438 | if (font_id == MAXFONTS) | ||
439 | return -1; /* too many fonts */ | ||
440 | } | 491 | } |
441 | 492 | handle = &buflib_allocations[font_id]; | |
442 | if (font_id == FONT_UI) | 493 | *handle = alloc_and_init(font_id, path); |
443 | { | 494 | if (*handle < 0) |
444 | /* currently, font loading replaces earlier font allocation*/ | 495 | return -1; |
445 | buffer = (unsigned char *)(((intptr_t)main_buf + 3) & ~3); | 496 | |
446 | /* make sure above doesn't exceed */ | 497 | if (handle_for_glyphcache < 0) |
447 | buffer_size = MAX_FONT_SIZE-3; | 498 | handle_for_glyphcache = *handle; |
448 | } | 499 | |
449 | else | 500 | buffer = buffer_from_handle(*handle); |
501 | buffer_size = MAX_FONT_SIZE; //FIXME | ||
502 | lock_font_handle(*handle, true); | ||
503 | |||
504 | if (!internal_load_font(font_id, path, buffer, buffer_size)) | ||
450 | { | 505 | { |
451 | buffer = pf->buffer_start; | 506 | lock_font_handle(*handle, false); |
452 | buffer_size = pf->buffer_size; | 507 | core_free(*handle); |
453 | } | 508 | *handle = -1; |
454 | |||
455 | if (!internal_load_font(pf, path, buffer, buffer_size)) | ||
456 | return -1; | 509 | return -1; |
510 | } | ||
457 | 511 | ||
458 | sysfonts[font_id] = pf; | 512 | lock_font_handle(*handle, false); |
513 | //printf("%s -> [%d] -> %d\n", path, font_id, *handle); | ||
459 | return font_id; /* success!*/ | 514 | return font_id; /* success!*/ |
460 | } | 515 | } |
461 | 516 | ||
462 | void font_unload(int font_id) | 517 | void font_unload(int font_id) |
463 | { | 518 | { |
464 | struct font* pf = sysfonts[font_id]; | 519 | int *handle = &buflib_allocations[font_id]; |
465 | if (font_id >= SYSTEMFONTCOUNT && pf) | 520 | struct buflib_alloc_data *pdata = core_get_data(*handle); |
521 | struct font* pf = &pdata->font; | ||
522 | pdata->refcount--; | ||
523 | if (pdata->refcount < 1) | ||
466 | { | 524 | { |
467 | if (pf->fd >= 0) | 525 | //printf("freeing id: %d %s\n", font_id, core_get_name(*handle)); |
526 | if (pf && pf->fd >= 0) | ||
468 | close(pf->fd); | 527 | close(pf->fd); |
469 | sysfonts[font_id] = NULL; | 528 | if (*handle > 0) |
529 | core_free(*handle); | ||
530 | if (handle_for_glyphcache == *handle) | ||
531 | handle_for_glyphcache = -1; // should find the next available handle | ||
532 | *handle = -1; | ||
470 | } | 533 | } |
471 | } | 534 | } |
472 | 535 | ||
@@ -478,14 +541,35 @@ void font_unload(int font_id) | |||
478 | struct font* font_get(int font) | 541 | struct font* font_get(int font) |
479 | { | 542 | { |
480 | struct font* pf; | 543 | struct font* pf; |
544 | if (font == FONT_UI) | ||
545 | font = MAXFONTS-1; | ||
546 | if (font <= FONT_SYSFIXED) | ||
547 | return &sysfont; | ||
481 | 548 | ||
482 | while (1) { | 549 | while (1) { |
483 | pf = sysfonts[font]; | 550 | struct buflib_alloc_data *alloc = core_get_data(buflib_allocations[font]); |
551 | pf = &alloc->font; | ||
484 | if (pf && pf->height) | 552 | if (pf && pf->height) |
485 | return pf; | 553 | return pf; |
486 | if (--font < 0) | 554 | if (--font < 0) |
487 | panicf("No font!"); | 555 | return &sysfont; |
556 | } | ||
557 | } | ||
558 | |||
559 | static int pf_to_handle(struct font* pf) | ||
560 | { | ||
561 | int i; | ||
562 | for (i=0; i<MAXFONTS; i++) | ||
563 | { | ||
564 | int handle = buflib_allocations[i]; | ||
565 | if (handle > 0) | ||
566 | { | ||
567 | struct buflib_alloc_data *pdata = core_get_data(handle); | ||
568 | if (pf == &pdata->font) | ||
569 | return handle; | ||
570 | } | ||
488 | } | 571 | } |
572 | return -1; | ||
489 | } | 573 | } |
490 | 574 | ||
491 | /* | 575 | /* |
@@ -495,9 +579,12 @@ static void | |||
495 | load_cache_entry(struct font_cache_entry* p, void* callback_data) | 579 | load_cache_entry(struct font_cache_entry* p, void* callback_data) |
496 | { | 580 | { |
497 | struct font* pf = callback_data; | 581 | struct font* pf = callback_data; |
582 | int handle = pf_to_handle(pf); | ||
498 | unsigned short char_code = p->_char_code; | 583 | unsigned short char_code = p->_char_code; |
499 | unsigned char tmp[2]; | 584 | unsigned char tmp[2]; |
500 | 585 | ||
586 | if (handle > 0) | ||
587 | lock_font_handle(handle, true); | ||
501 | if (pf->file_width_offset) | 588 | if (pf->file_width_offset) |
502 | { | 589 | { |
503 | int width_offset = pf->file_width_offset + char_code; | 590 | int width_offset = pf->file_width_offset + char_code; |
@@ -531,6 +618,9 @@ load_cache_entry(struct font_cache_entry* p, void* callback_data) | |||
531 | lseek(pf->fd, file_offset, SEEK_SET); | 618 | lseek(pf->fd, file_offset, SEEK_SET); |
532 | int src_bytes = glyph_bytes(pf, p->width); | 619 | int src_bytes = glyph_bytes(pf, p->width); |
533 | read(pf->fd, p->bitmap, src_bytes); | 620 | read(pf->fd, p->bitmap, src_bytes); |
621 | |||
622 | if (handle > 0) | ||
623 | lock_font_handle(handle, false); | ||
534 | } | 624 | } |
535 | 625 | ||
536 | /* | 626 | /* |
@@ -572,7 +662,7 @@ const unsigned char* font_get_bits(struct font* pf, unsigned short char_code) | |||
572 | if (pf->fd >= 0 && pf != &sysfont) | 662 | if (pf->fd >= 0 && pf != &sysfont) |
573 | { | 663 | { |
574 | bits = | 664 | bits = |
575 | (unsigned char*)font_cache_get(&pf->cache,char_code,load_cache_entry,pf)->bitmap; | 665 | (unsigned char*)font_cache_get(&pf->cache,char_code,load_cache_entry, pf)->bitmap; |
576 | } | 666 | } |
577 | else | 667 | else |
578 | { | 668 | { |
@@ -594,7 +684,8 @@ static int cache_fd; | |||
594 | static void glyph_file_write(void* data) | 684 | static void glyph_file_write(void* data) |
595 | { | 685 | { |
596 | struct font_cache_entry* p = data; | 686 | struct font_cache_entry* p = data; |
597 | struct font* pf = &font_ui; | 687 | int handle = handle_for_glyphcache; |
688 | struct font* pf = pf_from_handle(handle); | ||
598 | unsigned short ch; | 689 | unsigned short ch; |
599 | unsigned char tmp[2]; | 690 | unsigned char tmp[2]; |
600 | 691 | ||
@@ -617,9 +708,9 @@ static void glyph_file_write(void* data) | |||
617 | /* save the char codes of the loaded glyphs to a file */ | 708 | /* save the char codes of the loaded glyphs to a file */ |
618 | void glyph_cache_save(struct font* pf) | 709 | void glyph_cache_save(struct font* pf) |
619 | { | 710 | { |
620 | if (!pf) | 711 | if (pf != pf_from_handle(handle_for_glyphcache)) |
621 | pf = &font_ui; | 712 | return; |
622 | if (pf->fd >= 0 && pf == &font_ui) | 713 | if (pf->fd >= 0) |
623 | { | 714 | { |
624 | cache_fd = open(GLYPH_CACHE_FILE, O_WRONLY|O_CREAT|O_TRUNC, 0666); | 715 | cache_fd = open(GLYPH_CACHE_FILE, O_WRONLY|O_CREAT|O_TRUNC, 0666); |
625 | if (cache_fd < 0) | 716 | if (cache_fd < 0) |
@@ -675,9 +766,10 @@ static int ushortcmp(const void *a, const void *b) | |||
675 | } | 766 | } |
676 | static void glyph_cache_load(struct font* pf) | 767 | static void glyph_cache_load(struct font* pf) |
677 | { | 768 | { |
678 | 769 | if (handle_for_glyphcache <= 0) | |
770 | return; | ||
679 | #define MAX_SORT 256 | 771 | #define MAX_SORT 256 |
680 | if (pf->fd >= 0) { | 772 | if (pf->fd >= 0 && pf == pf_from_handle(handle_for_glyphcache)) { |
681 | int fd; | 773 | int fd; |
682 | int i, size; | 774 | int i, size; |
683 | unsigned char tmp[2]; | 775 | unsigned char tmp[2]; |
diff --git a/firmware/include/core_alloc.h b/firmware/include/core_alloc.h index f5206c9db9..b2edec5377 100644 --- a/firmware/include/core_alloc.h +++ b/firmware/include/core_alloc.h | |||
@@ -33,4 +33,11 @@ static inline void* core_get_data(int handle) | |||
33 | extern struct buflib_context core_ctx; | 33 | extern struct buflib_context core_ctx; |
34 | return buflib_get_data(&core_ctx, handle); | 34 | return buflib_get_data(&core_ctx, handle); |
35 | } | 35 | } |
36 | |||
37 | static inline const char* core_get_name(int handle) | ||
38 | { | ||
39 | extern struct buflib_context core_ctx; | ||
40 | return buflib_get_name(&core_ctx, handle); | ||
41 | } | ||
42 | |||
36 | #endif /* __CORE_ALLOC_H__ */ | 43 | #endif /* __CORE_ALLOC_H__ */ |