summaryrefslogtreecommitdiff
path: root/legacy/edje/src
diff options
context:
space:
mode:
authorGustavo Sverzut Barbieri <barbieri@gmail.com>2008-02-29 21:43:55 +0000
committerGustavo Sverzut Barbieri <barbieri@gmail.com>2008-02-29 21:43:55 +0000
commit08bfdacdee67ef3b835a055c3e64c6c216965593 (patch)
tree4a96efdafd12e49023eb1330b16254839ee44ebe /legacy/edje/src
parentda7eabb8091c8b5ce491492ece205d1dff110a10 (diff)
Bugfix and refactor get of font based on text_class.
Edje tries to copy original style to font provided by text_class if this have no style. However code was supposing that text_class font always had more than one occurrence, these separated with ',' and did not check if this is not the case, so "e = strchr(',', tok);" was returning NULL and all the math were using negative values. The fix now does the proper checking, avoid one useless alloca() and the respective copy, also doing the copies with memcpy() since sizes are already known. Refactory was done to make code simpler and also avoid having it copied 3 times. SVN revision: 33869
Diffstat (limited to 'legacy/edje/src')
-rw-r--r--legacy/edje/src/lib/edje_calc.c95
-rw-r--r--legacy/edje/src/lib/edje_private.h2
-rw-r--r--legacy/edje/src/lib/edje_text.c103
3 files changed, 60 insertions, 140 deletions
diff --git a/legacy/edje/src/lib/edje_calc.c b/legacy/edje/src/lib/edje_calc.c
index 2aa2fed..c98ab11 100644
--- a/legacy/edje/src/lib/edje_calc.c
+++ b/legacy/edje/src/lib/edje_calc.c
@@ -663,101 +663,12 @@ _edje_part_recalc_single(Edje *ed,
663 text = ep->text.text_source->chosen_description->text.text; 663 text = ep->text.text_source->chosen_description->text.text;
664 else 664 else
665 text = chosen_desc->text.text; 665 text = chosen_desc->text.text;
666 if (ep->text.source)
667 {
668 font = ep->text.source->chosen_description->text.font;
669 size = ep->text.source->chosen_description->text.size;
670 }
671 else
672 {
673 font = chosen_desc->text.font;
674 size = chosen_desc->text.size;
675 }
676 if (ep->text.source)
677 {
678 if ((ep->text.source->chosen_description->text.text_class) &&
679 (*ep->text.source->chosen_description->text.text_class))
680 {
681 Edje_Text_Class *tc;
682 666
683 tc = _edje_text_class_find(ed, ep->text.source->chosen_description->text.text_class); 667 if (ep->text.source)
684 if (tc) 668 font = _edje_text_class_font_get(ed, ep->text.source->chosen_description, &size, &sfont);
685 {
686 if ((tc->font) && (chosen_desc->text.font))
687 {
688 char *tok, *tok2, *e;
689
690 tok = strstr(chosen_desc->text.font, ":style=");
691 tok2 = strstr(tc->font, ":style=");
692 if ((tok) && (!tok2))
693 {
694 char *stl;
695 int tclen;
696
697 e = strchr(tok, ',');
698 stl = alloca(e - tok + 1);
699 strncpy(stl, tok, e - tok);
700 stl[e - tok] = 0;
701 font = tc->font;
702 tclen = strlen(tc->font);
703 sfont = malloc(tclen + e - tok + 1);
704 strcpy(sfont, tc->font);
705 strcpy(sfont + tclen, stl);
706 font = sfont;
707 }
708 else
709 font = tc->font;
710 }
711 else
712 {
713 if (tc->font) font = tc->font;
714 }
715 size = _edje_text_size_calc(size, tc);
716 }
717 }
718 }
719 else 669 else
720 { 670 font = _edje_text_class_font_get(ed, chosen_desc, &size, &sfont);
721 if ((chosen_desc->text.text_class) && (*chosen_desc->text.text_class))
722 {
723 Edje_Text_Class *tc;
724 671
725 tc = _edje_text_class_find(ed, chosen_desc->text.text_class);
726 if (tc)
727 {
728 if ((tc->font) && (chosen_desc->text.font))
729 {
730 char *tok, *tok2, *e;
731
732 tok = strstr(chosen_desc->text.font, ":style=");
733 tok2 = strstr(tc->font, ":style=");
734 if ((tok) && (!tok2))
735 {
736 char *stl;
737 int tclen;
738
739 e = strchr(tok, ',');
740 stl = alloca(e - tok + 1);
741 strncpy(stl, tok, e - tok);
742 stl[e - tok] = 0;
743 font = tc->font;
744 tclen = strlen(tc->font);
745 sfont = malloc(tclen + e - tok + 1);
746 strcpy(sfont, tc->font);
747 strcpy(sfont + tclen, stl);
748 font = sfont;
749 }
750 else
751 font = tc->font;
752 }
753 else
754 {
755 if (tc->font) font = tc->font;
756 }
757 size = _edje_text_size_calc(size, tc);
758 }
759 }
760 }
761 if (!font) font = ""; 672 if (!font) font = "";
762 673
763 if (ep->text.text_source) 674 if (ep->text.text_source)
diff --git a/legacy/edje/src/lib/edje_private.h b/legacy/edje/src/lib/edje_private.h
index fbf3195..022c7f3 100644
--- a/legacy/edje/src/lib/edje_private.h
+++ b/legacy/edje/src/lib/edje_private.h
@@ -1049,6 +1049,8 @@ void _edje_text_part_on_del(Edje *ed, Edje_Part *ep);
1049void _edje_text_real_part_on_del(Edje *ed, Edje_Real_Part *ep); 1049void _edje_text_real_part_on_del(Edje *ed, Edje_Real_Part *ep);
1050void _edje_text_recalc_apply(Edje *ed, Edje_Real_Part *ep, Edje_Calc_Params *params, Edje_Part_Description *chosen_desc); 1050void _edje_text_recalc_apply(Edje *ed, Edje_Real_Part *ep, Edje_Calc_Params *params, Edje_Part_Description *chosen_desc);
1051Evas_Font_Size _edje_text_size_calc(Evas_Font_Size size, Edje_Text_Class *tc); 1051Evas_Font_Size _edje_text_size_calc(Evas_Font_Size size, Edje_Text_Class *tc);
1052const char * _edje_text_class_font_get(Edje *ed, Edje_Part_Description *chosen_desc, int *size, char **free_later);
1053
1052 1054
1053Edje_Real_Part *_edje_real_part_get(Edje *ed, const char *part); 1055Edje_Real_Part *_edje_real_part_get(Edje *ed, const char *part);
1054Edje_Real_Part *_edje_real_part_recursive_get(Edje *ed, const char *part); 1056Edje_Real_Part *_edje_real_part_recursive_get(Edje *ed, const char *part);
diff --git a/legacy/edje/src/lib/edje_text.c b/legacy/edje/src/lib/edje_text.c
index 7e6bcbe..724800f 100644
--- a/legacy/edje/src/lib/edje_text.c
+++ b/legacy/edje/src/lib/edje_text.c
@@ -272,6 +272,60 @@ _edje_text_fit_x(Edje *ed, Edje_Real_Part *ep,
272 return buf; 272 return buf;
273} 273}
274 274
275static const char *
276_edje_text_font_get(const char *base, const char *new, char **free_later)
277{
278 const char *base_style, *new_style, *aux;
279 int font_len, style_len;
280
281 if (base && (!new))
282 return base;
283 else if ((!base) && new)
284 return new;
285
286 base_style = strstr(base, ":style=");
287 if (!base_style)
288 return new;
289
290 new_style = strstr(new, ":style=");
291 if (new_style)
292 return new;
293
294 font_len = strlen(new);
295 aux = strchr(base_style, ',');
296 style_len = (aux) ? (aux - base_style) : strlen(base_style);
297
298 *free_later = malloc(font_len + style_len + 1);
299 memcpy(*free_later, new, font_len);
300 memcpy(*free_later + font_len, base_style, style_len);
301 (*free_later)[font_len + style_len] = '\0';
302
303 return *free_later;
304}
305
306const char *
307_edje_text_class_font_get(Edje *ed, Edje_Part_Description *chosen_desc, int *size, char **free_later)
308{
309 Edje_Text_Class *tc;
310 const char *text_class_name, *font;
311
312 font = chosen_desc->text.font;
313 *size = chosen_desc->text.size;
314
315 text_class_name = chosen_desc->text.text_class;
316 if ((!text_class_name) || (!text_class_name[0]))
317 return font;
318
319 tc = _edje_text_class_find(ed, text_class_name);
320 if (!tc)
321 return font;
322
323 font = _edje_text_font_get(chosen_desc->text.font, tc->font, free_later);
324 *size = _edje_text_size_calc(*size, tc);
325
326 return font;
327}
328
275void 329void
276_edje_text_recalc_apply(Edje *ed, Edje_Real_Part *ep, 330_edje_text_recalc_apply(Edje *ed, Edje_Real_Part *ep,
277 Edje_Calc_Params *params, 331 Edje_Calc_Params *params,
@@ -288,54 +342,7 @@ _edje_text_recalc_apply(Edje *ed, Edje_Real_Part *ep,
288 342
289 343
290 text = chosen_desc->text.text; 344 text = chosen_desc->text.text;
291 font = chosen_desc->text.font; 345 font = _edje_text_class_font_get(ed, chosen_desc, &size, &sfont);
292 size = chosen_desc->text.size;
293
294 if ((chosen_desc->text.text_class) && (chosen_desc->text.text_class[0] != 0))
295 {
296 Edje_Text_Class *tc;
297
298 tc = _edje_text_class_find(ed, chosen_desc->text.text_class);
299 if (tc)
300 {
301 /* if the existing font spec in edje has a :style=XXX in it then
302 * its hinting that it wants to remain in that style even when
303 * a textclass is applied. if the textclass does not explicitly
304 * state a style, then snarf the old style out of the font spec
305 * and apply it to the text class being applie
306 */
307 if ((tc->font) && (chosen_desc->text.font))
308 {
309 char *tok, *tok2, *e;
310
311 tok = strstr(chosen_desc->text.font, ":style=");
312 tok2 = strstr(tc->font, ":style=");
313 if ((tok) && (!tok2))
314 {
315 char *stl;
316 int tclen;
317
318 e = strchr(tok, ',');
319 stl = alloca(e - tok + 1);
320 strncpy(stl, tok, e - tok);
321 stl[e - tok] = 0;
322 font = tc->font;
323 tclen = strlen(tc->font);
324 sfont = malloc(tclen + e - tok + 1);
325 strcpy(sfont, tc->font);
326 strcpy(sfont + tclen, stl);
327 font = sfont;
328 }
329 else
330 font = tc->font;
331 }
332 else
333 {
334 if (tc->font) font = tc->font;
335 }
336 size = _edje_text_size_calc(size, tc);
337 }
338 }
339 346
340 if (ep->text.text) text = (char *) ep->text.text; 347 if (ep->text.text) text = (char *) ep->text.text;
341 if (ep->text.font) font = ep->text.font; 348 if (ep->text.font) font = ep->text.font;