efl

Форк
0
/
edje_textblock_styles.c 
812 строк · 26.9 Кб
1
#include "edje_private.h"
2
#include <ctype.h>
3

4
void _edje_textblock_style_update(Edje *ed, Edje_Style *stl);
5

6
static Edje_Style *
7
_edje_textblock_style_copy(Edje_Style *stl)
8
{
9
   Edje_Style *new_stl;
10

11
   new_stl = calloc(1, sizeof(Edje_Style));
12
   if (!new_stl) return NULL;
13

14
   new_stl->style = evas_textblock_style_new();
15
   evas_textblock_style_set(new_stl->style, NULL);
16

17
   // just keep a reference.
18
   new_stl->tags = stl->tags;
19
   new_stl->name = stl->name;
20
   new_stl->cache = EINA_FALSE;
21

22
   return new_stl;
23
}
24

25
static void
26
_edje_object_textblock_styles_cache_style_free(void *data)
27
{
28
   Edje_Style *obj_stl = data;
29

30
   if (!obj_stl) return;
31

32
   if (obj_stl->style) evas_textblock_style_free(obj_stl->style);
33
   free(obj_stl);
34
}
35

36
static Edje_Style *
37
_edje_object_textblock_styles_cache_add(Edje *ed, Edje_Style *stl)
38
{
39
   Edje_Style *obj_stl = eina_hash_find(ed->styles, stl->name);
40
   // Find the style in the object cache
41

42
   if (!obj_stl)
43
     {
44
        obj_stl = _edje_textblock_style_copy(stl);
45

46
        if (obj_stl)
47
          {
48
             if (!ed->styles) ed->styles = eina_hash_stringshared_new(_edje_object_textblock_styles_cache_style_free);
49
             eina_hash_direct_add(ed->styles, obj_stl->name, obj_stl);
50
             _edje_textblock_style_update(ed, obj_stl);
51
          }
52
     }
53
   return obj_stl;
54
}
55

56
void
57
_edje_object_textblock_styles_cache_cleanup(Edje *ed)
58
{
59
   if (!ed || !ed->styles) return;
60
   eina_hash_free(ed->styles);
61
   ed->styles = NULL;
62
}
63

64
static Edje_Style *
65
_edje_object_textblock_styles_cache_get(Edje *ed, const char *stl)
66
{
67
   // Find the style in the object cache
68
   return eina_hash_find(ed->styles, stl);
69
}
70

71
static int
72
_edje_font_is_embedded(Edje_File *edf, const char *font)
73
{
74
   if (!eina_hash_find(edf->fonts, font)) return 0;
75
   return 1;
76
}
77

78
static char *
79
_edje_format_parse(const char **s)
80
{
81
   const char *p;
82
   const char *s1 = NULL;
83
   const char *s2 = NULL;
84
   Eina_Bool quote = EINA_FALSE;
85

86
   p = *s;
87
   if ((!p) || (*p == 0)) return NULL;
88
   for (;; )
89
     {
90
        if (!s1)
91
          {
92
             if (*p != ' ') s1 = p;
93
             if (*p == 0) break;
94
          }
95
        else if (!s2)
96
          {
97
             if (*p == '\'')
98
               {
99
                  quote = !quote;
100
               }
101

102
             if ((p > *s) && (p[-1] != '\\') && (!quote))
103
               {
104
                  if (*p == ' ') s2 = p;
105
               }
106
             if (*p == 0) s2 = p;
107
          }
108
        p++;
109
        if (s1 && s2 && (s2 > s1))
110
          {
111
             size_t len = s2 - s1;
112
             char *ret = malloc(len + 1);
113
             memcpy(ret, s1, len);
114
             ret[len] = '\0';
115
             *s = s2;
116
             return ret;
117
          }
118
     }
119
   *s = p;
120
   return NULL;
121
}
122

123
#define _IS_STRINGS_EQUAL(str1, len1, str2, len2) (((len1)==(len2)) && !strncmp(str1, str2, len1))
124

