1 #include "edje_private.h"
4 _edje_font_is_embedded(Edje_File *edf, char *font)
6 if (!eina_hash_find(edf->fonts, font)) return 0;
11 _edje_format_param_parse(char *item, char **key, char **val)
15 p = strchr(item, '=');
16 k = malloc(p - item + 1);
17 strncpy(k, item, p - item);
26 _edje_format_parse(const char **s)
29 const char *s1 = NULL;
30 const char *s2 = NULL;
31 Eina_Bool quote = EINA_FALSE;
34 if ((!p) || (*p == 0)) return NULL;
39 if (*p != ' ') s1 = p;
49 if ((p > *s) && (p[-1] != '\\') && (!quote))
51 if (*p == ' ') s2 = p;
56 if (s1 && s2 && (s2 > s1))
59 char *ret = malloc(len + 1);
71 _edje_format_is_param(char *item)
73 if (strchr(item, '=')) return 1;
78 _edje_format_reparse(Edje_File *edf, const char *str, Edje_Style_Tag **tag_ret)
80 Eina_Strbuf *txt, *tmp = NULL;
81 char *s2, *item, *ret;
84 txt = eina_strbuf_new();
86 while ((item = _edje_format_parse(&s)))
88 if (_edje_format_is_param(item))
90 char *key = NULL, *val = NULL;
92 _edje_format_param_parse(item, &key, &val);
93 if (!strcmp(key, "font_source"))
95 /* dont allow font sources */
97 else if (!strcmp(key, "text_class"))
100 (*tag_ret)->text_class = eina_stringshare_add(val);
102 else if (!strcmp(key, "font_size"))
105 (*tag_ret)->font_size = atof(val);
107 else if (!strcmp(key, "font")) /* Fix fonts */
111 if (_edje_font_is_embedded(edf, val))
114 tmp = eina_strbuf_new();
115 eina_strbuf_append(tmp, "edje/fonts/");
116 eina_strbuf_append(tmp, val);
117 (*tag_ret)->font = eina_stringshare_add(eina_strbuf_string_get(tmp));
118 eina_strbuf_reset(tmp);
122 (*tag_ret)->font = eina_stringshare_add(val);
126 else /* Otherwise add to tag buffer */
128 s2 = eina_str_escape(item);
131 if (eina_strbuf_length_get(txt)) eina_strbuf_append(txt, " ");
132 eina_strbuf_append(txt, s2);
141 if (eina_strbuf_length_get(txt)) eina_strbuf_append(txt, " ");
142 eina_strbuf_append(txt, item);
147 eina_strbuf_free(tmp);
148 ret = eina_strbuf_string_steal(txt);
149 eina_strbuf_free(txt);
153 /* Update all evas_styles which are in an edje
155 * @param ed The edje containing styles which need to be updated
158 _edje_textblock_style_all_update(Edje *ed)
162 Eina_Strbuf *txt = NULL;
164 if (!ed->file) return;
166 EINA_LIST_FOREACH(ed->file->styles, l, stl)
171 char *fontset = NULL, *fontsource = NULL;
173 /* Make sure the style is already defined */
174 if (!stl->style) break;
176 /* Make sure the style contains a text_class */
177 EINA_LIST_FOREACH(stl->tags, ll, tag)
186 /* No text classes , goto next style */
187 if (!found) continue;
190 txt = eina_strbuf_new();
192 if (_edje_fontset_append)
193 fontset = eina_str_escape(_edje_fontset_append);
194 fontsource = eina_str_escape(ed->file->path);
196 /* Build the style from each tag */
197 EINA_LIST_FOREACH(stl->tags, ll, tag)
199 if (!tag->key) continue;
202 eina_strbuf_append(txt, tag->key);
203 eina_strbuf_append(txt, "='");
205 /* Configure fonts from text class if it exists */
206 tc = _edje_text_class_find(ed, tag->text_class);
208 /* Add and Ha`ndle tag parsed data */
209 eina_strbuf_append(txt, tag->value);
211 if (!strcmp(tag->key, "DEFAULT"))
215 eina_strbuf_append(txt, " ");
216 eina_strbuf_append(txt, "font_fallbacks=");
217 eina_strbuf_append(txt, fontset);
219 eina_strbuf_append(txt, " ");
220 eina_strbuf_append(txt, "font_source=");
221 eina_strbuf_append(txt, fontsource);
223 if (tag->font_size != 0)
228 snprintf(font_size, sizeof(font_size), "%f", (double) _edje_text_size_calc(tag->font_size, tc));
230 snprintf(font_size, sizeof(font_size), "%f", tag->font_size);
232 eina_strbuf_append(txt, " ");
233 eina_strbuf_append(txt, "font_size=");
234 eina_strbuf_append(txt, font_size);
236 /* Add font name last to save evas from multiple loads */
241 eina_strbuf_append(txt, " ");
242 eina_strbuf_append(txt, "font=");
244 f = (tc && tc->font) ? tc->font : tag->font;
245 eina_strbuf_append_escaped(txt, f);
248 eina_strbuf_append(txt, "'");
250 if (fontset) free(fontset);
251 if (fontsource) free(fontsource);
253 /* Configure the style */
254 evas_textblock_style_set(stl->style, eina_strbuf_string_get(txt));
255 eina_strbuf_reset(txt);
258 eina_strbuf_free(txt);
262 _edje_textblock_styles_add(Edje *ed)
267 if (!ed->file) return;
269 EINA_LIST_FOREACH(ed->file->styles, l, stl)
273 /* Make sure the style contains the text_class */
274 EINA_LIST_FOREACH(stl->tags, ll, tag)
276 if (!tag->text_class) continue;
277 _edje_text_class_member_add(ed, tag->text_class);
283 _edje_textblock_styles_del(Edje *ed)
288 if (!ed->file) return;
290 EINA_LIST_FOREACH(ed->file->styles, l, stl)
294 /* Make sure the style contains the text_class */
295 EINA_LIST_FOREACH(stl->tags, ll, tag)
297 if (!tag->text_class) continue;
298 _edje_text_class_member_del(ed, tag->text_class);
303 /* When we get to here the edje file had been read into memory
304 * the name of the style is established as well as the name and
305 * data for the tags. This function will create the Evas_Style
306 * object for each style. The style is composed of a base style
307 * followed by a list of tags.
310 _edje_textblock_style_parse_and_fix(Edje_File *edf)
312 Eina_Strbuf *txt = NULL;
316 EINA_LIST_FOREACH(edf->styles, l, stl)
319 char *fontset = NULL, *fontsource = NULL, *ts;
321 if (stl->style) break;
324 txt = eina_strbuf_new();
326 stl->style = evas_textblock_style_new();
327 evas_textblock_style_set(stl->style, NULL);
329 if (_edje_fontset_append)
330 fontset = eina_str_escape(_edje_fontset_append);
331 fontsource = eina_str_escape(edf->path);
333 /* Build the style from each tag */
334 EINA_LIST_FOREACH(stl->tags, ll, tag)
336 if (!tag->key) continue;
339 eina_strbuf_append(txt, tag->key);
340 eina_strbuf_append(txt, "='");
342 ts = _edje_format_reparse(edf, tag->value, &(tag));
344 /* Add and Handle tag parsed data */
347 if (eet_dictionary_string_check(eet_dictionary_get(edf->ef), tag->value) == 0)
348 eina_stringshare_del(tag->value);
349 tag->value = eina_stringshare_add(ts);
350 eina_strbuf_append(txt, tag->value);
354 if (!strcmp(tag->key, "DEFAULT"))
358 eina_strbuf_append(txt, " ");
359 eina_strbuf_append(txt, "font_fallbacks=");
360 eina_strbuf_append(txt, fontset);
362 eina_strbuf_append(txt, " ");
363 eina_strbuf_append(txt, "font_source=");
364 eina_strbuf_append(txt, fontsource);
366 if (tag->font_size > 0)
370 snprintf(font_size, sizeof(font_size), "%f", tag->font_size);
371 eina_strbuf_append(txt, " ");
372 eina_strbuf_append(txt, "font_size=");
373 eina_strbuf_append(txt, font_size);
375 /* Add font name last to save evas from multiple loads */
378 eina_strbuf_append(txt, " ");
379 eina_strbuf_append(txt, "font=");
380 eina_strbuf_append_escaped(txt, tag->font);
382 eina_strbuf_append(txt, "'");
384 if (fontset) free(fontset);
385 if (fontsource) free(fontsource);
387 /* Configure the style */
388 evas_textblock_style_set(stl->style, eina_strbuf_string_get(txt));
389 eina_strbuf_reset(txt);
392 eina_strbuf_free(txt);
396 _edje_textblock_style_cleanup(Edje_File *edf)
402 stl = edf->styles->data;
403 edf->styles = eina_list_remove_list(edf->styles, edf->styles);
408 tag = stl->tags->data;
409 stl->tags = eina_list_remove_list(stl->tags, stl->tags);
410 if (edf->free_strings)
412 if (tag->key) eina_stringshare_del(tag->key);
413 /* FIXME: Find a proper way to handle it. */
414 if (tag->value) eina_stringshare_del(tag->value);
415 if (tag->text_class) eina_stringshare_del(tag->text_class);
416 if (tag->font) eina_stringshare_del(tag->font);
420 if (edf->free_strings && stl->name) eina_stringshare_del(stl->name);
421 if (stl->style) evas_textblock_style_free(stl->style);