summaryrefslogtreecommitdiff
path: root/apps/gui/skin_engine/skin_parser.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/gui/skin_engine/skin_parser.c')
-rw-r--r--apps/gui/skin_engine/skin_parser.c109
1 files changed, 95 insertions, 14 deletions
diff --git a/apps/gui/skin_engine/skin_parser.c b/apps/gui/skin_engine/skin_parser.c
index 7fbf63bfeb..8f802a12a4 100644
--- a/apps/gui/skin_engine/skin_parser.c
+++ b/apps/gui/skin_engine/skin_parser.c
@@ -430,6 +430,19 @@ struct gui_img* find_image(char label, struct wps_data *data)
430 } 430 }
431 return NULL; 431 return NULL;
432} 432}
433
434struct skin_font* find_font(int id, struct wps_data *data)
435{
436 struct skin_token_list *list = data->fonts;
437 while (list)
438 {
439 struct skin_font *f = (struct skin_font*)list->token->value.data;
440 if (f->id == id)
441 return f;
442 list = list->next;
443 }
444 return NULL;
445}
433#endif 446#endif
434 447
435/* traverse the viewport linked list for a viewport */ 448/* traverse the viewport linked list for a viewport */
@@ -696,14 +709,14 @@ static int parse_image_load(const char *wps_bufptr,
696/* this array acts as a simple mapping between the id the user uses for a font 709/* this array acts as a simple mapping between the id the user uses for a font
697 * and the id the font actually gets from the font loader. 710 * and the id the font actually gets from the font loader.
698 * font id 2 is always the first skin font (regardless of how many screens */ 711 * font id 2 is always the first skin font (regardless of how many screens */
699static int font_ids[MAXUSERFONTS];
700static int parse_font_load(const char *wps_bufptr, 712static int parse_font_load(const char *wps_bufptr,
701 struct wps_token *token, struct wps_data *wps_data) 713 struct wps_token *token, struct wps_data *wps_data)
702{ 714{
703 (void)wps_data; (void)token; 715 (void)wps_data; (void)token;
704 const char *ptr = wps_bufptr; 716 const char *ptr = wps_bufptr;
705 int id; 717 int id;
706 char *filename, buf[MAX_PATH]; 718 char *filename;
719 struct skin_font *font;
707 720
708 if (*ptr != '|') 721 if (*ptr != '|')
709 return WPS_ERROR_INVALID_PARAM; 722 return WPS_ERROR_INVALID_PARAM;
@@ -719,13 +732,25 @@ static int parse_font_load(const char *wps_bufptr,
719 732
720 if (id <= FONT_UI || id >= MAXFONTS-1) 733 if (id <= FONT_UI || id >= MAXFONTS-1)
721 return WPS_ERROR_INVALID_PARAM; 734 return WPS_ERROR_INVALID_PARAM;
722 id -= FONT_UI; 735
723 736 font = skin_buffer_alloc(sizeof(struct skin_font));
724 memcpy(buf, filename, ptr-filename); 737 int len = ptr-filename+1;
725 buf[ptr-filename] = '\0'; 738 char* name = skin_buffer_alloc(len);
726 font_ids[id] = skin_font_load(buf); 739 if (!font || !name)
727 740 return WPS_ERROR_INVALID_PARAM;
728 return font_ids[id] >= 0 ? skip_end_of_line(wps_bufptr) : WPS_ERROR_INVALID_PARAM; 741
742 strlcpy(name, filename, len);
743 font->id = id;
744 font->font_id = -1;
745 font->name = name;
746
747 struct skin_token_list *item = new_skin_token_list_item(NULL, font);
748
749 if (!item)
750 return WPS_ERROR_INVALID_PARAM;
751 add_to_ll_chain(&wps_data->fonts, item);
752
753 return skip_end_of_line(wps_bufptr);
729} 754}
730 755
731 756
@@ -931,13 +956,13 @@ static int parse_viewport(const char *wps_bufptr,
931 else 956 else
932 vp->flags &= ~VP_FLAG_ALIGN_RIGHT; /* ignore right-to-left languages */ 957 vp->flags &= ~VP_FLAG_ALIGN_RIGHT; /* ignore right-to-left languages */
933 958
959 /* increment because font=2 and FONT_UI_REMOTE is ambiguous */
960 if (vp->font > FONT_UI)
961 vp->font++;
934#ifdef HAVE_REMOTE_LCD 962#ifdef HAVE_REMOTE_LCD
935 if (vp->font == FONT_UI && curr_screen == SCREEN_REMOTE) 963 if (vp->font == FONT_UI && curr_screen == SCREEN_REMOTE)
936 vp->font = FONT_UI_REMOTE; 964 vp->font = FONT_UI_REMOTE;
937 else
938#endif 965#endif
939 if (vp->font > FONT_UI)
940 vp->font = font_ids[vp->font - FONT_UI];
941 966
942 struct skin_token_list *list = new_skin_token_list_item(NULL, skin_vp); 967 struct skin_token_list *list = new_skin_token_list_item(NULL, skin_vp);
943 if (!list) 968 if (!list)
@@ -1949,8 +1974,7 @@ static bool wps_parse(struct wps_data *data, const char *wps_bufptr, bool debug)
1949static void skin_data_reset(struct wps_data *wps_data) 1974static void skin_data_reset(struct wps_data *wps_data)
1950{ 1975{
1951#ifdef HAVE_LCD_BITMAP 1976#ifdef HAVE_LCD_BITMAP
1952 wps_data->images = NULL; 1977 wps_data->images = wps_data->progressbars = wps_data->fonts = NULL;
1953 wps_data->progressbars = NULL;
1954#endif 1978#endif
1955#if LCD_DEPTH > 1 || defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1 1979#if LCD_DEPTH > 1 || defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
1956 wps_data->backdrop = NULL; 1980 wps_data->backdrop = NULL;
@@ -2073,6 +2097,57 @@ static bool load_skin_bitmaps(struct wps_data *wps_data, char *bmpdir)
2073 return retval; 2097 return retval;
2074} 2098}
2075 2099
2100static bool skin_load_fonts(struct wps_data *data)
2101{
2102 /* don't spit out after the first failue to aid debugging */
2103 bool success = true;
2104 struct skin_token_list *vp_list;
2105 /* walk though each viewport and assign its font */
2106 for(vp_list = data->viewports; vp_list; vp_list = vp_list->next)
2107 {
2108 /* first, find the viewports that have a non-sys/ui-font font */
2109 struct skin_viewport *skin_vp =
2110 (struct skin_viewport*)vp_list->token->value.data;
2111 struct viewport *vp = &skin_vp->vp;
2112
2113
2114 if (vp->font < SYSTEMFONTCOUNT)
2115 { /* the usual case -> built-in fonts */
2116 continue;
2117 }
2118
2119 /* decrement, because font has been incremented in viewport parsing
2120 * due to the FONT_UI_REMOTE ambiguity */
2121 int skin_font_id = vp->font-1;
2122
2123 /* now find the corresponding skin_font */
2124 struct skin_font *font = find_font(skin_font_id, data);
2125 if (!font)
2126 {
2127 DEBUGF("Could not find font %d\n", skin_font_id);
2128 success = false;
2129 continue;
2130 }
2131
2132 /* load the font - will handle loading the same font again if
2133 * multiple viewports use the same */
2134 if (font->font_id < 0)
2135 font->font_id = skin_font_load(font->name);
2136
2137 if (font->font_id < 0)
2138 {
2139 DEBUGF("Unable to load font %d: '%s.fnt'\n",
2140 skin_font_id, font->name);
2141 success = false;
2142 continue;
2143 }
2144
2145 /* finally, assign the font_id to the viewport */
2146 vp->font = font->font_id;
2147 }
2148 return success;
2149}
2150
2076#endif /* HAVE_LCD_BITMAP */ 2151#endif /* HAVE_LCD_BITMAP */
2077 2152
2078/* to setup up the wps-data from a format-buffer (isfile = false) 2153/* to setup up the wps-data from a format-buffer (isfile = false)
@@ -2188,6 +2263,12 @@ bool skin_data_load(enum screen_type screen, struct wps_data *wps_data,
2188 wps_data->wps_loaded = false; 2263 wps_data->wps_loaded = false;
2189 return false; 2264 return false;
2190 } 2265 }
2266 if (!skin_load_fonts(wps_data))
2267 {
2268 skin_data_reset(wps_data);
2269 wps_data->wps_loaded = false;
2270 return false;
2271 }
2191#endif 2272#endif
2192#if defined(HAVE_ALBUMART) && !defined(__PCTOOL__) 2273#if defined(HAVE_ALBUMART) && !defined(__PCTOOL__)
2193 status = audio_status(); 2274 status = audio_status();