125
static void
126
_edje_format_reparse(Edje_File *edf, const char *str, Edje_Style_Tag *tag_ret, Eina_Strbuf *result)
127
{
128
   char *s2, *item;
129
   const char *s;
130

131
   s = str;
132
   while ((item = _edje_format_parse(&s)))
133
     {
134
        const char *pos = strchr(item, '=');
135
        if (pos)
136
          {
137
             size_t key_len = pos - item;
138
             const char *key = item;
139
             const char *val = pos + 1;
140

141
             if (_IS_STRINGS_EQUAL(key, key_len, "font_source", 11))
142
               {
143
                  /* dont allow font sources */
144
               }
145
             else if (_IS_STRINGS_EQUAL(key, key_len, "text_class", 10))
146
               {
147
                  if (tag_ret)
148
                    eina_stringshare_replace(&(tag_ret->text_class), val);
149

150
                  // no need to add text_class tag to style
151
                  // as evas_textblock_style has no idea about
152
                  // text_class tag.
153
                  free(item);
154
                  continue;
155
               }
156
             else if (_IS_STRINGS_EQUAL(key, key_len, "color_class", 11))
157
               {
158
                  if (tag_ret)
159
                    eina_stringshare_replace(&(tag_ret->color_class), val);
160

161
                  // no need to add color_class tag to style
162
                  // as evas_textblock_style has no idea about
163
                  // color_class tag.
164
                  free(item);
165
                  continue;
166
               }
167
             else if (_IS_STRINGS_EQUAL(key, key_len, "font_size", 9))
168
               {
169
                  if (tag_ret)
170
                    tag_ret->font_size = atof(val);
171
               }
172
             else if (_IS_STRINGS_EQUAL(key, key_len, "font", 4)) /* Fix fonts */
173
               {
174
                  if (tag_ret)
175
                    {
176
                       if (_edje_font_is_embedded(edf, val))
177
                         {
178
                            char buffer[120];
179
                            snprintf(buffer, sizeof(buffer), "edje/fonts/%s", val);
180
                            eina_stringshare_replace(&tag_ret->font, buffer);
181
                            if (eina_strbuf_length_get(result)) eina_strbuf_append(result, " ");
182
                            eina_strbuf_append(result, "font=");
183
                            eina_strbuf_append(result, buffer);
184
                            continue;
185
                         }
186
                       else
187
                         {
188
                            tag_ret->font = eina_stringshare_add(val);
189
                         }
190
                    }
191
               }
192
             // handle colorclass replacements of color like: color=cc:/fg/normal
193
             else if ((_IS_STRINGS_EQUAL(key, key_len, "color", 5)) ||
194
                      (_IS_STRINGS_EQUAL(key, key_len, "outline_color", 13)) ||
195
                      (_IS_STRINGS_EQUAL(key, key_len, "shadow_color", 12)) ||
196
                      (_IS_STRINGS_EQUAL(key, key_len, "underline_color", 15)) ||
197
                      (_IS_STRINGS_EQUAL(key, key_len, "underline2_color", 16)) ||
198
                      (_IS_STRINGS_EQUAL(key, key_len, "secondary_underline_color", 25)) ||
199
                      (_IS_STRINGS_EQUAL(key, key_len, "underline_dash_color", 20)) ||
200
                      (_IS_STRINGS_EQUAL(key, key_len, "underline_dashed_color", 22)) ||
201
                      (_IS_STRINGS_EQUAL(key, key_len, "glow_color", 10)) ||
202
                      (_IS_STRINGS_EQUAL(key, key_len, "glow2_color", 11)) ||
203
                      (_IS_STRINGS_EQUAL(key, key_len, "secondary_glow_color", 20)) ||
204
                      (_IS_STRINGS_EQUAL(key, key_len, "backing_color", 13)) ||
205
                      (_IS_STRINGS_EQUAL(key, key_len, "background_color", 16)) ||
206
                      (_IS_STRINGS_EQUAL(key, key_len, "strikethrough_color", 19)))
207
               {
208
                  if (!strncmp(val, "cc:", 3))
209
                    {
210
                       if ((_IS_STRINGS_EQUAL(key, key_len, "color", 5)))
211
                         eina_stringshare_replace(&(tag_ret->color_class), val + 3);
212
                       else if ((_IS_STRINGS_EQUAL(key, key_len, "outline_color", 13)))
213
                         eina_stringshare_replace(&(tag_ret->outline_color_class), val + 3);
214
                       else if ((_IS_STRINGS_EQUAL(key, key_len, "shadow_color", 12)))
215
                         eina_stringshare_replace(&(tag_ret->shadow_color_class), val + 3);
216
                       else if ((_IS_STRINGS_EQUAL(key, key_len, "underline_color", 15)))
217
                         eina_stringshare_replace(&(tag_ret->underline_color_class), val + 3);
218
                       else if ((_IS_STRINGS_EQUAL(key, key_len, "underline2_color", 16)) ||
219
                                (_IS_STRINGS_EQUAL(key, key_len, "secondary_underline_color", 25)))
220
                         eina_stringshare_replace(&(tag_ret->underline2_color_class), val + 3);
221
                       else if ((_IS_STRINGS_EQUAL(key, key_len, "underline_dash_color", 20)) ||
222
                                (_IS_STRINGS_EQUAL(key, key_len, "underline_dashed_color", 22)))
223
                         eina_stringshare_replace(&(tag_ret->underline_dash_color_class), val + 3);
224
                       else if ((_IS_STRINGS_EQUAL(key, key_len, "glow_color", 10)))
225
                         eina_stringshare_replace(&(tag_ret->glow_color_class), val + 3);
226
                       else if ((_IS_STRINGS_EQUAL(key, key_len, "glow2_color", 11)) ||
227
                                (_IS_STRINGS_EQUAL(key, key_len, "secondary_glow_color", 20)))
228
                         eina_stringshare_replace(&(tag_ret->glow2_color_class), val + 3);
229
                       else if ((_IS_STRINGS_EQUAL(key, key_len, "backing_color", 13)) ||
230
                                (_IS_STRINGS_EQUAL(key, key_len, "background_color", 16)))
231
                         eina_stringshare_replace(&(tag_ret->backing_color_class), val + 3);
232
                       else if ((_IS_STRINGS_EQUAL(key, key_len, "strikethrough_color", 19)))
233
                         eina_stringshare_replace(&(tag_ret->strikethrough_color_class), val + 3);
234
                    }
235
               }
236
             // XXX: how do we do better for:
237
             // color
238
             // outline_color
239
             // shadow_color
240
             // 
241
             // XXX: and do these too:
242
             // underline_color
243
             // underline2_color | secondary_underline_color
244
             // underline_dash_color | underline_dashed_color
245
             // glow_color
246
             // glow2_color | secondary_glow_color
247
             // backing_color | background_color
248
             // strikethrough_color
249
             s2 = eina_str_escape(item);
250
             if (s2)
251
               {
252
                  if (eina_strbuf_length_get(result)) eina_strbuf_append(result, " ");
253
                  eina_strbuf_append(result, s2);
254
                  free(s2);
255
               }
256
          }
257
        else
258
          {
259
             if (eina_strbuf_length_get(result)) eina_strbuf_append(result, " ");
260
             eina_strbuf_append(result, item);
261
          }
262
        free(item);
263
     }
264
}
265

