Enlightenment CVS committal Author : barbieri Project : e17 Module : libs/edje
Dir : e17/libs/edje/src/lib Modified Files: edje_calc.c edje_private.h edje_text.c Log Message: 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. =================================================================== RCS file: /cvs/e/e17/libs/edje/src/lib/edje_calc.c,v retrieving revision 1.120 retrieving revision 1.121 diff -u -3 -r1.120 -r1.121 --- edje_calc.c 29 Feb 2008 03:39:31 -0000 1.120 +++ edje_calc.c 29 Feb 2008 21:43:55 -0000 1.121 @@ -663,101 +663,12 @@ text = ep->text.text_source->chosen_description->text.text; else text = chosen_desc->text.text; - if (ep->text.source) - { - font = ep->text.source->chosen_description->text.font; - size = ep->text.source->chosen_description->text.size; - } - else - { - font = chosen_desc->text.font; - size = chosen_desc->text.size; - } - if (ep->text.source) - { - if ((ep->text.source->chosen_description->text.text_class) && - (*ep->text.source->chosen_description->text.text_class)) - { - Edje_Text_Class *tc; - tc = _edje_text_class_find(ed, ep->text.source->chosen_description->text.text_class); - if (tc) - { - if ((tc->font) && (chosen_desc->text.font)) - { - char *tok, *tok2, *e; - - tok = strstr(chosen_desc->text.font, ":style="); - tok2 = strstr(tc->font, ":style="); - if ((tok) && (!tok2)) - { - char *stl; - int tclen; - - e = strchr(tok, ','); - stl = alloca(e - tok + 1); - strncpy(stl, tok, e - tok); - stl[e - tok] = 0; - font = tc->font; - tclen = strlen(tc->font); - sfont = malloc(tclen + e - tok + 1); - strcpy(sfont, tc->font); - strcpy(sfont + tclen, stl); - font = sfont; - } - else - font = tc->font; - } - else - { - if (tc->font) font = tc->font; - } - size = _edje_text_size_calc(size, tc); - } - } - } + if (ep->text.source) + font = _edje_text_class_font_get(ed, ep->text.source->chosen_description, &size, &sfont); else - { - if ((chosen_desc->text.text_class) && (*chosen_desc->text.text_class)) - { - Edje_Text_Class *tc; + font = _edje_text_class_font_get(ed, chosen_desc, &size, &sfont); - tc = _edje_text_class_find(ed, chosen_desc->text.text_class); - if (tc) - { - if ((tc->font) && (chosen_desc->text.font)) - { - char *tok, *tok2, *e; - - tok = strstr(chosen_desc->text.font, ":style="); - tok2 = strstr(tc->font, ":style="); - if ((tok) && (!tok2)) - { - char *stl; - int tclen; - - e = strchr(tok, ','); - stl = alloca(e - tok + 1); - strncpy(stl, tok, e - tok); - stl[e - tok] = 0; - font = tc->font; - tclen = strlen(tc->font); - sfont = malloc(tclen + e - tok + 1); - strcpy(sfont, tc->font); - strcpy(sfont + tclen, stl); - font = sfont; - } - else - font = tc->font; - } - else - { - if (tc->font) font = tc->font; - } - size = _edje_text_size_calc(size, tc); - } - } - } if (!font) font = ""; if (ep->text.text_source) =================================================================== RCS file: /cvs/e/e17/libs/edje/src/lib/edje_private.h,v retrieving revision 1.141 retrieving revision 1.142 diff -u -3 -r1.141 -r1.142 --- edje_private.h 27 Feb 2008 16:03:23 -0000 1.141 +++ edje_private.h 29 Feb 2008 21:43:55 -0000 1.142 @@ -1049,6 +1049,8 @@ void _edje_text_real_part_on_del(Edje *ed, Edje_Real_Part *ep); void _edje_text_recalc_apply(Edje *ed, Edje_Real_Part *ep, Edje_Calc_Params *params, Edje_Part_Description *chosen_desc); Evas_Font_Size _edje_text_size_calc(Evas_Font_Size size, Edje_Text_Class *tc); +const char * _edje_text_class_font_get(Edje *ed, Edje_Part_Description *chosen_desc, int *size, char **free_later); + Edje_Real_Part *_edje_real_part_get(Edje *ed, const char *part); Edje_Real_Part *_edje_real_part_recursive_get(Edje *ed, const char *part); =================================================================== RCS file: /cvs/e/e17/libs/edje/src/lib/edje_text.c,v retrieving revision 1.68 retrieving revision 1.69 diff -u -3 -r1.68 -r1.69 --- edje_text.c 22 Oct 2007 22:31:13 -0000 1.68 +++ edje_text.c 29 Feb 2008 21:43:55 -0000 1.69 @@ -272,6 +272,60 @@ return buf; } +static const char * +_edje_text_font_get(const char *base, const char *new, char **free_later) +{ + const char *base_style, *new_style, *aux; + int font_len, style_len; + + if (base && (!new)) + return base; + else if ((!base) && new) + return new; + + base_style = strstr(base, ":style="); + if (!base_style) + return new; + + new_style = strstr(new, ":style="); + if (new_style) + return new; + + font_len = strlen(new); + aux = strchr(base_style, ','); + style_len = (aux) ? (aux - base_style) : strlen(base_style); + + *free_later = malloc(font_len + style_len + 1); + memcpy(*free_later, new, font_len); + memcpy(*free_later + font_len, base_style, style_len); + (*free_later)[font_len + style_len] = '\0'; + + return *free_later; +} + +const char * +_edje_text_class_font_get(Edje *ed, Edje_Part_Description *chosen_desc, int *size, char **free_later) +{ + Edje_Text_Class *tc; + const char *text_class_name, *font; + + font = chosen_desc->text.font; + *size = chosen_desc->text.size; + + text_class_name = chosen_desc->text.text_class; + if ((!text_class_name) || (!text_class_name[0])) + return font; + + tc = _edje_text_class_find(ed, text_class_name); + if (!tc) + return font; + + font = _edje_text_font_get(chosen_desc->text.font, tc->font, free_later); + *size = _edje_text_size_calc(*size, tc); + + return font; +} + void _edje_text_recalc_apply(Edje *ed, Edje_Real_Part *ep, Edje_Calc_Params *params, @@ -288,54 +342,7 @@ text = chosen_desc->text.text; - font = chosen_desc->text.font; - size = chosen_desc->text.size; - - if ((chosen_desc->text.text_class) && (chosen_desc->text.text_class[0] != 0)) - { - Edje_Text_Class *tc; - - tc = _edje_text_class_find(ed, chosen_desc->text.text_class); - if (tc) - { - /* if the existing font spec in edje has a :style=XXX in it then - * its hinting that it wants to remain in that style even when - * a textclass is applied. if the textclass does not explicitly - * state a style, then snarf the old style out of the font spec - * and apply it to the text class being applie - */ - if ((tc->font) && (chosen_desc->text.font)) - { - char *tok, *tok2, *e; - - tok = strstr(chosen_desc->text.font, ":style="); - tok2 = strstr(tc->font, ":style="); - if ((tok) && (!tok2)) - { - char *stl; - int tclen; - - e = strchr(tok, ','); - stl = alloca(e - tok + 1); - strncpy(stl, tok, e - tok); - stl[e - tok] = 0; - font = tc->font; - tclen = strlen(tc->font); - sfont = malloc(tclen + e - tok + 1); - strcpy(sfont, tc->font); - strcpy(sfont + tclen, stl); - font = sfont; - } - else - font = tc->font; - } - else - { - if (tc->font) font = tc->font; - } - size = _edje_text_size_calc(size, tc); - } - } + font = _edje_text_class_font_get(ed, chosen_desc, &size, &sfont); if (ep->text.text) text = (char *) ep->text.text; if (ep->text.font) font = ep->text.font; ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ enlightenment-cvs mailing list enlightenment-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs