summaryrefslogtreecommitdiff
path: root/legacy/edje/src/lib/edje_text.c
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/lib/edje_text.c
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/lib/edje_text.c')
-rw-r--r--legacy/edje/src/lib/edje_text.c103
1 files changed, 55 insertions, 48 deletions
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;