266
static void
267
_edje_textblock_tag_update(Eina_Strbuf *style, const char *key, const char *new_tag)
268
{
269
   char *ptr = strstr(eina_strbuf_string_get(style), key);
270
   char *last = NULL;
271

272
   while (ptr != NULL)
273
     {
274
        last = ptr;
275
        ptr = strstr(ptr + 1, key);
276
     }
277

278
   if (last)
279
     {
280
        char *tok = strdup(last);
281
        int cnt = 0;
282
        while (*tok && !isspace(*tok))
283
          {
284
             tok++;
285
             cnt++;
286
          }
287
        if (*tok) *tok = 0;
288
        tok -= cnt;
289

290
        eina_strbuf_replace_last(style, tok, new_tag);
291
        free(tok);
292
     }
293
   else
294
     {
295
        eina_strbuf_append(style, " ");
296
        eina_strbuf_append(style, new_tag);
297
     }
298
}
299

300
static void
301
_edje_textblock_font_tag_update(Eina_Strbuf *style, const char *new_value)
302
{
303
   const char *font_key = "font=";
304
   char new_font[256] = {0,};
305
   snprintf(new_font, sizeof(new_font), "%s%s", font_key, new_value);
306
   _edje_textblock_tag_update(style, font_key, new_font);
307
}
308

