diff options
author | Jonathan Gordon <rockbox@jdgordon.info> | 2010-02-14 06:26:16 +0000 |
---|---|---|
committer | Jonathan Gordon <rockbox@jdgordon.info> | 2010-02-14 06:26:16 +0000 |
commit | 1c2aa35371aed8d895b3448dad865b913da57cfb (patch) | |
tree | 8a790ad8efe5d0abd73eaf77adc854d336ce0ef4 /apps/gui | |
parent | ed21ab1c8c9b16ec62933313c3d36a93d9255f62 (diff) | |
download | rockbox-1c2aa35371aed8d895b3448dad865b913da57cfb.tar.gz rockbox-1c2aa35371aed8d895b3448dad865b913da57cfb.zip |
FS#10984 - multifont! 2 major additions:
1) seperate UI font for the remote and main displays
2) allow individual skins to load additional fonts for use in the skin (Uo to 7 extra in this first version) see CustomWPS for info on how to load a font in the skins.
Code should always use FONT_UI+screen_number to get the correct user font
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@24644 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/gui')
-rw-r--r-- | apps/gui/skin_engine/skin_fonts.c | 139 | ||||
-rw-r--r-- | apps/gui/skin_engine/skin_fonts.h | 46 | ||||
-rw-r--r-- | apps/gui/skin_engine/skin_parser.c | 40 | ||||
-rw-r--r-- | apps/gui/statusbar-skinned.c | 4 | ||||
-rw-r--r-- | apps/gui/viewport.c | 16 |
5 files changed, 237 insertions, 8 deletions
diff --git a/apps/gui/skin_engine/skin_fonts.c b/apps/gui/skin_engine/skin_fonts.c new file mode 100644 index 0000000000..1d3ef84271 --- /dev/null +++ b/apps/gui/skin_engine/skin_fonts.c | |||
@@ -0,0 +1,139 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id: skin_tokens.c 24526 2010-02-05 23:58:53Z jdgordon $ | ||
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 | #define FONT_SIZE 10000 | ||
33 | |||
34 | |||
35 | static struct skin_font { | ||
36 | struct font font; | ||
37 | int font_id; | ||
38 | char name[MAX_PATH]; | ||
39 | char *buffer; | ||
40 | int ref_count; /* how many times has this font been loaded? */ | ||
41 | } font_table[MAXUSERFONTS]; | ||
42 | |||
43 | /* need this to know if we should be closing font fd's on the next init */ | ||
44 | static bool first_load = true; | ||
45 | |||
46 | void skin_font_init(void) | ||
47 | { | ||
48 | int i; | ||
49 | for(i=0;i<MAXUSERFONTS;i++) | ||
50 | { | ||
51 | if (!first_load) | ||
52 | font_unload(font_table[i].font_id); | ||
53 | font_table[i].font_id = -1; | ||
54 | font_table[i].name[0] = '\0'; | ||
55 | font_table[i].buffer = NULL; | ||
56 | font_table[i].ref_count = 0; | ||
57 | } | ||
58 | } | ||
59 | |||
60 | /* load a font into the skin buffer. return the font id. */ | ||
61 | int skin_font_load(char* font_name) | ||
62 | { | ||
63 | int i; | ||
64 | struct font *pf; | ||
65 | struct skin_font *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 | for(i=0;i<MAXUSERFONTS;i++) | ||
75 | { | ||
76 | if (font_table[i].font_id >= 0 && !strcmp(font_table[i].name, font_name)) | ||
77 | { | ||
78 | font_table[i].ref_count++; | ||
79 | return font_table[i].font_id; | ||
80 | } | ||
81 | else if (!font && font_table[i].font_id == -1) | ||
82 | { | ||
83 | font = &font_table[i]; | ||
84 | } | ||
85 | } | ||
86 | if (!font) | ||
87 | return -1; /* too many fonts loaded */ | ||
88 | |||
89 | pf = &font->font; | ||
90 | if (!font->buffer) | ||
91 | { | ||
92 | pf->buffer_start = skin_buffer_alloc(FONT_SIZE); | ||
93 | if (!pf->buffer_start) | ||
94 | return -1; | ||
95 | font->buffer = pf->buffer_start; | ||
96 | } | ||
97 | else | ||
98 | { | ||
99 | pf->buffer_start = font->buffer; | ||
100 | } | ||
101 | pf->buffer_size = FONT_SIZE; | ||
102 | |||
103 | snprintf(filename, MAX_PATH, FONT_DIR "/%s.fnt", font_name); | ||
104 | strcpy(font->name, font_name); | ||
105 | |||
106 | pf->fd = -1; | ||
107 | font->font_id = font_load(pf, filename); | ||
108 | |||
109 | if (font->font_id < 0) | ||
110 | return -1; | ||
111 | font->ref_count = 1; | ||
112 | |||
113 | return font->font_id; | ||
114 | } | ||
115 | |||
116 | /* unload a skin font. If a font has been loaded more than once it wont actually | ||
117 | * be unloaded untill all references have been unloaded */ | ||
118 | void skin_font_unload(int font_id) | ||
119 | { | ||
120 | int i; | ||
121 | for(i=0;i<MAXUSERFONTS;i++) | ||
122 | { | ||
123 | if (font_table[i].font_id == font_id) | ||
124 | { | ||
125 | if (--font_table[i].ref_count == 0) | ||
126 | { | ||
127 | font_unload(font_id); | ||
128 | font_table[i].font_id = -1; | ||
129 | font_table[i].name[0] = '\0'; | ||
130 | } | ||
131 | return; | ||
132 | } | ||
133 | } | ||
134 | } | ||
135 | |||
136 | |||
137 | |||
138 | |||
139 | |||
diff --git a/apps/gui/skin_engine/skin_fonts.h b/apps/gui/skin_engine/skin_fonts.h new file mode 100644 index 0000000000..3b43012de3 --- /dev/null +++ b/apps/gui/skin_engine/skin_fonts.h | |||
@@ -0,0 +1,46 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id: skin_tokens.c 24526 2010-02-05 23:58:53Z jdgordon $ | ||
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 | |||
32 | #ifndef _SKINFONTS_H_ | ||
33 | #define _SKINFONTS_H_ | ||
34 | |||
35 | #define MAXUSERFONTS (MAXFONTS - SYSTEMFONTCOUNT) | ||
36 | |||
37 | void skin_font_init(void); | ||
38 | |||
39 | /* load a font into the skin buffer. return the font id. */ | ||
40 | int skin_font_load(char* font_name); | ||
41 | |||
42 | /* unload a skin font. If a font has been loaded more than once it wont actually | ||
43 | * be unloaded untill all references have been unloaded */ | ||
44 | void skin_font_unload(int font_id); | ||
45 | |||
46 | #endif | ||
diff --git a/apps/gui/skin_engine/skin_parser.c b/apps/gui/skin_engine/skin_parser.c index 4655bf0dff..034ff532f0 100644 --- a/apps/gui/skin_engine/skin_parser.c +++ b/apps/gui/skin_engine/skin_parser.c | |||
@@ -52,6 +52,7 @@ | |||
52 | #include "skin_engine.h" | 52 | #include "skin_engine.h" |
53 | #include "settings.h" | 53 | #include "settings.h" |
54 | #include "settings_list.h" | 54 | #include "settings_list.h" |
55 | #include "skin_fonts.h" | ||
55 | 56 | ||
56 | #ifdef HAVE_LCD_BITMAP | 57 | #ifdef HAVE_LCD_BITMAP |
57 | #include "bmp.h" | 58 | #include "bmp.h" |
@@ -157,6 +158,8 @@ static int parse_image_display(const char *wps_bufptr, | |||
157 | struct wps_token *token, struct wps_data *wps_data); | 158 | struct wps_token *token, struct wps_data *wps_data); |
158 | static int parse_image_load(const char *wps_bufptr, | 159 | static int parse_image_load(const char *wps_bufptr, |
159 | struct wps_token *token, struct wps_data *wps_data); | 160 | struct wps_token *token, struct wps_data *wps_data); |
161 | static int parse_font_load(const char *wps_bufptr, | ||
162 | struct wps_token *token, struct wps_data *wps_data); | ||
160 | #endif /*HAVE_LCD_BITMAP */ | 163 | #endif /*HAVE_LCD_BITMAP */ |
161 | #if (LCD_DEPTH > 1) || (defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)) | 164 | #if (LCD_DEPTH > 1) || (defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)) |
162 | static int parse_image_special(const char *wps_bufptr, | 165 | static int parse_image_special(const char *wps_bufptr, |
@@ -353,6 +356,7 @@ static const struct wps_tag all_tags[] = { | |||
353 | parse_image_display }, | 356 | parse_image_display }, |
354 | 357 | ||
355 | { WPS_TOKEN_IMAGE_DISPLAY, "x", 0, parse_image_load }, | 358 | { WPS_TOKEN_IMAGE_DISPLAY, "x", 0, parse_image_load }, |
359 | { WPS_NO_TOKEN, "Fl", 0, parse_font_load }, | ||
356 | #ifdef HAVE_ALBUMART | 360 | #ifdef HAVE_ALBUMART |
357 | { WPS_NO_TOKEN, "Cl", 0, parse_albumart_load }, | 361 | { WPS_NO_TOKEN, "Cl", 0, parse_albumart_load }, |
358 | { WPS_TOKEN_ALBUMART_DISPLAY, "C", WPS_REFRESH_STATIC, parse_albumart_display }, | 362 | { WPS_TOKEN_ALBUMART_DISPLAY, "C", WPS_REFRESH_STATIC, parse_albumart_display }, |
@@ -688,6 +692,39 @@ static int parse_image_load(const char *wps_bufptr, | |||
688 | return skip_end_of_line(wps_bufptr); | 692 | return skip_end_of_line(wps_bufptr); |
689 | } | 693 | } |
690 | 694 | ||
695 | static int font_ids[MAXUSERFONTS]; | ||
696 | static int parse_font_load(const char *wps_bufptr, | ||
697 | struct wps_token *token, struct wps_data *wps_data) | ||
698 | { | ||
699 | (void)wps_data; (void)token; | ||
700 | const char *ptr = wps_bufptr; | ||
701 | int id; | ||
702 | char *filename, buf[MAX_PATH]; | ||
703 | |||
704 | if (*ptr != '|') | ||
705 | return WPS_ERROR_INVALID_PARAM; | ||
706 | |||
707 | ptr++; | ||
708 | |||
709 | if (!(ptr = parse_list("ds", NULL, '|', ptr, &id, &filename))) | ||
710 | return WPS_ERROR_INVALID_PARAM; | ||
711 | |||
712 | /* Check there is a terminating | */ | ||
713 | if (*ptr != '|') | ||
714 | return WPS_ERROR_INVALID_PARAM; | ||
715 | |||
716 | if (id <= FONT_UI || id >= MAXFONTS-1) | ||
717 | return WPS_ERROR_INVALID_PARAM; | ||
718 | id -= SYSTEMFONTCOUNT; | ||
719 | |||
720 | memcpy(buf, filename, ptr-filename); | ||
721 | buf[ptr-filename] = '\0'; | ||
722 | font_ids[id] = skin_font_load(buf); | ||
723 | |||
724 | return font_ids[id] >= 0 ? skip_end_of_line(wps_bufptr) : WPS_ERROR_INVALID_PARAM; | ||
725 | } | ||
726 | |||
727 | |||
691 | static int parse_viewport_display(const char *wps_bufptr, | 728 | static int parse_viewport_display(const char *wps_bufptr, |
692 | struct wps_token *token, | 729 | struct wps_token *token, |
693 | struct wps_data *wps_data) | 730 | struct wps_data *wps_data) |
@@ -890,7 +927,8 @@ static int parse_viewport(const char *wps_bufptr, | |||
890 | else | 927 | else |
891 | vp->flags &= ~VP_FLAG_ALIGN_RIGHT; /* ignore right-to-left languages */ | 928 | vp->flags &= ~VP_FLAG_ALIGN_RIGHT; /* ignore right-to-left languages */ |
892 | 929 | ||
893 | 930 | if (vp->font >= SYSTEMFONTCOUNT) | |
931 | vp->font = font_ids[vp->font - SYSTEMFONTCOUNT]; | ||
894 | 932 | ||
895 | struct skin_token_list *list = new_skin_token_list_item(NULL, skin_vp); | 933 | struct skin_token_list *list = new_skin_token_list_item(NULL, skin_vp); |
896 | if (!list) | 934 | if (!list) |
diff --git a/apps/gui/statusbar-skinned.c b/apps/gui/statusbar-skinned.c index 9d447f62db..fac6756aec 100644 --- a/apps/gui/statusbar-skinned.c +++ b/apps/gui/statusbar-skinned.c | |||
@@ -32,6 +32,7 @@ | |||
32 | #include "statusbar.h" | 32 | #include "statusbar.h" |
33 | #include "statusbar-skinned.h" | 33 | #include "statusbar-skinned.h" |
34 | #include "debug.h" | 34 | #include "debug.h" |
35 | #include "font.h" | ||
35 | 36 | ||
36 | 37 | ||
37 | /* currently only one wps_state is needed */ | 38 | /* currently only one wps_state is needed */ |
@@ -183,7 +184,8 @@ void sb_create_from_settings(enum screen_type screen) | |||
183 | default: | 184 | default: |
184 | height = screens[screen].lcdheight; | 185 | height = screens[screen].lcdheight; |
185 | } | 186 | } |
186 | len = snprintf(ptr, remaining, "%%ax%%Vi|0|%d|-|%d|1|-|-|\n", y, height); | 187 | len = snprintf(ptr, remaining, "%%ax%%Vi|0|%d|-|%d|%d|-|-|\n", |
188 | y, height, FONT_UI + screen); | ||
187 | } | 189 | } |
188 | sb_skin_data_load(screen, buf, false); | 190 | sb_skin_data_load(screen, buf, false); |
189 | } | 191 | } |
diff --git a/apps/gui/viewport.c b/apps/gui/viewport.c index eaee2cc8a5..ee233b9c46 100644 --- a/apps/gui/viewport.c +++ b/apps/gui/viewport.c | |||
@@ -315,7 +315,7 @@ void viewport_set_fullscreen(struct viewport *vp, | |||
315 | #ifndef __PCTOOL__ | 315 | #ifndef __PCTOOL__ |
316 | set_default_align_flags(vp); | 316 | set_default_align_flags(vp); |
317 | #endif | 317 | #endif |
318 | vp->font = FONT_UI; /* default to UI to discourage SYSFONT use */ | 318 | vp->font = FONT_UI + screen; /* default to UI to discourage SYSFONT use */ |
319 | vp->drawmode = DRMODE_SOLID; | 319 | vp->drawmode = DRMODE_SOLID; |
320 | #if LCD_DEPTH > 1 | 320 | #if LCD_DEPTH > 1 |
321 | #ifdef HAVE_REMOTE_LCD | 321 | #ifdef HAVE_REMOTE_LCD |
@@ -453,11 +453,15 @@ const char* viewport_parse_viewport(struct viewport *vp, | |||
453 | return NULL; | 453 | return NULL; |
454 | } | 454 | } |
455 | 455 | ||
456 | /* Default to using the user font if the font was an invalid number or '-'*/ | 456 | /* Default to using the user font if the font was an invalid number or '-' |
457 | if (((vp->font != FONT_SYSFIXED) && (vp->font != FONT_UI)) | 457 | * font 1 is *always* the UI font for the current screen |
458 | || !LIST_VALUE_PARSED(set, PL_FONT) | 458 | * 2 is always the first extra font */ |
459 | ) | 459 | if (!LIST_VALUE_PARSED(set, PL_FONT)) |
460 | vp->font = FONT_UI; | 460 | vp->font = FONT_UI + screen; |
461 | #ifdef HAVE_REMOTE_LCD | ||
462 | else if (vp->font == FONT_UI && screen == SCREEN_REMOTE) | ||
463 | vp->font = FONT_UI_REMOTE; | ||
464 | #endif | ||
461 | 465 | ||
462 | /* Set the defaults for fields not user-specified */ | 466 | /* Set the defaults for fields not user-specified */ |
463 | vp->drawmode = DRMODE_SOLID; | 467 | vp->drawmode = DRMODE_SOLID; |