309
static void
310
_edje_textblock_font_size_tag_update(Eina_Strbuf *style, double new_value)
311
{
312
   const char *font_size_key = "font_size=";
313
   char new_font_size[32] = {0,};
314
   snprintf(new_font_size, sizeof(new_font_size), "%s%.1f", font_size_key, new_value);
315
   _edje_textblock_tag_update(style, font_size_key, new_font_size);
316
}
317

318
/* Update the given evas_style
319
 *
320
 * @param ed The edje containing the given style which need to be updated
321
 * @param style The style which need to be updated
322
 * As now edje_style supports lazy computation of evas_textblock_style
323
 * only call this function from _edje_textblock_style_get()
324
 */
325
void
326
_edje_textblock_style_update(Edje *ed, Edje_Style *stl)
327
{
328
   Eina_List *l;
329
   Eina_Strbuf *txt = NULL;
330
   Edje_Style_Tag *tag;
331
   Edje_Text_Class *tc;
332
   Edje_Color_Class *cc;
333
   char *fontset = _edje_fontset_append_escaped, *fontsource = NULL;
334

335
   if (!ed->file) return;
336

337
   /* Make sure the style is already defined */
338
   if (!stl->style) return;
339

340
   /* this check is only here to catch misuse of this function */
341
   if (stl->readonly)
342
     {
343
        WRN("style_update() shouldn't be called for readonly style. performance regression : %s", stl->name);
344
        return;
345
     }
346

347
   /* this check is only here to catch misuse of this function */
348
   if (stl->cache)
349
     {
350
        WRN("style_update() shouldn't be called for cached style. performance regression : %s", stl->name);
351
        return;
352
     }
353

354
   if (!txt)
355
     txt = eina_strbuf_new();
356

357
   if (ed->file->fonts)
358
     fontsource = eina_str_escape(ed->file->path);
359

360
   /* Build the style from each tag */
361
   EINA_LIST_FOREACH(stl->tags, l, tag)
362
     {
363
        if (!tag->key) continue;
364

365
        /* Add Tag Key */
366
        eina_strbuf_append(txt, tag->key);
367
        eina_strbuf_append(txt, "='");
368

369
        /* Configure fonts from text class if it exists */
370
        if (tag->text_class) tc = _edje_text_class_find(ed, tag->text_class);
371
        else tc = NULL;
372

373
        /* Add and Handle tag parsed data */
374
        eina_strbuf_append(txt, tag->value);
375

376
        if (!strcmp(tag->key, "DEFAULT"))
377
          {
378
             if (fontset)
379
               {
380
                  eina_strbuf_append(txt, " font_fallbacks=");
381
                  eina_strbuf_append(txt, fontset);
382
               }
383
             if (fontsource)
384
               {
385
                  eina_strbuf_append(txt, " font_source=");
386
                  eina_strbuf_append(txt, fontsource);
387
               }
388
          }
389
        if (tc && tc->size)
390
          {
391
             double new_size = _edje_text_size_calc(tag->font_size, tc);
392
             if (!EINA_DBL_EQ(tag->font_size, new_size))
393
               {
394
                  _edje_textblock_font_size_tag_update(txt, new_size);
395
               }
396
          }
397
        /* Add font name last to save evas from multiple loads */
398
        if (tc && tc->font)
399
          {
400
             const char *f;
401
             char *sfont = NULL;
402

403
             f = _edje_text_font_get(tag->font, tc->font, &sfont);
404
             _edje_textblock_font_tag_update(txt, f);
405

406
             if (sfont) free(sfont);
407
          }
408
        if (tag->color_class)
409
          {
410
             if ((cc = _edje_color_class_recursive_find(ed, tag->color_class)))
411
               eina_strbuf_append_printf(txt, " color=#%02x%02x%02x%02x", cc->r,  cc->g,  cc->b,  cc->a);
412
          }
413
        if (tag->outline_color_class)
414
          {
415
             if ((cc = _edje_color_class_recursive_find(ed, tag->outline_color_class)))
416
               eina_strbuf_append_printf(txt, " outline_color=#%02x%02x%02x%02x", cc->r,  cc->g,  cc->b,  cc->a);
417
          }
418
        if (tag->shadow_color_class)
419
          {
420
             if ((cc = _edje_color_class_recursive_find(ed, tag->shadow_color_class)))
421
               eina_strbuf_append_printf(txt, " shadow_color=#%02x%02x%02x%02x", cc->r,  cc->g,  cc->b,  cc->a);
422
          }
423
        if (tag->underline_color_class)
424
          {
425
             if ((cc = _edje_color_class_recursive_find(ed, tag->underline_color_class)))
426
               eina_strbuf_append_printf(txt, " underline_color=#%02x%02x%02x%02x", cc->r,  cc->g,  cc->b,  cc->a);
427
          }
428
        if (tag->underline2_color_class)
429
          {
430
             if ((cc = _edje_color_class_recursive_find(ed, tag->underline2_color_class)))
431
               eina_strbuf_append_printf(txt, " underline2_color=#%02x%02x%02x%02x", cc->r,  cc->g,  cc->b,  cc->a);
432
          }
433
        if (tag->underline_dash_color_class)
434
          {
435
             if ((cc = _edje_color_class_recursive_find(ed, tag->underline_dash_color_class)))
436
               eina_strbuf_append_printf(txt, " underline_dash_color=#%02x%02x%02x%02x", cc->r,  cc->g,  cc->b,  cc->a);
437
          }
438
        if (tag->glow_color_class)
439
          {
440
             if ((cc = _edje_color_class_recursive_find(ed, tag->glow_color_class)))
441
               eina_strbuf_append_printf(txt, " glow_color=#%02x%02x%02x%02x", cc->r,  cc->g,  cc->b,  cc->a);
442
          }
443
        if (tag->glow2_color_class)
444
          {
445
             if ((cc = _edje_color_class_recursive_find(ed, tag->glow2_color_class)))
446
               eina_strbuf_append_printf(txt, " glow2_color=#%02x%02x%02x%02x", cc->r,  cc->g,  cc->b,  cc->a);
447
          }
448
        if (tag->backing_color_class)
449
          {
450
             if ((cc = _edje_color_class_recursive_find(ed, tag->backing_color_class)))
451
               eina_strbuf_append_printf(txt, " backing_color=#%02x%02x%02x%02x", cc->r,  cc->g,  cc->b,  cc->a);
452
          }
453
        if (tag->strikethrough_color_class)
454
          {
455
             if ((cc = _edje_color_class_recursive_find(ed, tag->strikethrough_color_class)))
456
               eina_strbuf_append_printf(txt, " strikethrough_color=#%02x%02x%02x%02x", cc->r,  cc->g,  cc->b,  cc->a);
457
          }
458

459
        eina_strbuf_append(txt, "'");
460
     }
461
   if (fontsource) free(fontsource);
462

463
   /* Configure the style */
464
   stl->cache = EINA_TRUE;
465
   evas_textblock_style_set(stl->style, eina_strbuf_string_get(txt));
466
   if (txt) eina_strbuf_free(txt);
467
}
468

469
static inline Edje_Style *
470
_edje_textblock_style_search(Edje *ed, const char *style)
471
{
472
   if (!style) return NULL;
473

474
   return eina_hash_find(ed->file->style_hash, style);
475
}
476

477
static inline void
478
_edje_textblock_style_observer_add(Edje_Style *stl, Efl_Observer* observer)
479
{
480
   Eina_List* l;
481
   Edje_Style_Tag *tag;
482

483
   EINA_LIST_FOREACH(stl->tags, l, tag)
484
     {
485
        if (tag->text_class)
486
          efl_observable_observer_add(_edje_text_class_member, tag->text_class, observer);
487
     }
488
}
489

490
static inline void
491
_edje_textblock_style_observer_del(Edje_Style *stl, Efl_Observer* observer)
492
{
493
   Eina_List* l;
494
   Edje_Style_Tag *tag;
495

496
   EINA_LIST_FOREACH(stl->tags, l, tag)
497
     {
498
        if (tag->text_class)
499
          efl_observable_observer_del(_edje_text_class_member, tag->text_class, observer);
500
     }
501
}
502

503
static inline void
504
_edje_textblock_style_add(Edje *ed, Edje_Style *stl)
505
{
506
   if (!stl) return;
507

508
   if (stl->readonly) return;
509

510
   _edje_textblock_style_observer_add(stl, ed->obj);
511

512
   // mark it dirty to recompute it later.
513
   stl->cache = EINA_FALSE;
514
}
515

516
static inline void
517
_edje_textblock_style_del(Edje *ed, Edje_Style *stl)
518
{
519
   if (!stl) return;
520

521
   _edje_textblock_style_observer_del(stl, ed->obj);
522
}
523

524
void
525
_edje_textblock_styles_add(Edje *ed, Edje_Real_Part *ep)
526
{
527
   Edje_Part *pt = ep->part;
528
   Edje_Part_Description_Text *desc;
529
   Edje_Style *stl = NULL;
530
   const char *style;
531
   unsigned int i;
532

533
   if (pt->type != EDJE_PART_TYPE_TEXTBLOCK) return;
534

535
   /* if text class exists in the textblock styles for this part,
536
      add the edje to the tc member list */
537
   desc = (Edje_Part_Description_Text *)pt->default_desc;
538
   style = edje_string_get(&desc->text.style);
539
   stl = _edje_textblock_style_search(ed, style);
540

541
   _edje_textblock_style_add(ed, stl);
542

543
   /* If any other classes exist add them */
544
   for (i = 0; i < pt->other.desc_count; ++i)
545
     {
546
        desc = (Edje_Part_Description_Text *)pt->other.desc[i];
547
        style = edje_string_get(&desc->text.style);
548
        stl = _edje_textblock_style_search(ed, style);
549

550
        _edje_textblock_style_add(ed, stl);
551
     }
552
}
553

554
void
555
_edje_textblock_styles_del(Edje *ed, Edje_Part *pt)
556
{
557
   Edje_Part_Description_Text *desc;
558
   Edje_Style *stl = NULL;
559
   const char *style;
560
   unsigned int i;
561

562
   if (pt->type != EDJE_PART_TYPE_TEXTBLOCK) return;
563

564
   desc = (Edje_Part_Description_Text *)pt->default_desc;
565
   style = edje_string_get(&desc->text.style);
566

567
   stl = _edje_textblock_style_search(ed, style);
568

569
   _edje_textblock_style_del(ed, stl);
570

571
   for (i = 0; i < pt->other.desc_count; ++i)
572
     {
573
        desc = (Edje_Part_Description_Text *)pt->other.desc[i];
574
        style = edje_string_get(&desc->text.style);
575
        stl = _edje_textblock_style_search(ed, style);
576

577
        _edje_textblock_style_del(ed, stl);
578
     }
579
}
580

581
/*
582
 * returns a evas_textblock style for a given style_string.
583
 * does lazy computation of the evas_textblock_style
584
 * It will compute and cache it if not computed yet and
585
 * will return the final textblock style.
586
 */
587
Evas_Textblock_Style *
588
_edje_textblock_style_get(Edje *ed, const char *style)
589
{
590
   Edje_Style *stl;
591

592
   if (!style) return NULL;
593

594
   // First search in Edje_Object styles list
595
   stl = _edje_object_textblock_styles_cache_get(ed, style);
596

597
   if (!stl)
598
     {
599
        // If not found in Edje_Object search in Edje_File styles list
600
        stl = _edje_textblock_style_search(ed, style);
601
     }
602

603
   if (!stl) return NULL;
604

605
   /* readonly style naver change */
606
   if (stl->readonly) return stl->style;
607

608
   /* if style is dirty recompute */
609
   if (!stl->cache)
610
     _edje_textblock_style_update(ed, stl);
611

612
   return stl->style;
613
}
614

615
static void
616
_edje_textblock_style_all_update_text_class(Edje *ed, const char *text_class, Eina_Bool is_object_level)
617
{
618
   Eina_List *ll, *l;
619
   Edje_Style *stl;
620
   Edje_Style *obj_stl;
621
   Edje_File *edf;
622

623
   if (!ed) return;
624
   if (!ed->file) return;
625
   if (!text_class) return;
626

627
   edf = ed->file;
628

629
   // check if there is styles in file that uses this text_class
630
   EINA_LIST_FOREACH(edf->styles, l, stl)
631
     {
632
        Edje_Style_Tag *tag;
633

634
        if (stl->readonly) continue;
635

636
        EINA_LIST_FOREACH(stl->tags, ll, tag)
637
          {
638
             if (!tag->text_class) continue;
639

640
             if (!strcmp(tag->text_class, text_class))
641
               {
642
                  if (is_object_level)
643
                    {
644
                       obj_stl = _edje_object_textblock_styles_cache_get(ed, stl->name);
645
                       if (obj_stl)
646
                         // If already in Edje styles just make it dirty
647
                         obj_stl->cache = EINA_FALSE;
648
                       else
649
                         // create a copy from it if it's not exists
650
                         _edje_object_textblock_styles_cache_add(ed, stl);
651
                    }
652
                  else
653
                    {
654
                       // just mark it dirty so the next request
655
                       // for this style will trigger recomputation.
656
                       stl->cache = EINA_FALSE;
657
                    }
658
                  // don't need to continue searching
659
                  break;
660
               }
661
          }
662
     }
663
}
664

665
/*
666
 * Finds all the styles having text class tag as text_class and
667
 * updates them in object level.
668
 */
669
void
670
_edje_object_textblock_style_all_update_text_class(Edje *ed, const char *text_class)
671
{
672
   _edje_textblock_style_all_update_text_class(ed, text_class, EINA_TRUE);
673
}
674

675
/*
676
 * Finds all the styles having text class tag as text_class and
677
 * updates them in file level.
678
 */
679
void
680
_edje_file_textblock_styles_all_update_text_class(Edje *ed, const char *text_class)
681
{
682
   _edje_textblock_style_all_update_text_class(ed, text_class, EINA_FALSE);
683
}
684

685
/* When we get to here the edje file had been read into memory
686
 * the name of the style is established as well as the name and
687
 * data for the tags.  This function will create the Evas_Style
688
 * object for each style. The style is composed of a base style
689
 * followed by a list of tags.
690
 */
691
void
692
_edje_file_textblock_style_parse_and_fix(Edje_File *edf)
693
{
694
   Eina_List *l, *ll;
695
   Edje_Style *stl;
696
   char *fontset = _edje_fontset_append_escaped;
697
   Eina_Strbuf *reparseBuffer = eina_strbuf_new();
698
   Eina_Strbuf *styleBuffer = eina_strbuf_new();
699
   char *fontsource = edf->fonts ? eina_str_escape(edf->path) : NULL;
700

701
   EINA_LIST_FOREACH(edf->styles, l, stl)
702
     {
703
        Edje_Style_Tag *tag;
704

705
        if (stl->style) break;
706

707
        stl->readonly = EINA_TRUE;
708

709
        stl->style = evas_textblock_style_new();
710
        evas_textblock_style_set(stl->style, NULL);
711

712
        eina_strbuf_reset(styleBuffer);
713
        /* Build the style from each tag */
714
        EINA_LIST_FOREACH(stl->tags, ll, tag)
715
          {
716
             if (!tag->key) continue;
717

718
             eina_strbuf_reset(reparseBuffer);
719

720
             /* Add Tag Key */
721
             eina_strbuf_append(styleBuffer, tag->key);
722
             eina_strbuf_append(styleBuffer, "='");
723

724
             _edje_format_reparse(edf, tag->value, tag, reparseBuffer);
725

726
             /* Add and Handle tag parsed data */
727
             if (eina_strbuf_length_get(reparseBuffer))
728
               {
729
                  if (edf->allocated_strings &&
730
                      eet_dictionary_string_check(eet_dictionary_get(edf->ef), tag->value) == 0)
731
                    eina_stringshare_del(tag->value);
732
                  tag->value = eina_stringshare_add(eina_strbuf_string_get(reparseBuffer));
733
                  eina_strbuf_append(styleBuffer, tag->value);
734
               }
735

736
             if (!strcmp(tag->key, "DEFAULT"))
737
               {
738
                  if (fontset)
739
                    {
740
                       eina_strbuf_append(styleBuffer, " font_fallbacks=");
741
                       eina_strbuf_append(styleBuffer, fontset);
742
                    }
743
                  if (fontsource)
744
                    {
745
                       eina_strbuf_append(styleBuffer, " font_source=");
746
                       eina_strbuf_append(styleBuffer, fontsource);
747
                    }
748
               }
749
             eina_strbuf_append(styleBuffer, "'");
750

751
             if (tag->text_class) stl->readonly = EINA_FALSE;
752
             else if (tag->color_class) stl->readonly = EINA_FALSE;
753
             else if (tag->outline_color_class) stl->readonly = EINA_FALSE;
754
             else if (tag->shadow_color_class) stl->readonly = EINA_FALSE;
755
             else if (tag->underline_color_class) stl->readonly = EINA_FALSE;
756
             else if (tag->underline2_color_class) stl->readonly = EINA_FALSE;
757
             else if (tag->underline_dash_color_class) stl->readonly = EINA_FALSE;
758
             else if (tag->glow_color_class) stl->readonly = EINA_FALSE;
759
             else if (tag->glow2_color_class) stl->readonly = EINA_FALSE;
760
             else if (tag->backing_color_class) stl->readonly = EINA_FALSE;
761
             else if (tag->strikethrough_color_class) stl->readonly = EINA_FALSE;
762
          }
763
        /* Configure the style  only if it will never change again*/
764
        if (stl->readonly)
765
          evas_textblock_style_set(stl->style, eina_strbuf_string_get(styleBuffer));
766
     }
767

768
   if (fontsource) free(fontsource);
769
   eina_strbuf_free(styleBuffer);
770
   eina_strbuf_free(reparseBuffer);
771
}
772

773
void
774
_edje_file_textblock_style_cleanup(Edje_File *edf)
775
{
776
   Edje_Style *stl;
777

778
   EINA_LIST_FREE(edf->styles, stl)
779
     {
780
        Edje_Style_Tag *tag;
781

782
        EINA_LIST_FREE(stl->tags, tag)
783
          {
784
             if (edf->allocated_strings &&
785
                 tag->value &&
786
                 eet_dictionary_string_check(eet_dictionary_get(edf->ef), tag->value) == 0)
787
               eina_stringshare_del(tag->value);
788
             if (edf->free_strings)
789
               {
790
#define STRSHRDEL(_x) if (tag->_x) eina_stringshare_del(tag->_x)
791
                  STRSHRDEL(key);
792
/*                FIXME: Find a proper way to handle it. */
793
                  STRSHRDEL(text_class);
794
                  STRSHRDEL(color_class);
795
                  STRSHRDEL(outline_color_class);
796
                  STRSHRDEL(shadow_color_class);
797
                  STRSHRDEL(underline_color_class);
798
                  STRSHRDEL(underline2_color_class);
799
                  STRSHRDEL(underline_dash_color_class);
800
                  STRSHRDEL(glow_color_class);
801
                  STRSHRDEL(glow2_color_class);
802
                  STRSHRDEL(backing_color_class);
803
                  STRSHRDEL(strikethrough_color_class);
804
                  STRSHRDEL(font);
805
               }
806
             free(tag);
807
          }
808
        if (edf->free_strings && stl->name) eina_stringshare_del(stl->name);
809
        if (stl->style) evas_textblock_style_free(stl->style);
810
        free(stl);
811
     }
812
}
813

814

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.