summaryrefslogtreecommitdiff
path: root/src/lib/edje/edje_textblock_styles.c
diff options
context:
space:
mode:
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>2021-04-28 13:14:34 +0100
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2021-04-28 13:14:34 +0100
commit9d457fcc3f5129a0b7ef115a43afcac483763954 (patch)
treea28b32fd831e7b6c71fa54ec68baa710ce6435b6 /src/lib/edje/edje_textblock_styles.c
parent74832777f4057e86e8ccca7214bd7445881f3abd (diff)
edje - color classes totally did nothing in textblock styles
this never worked... the code just was not there to look uop color classes in text styles and change/replace them. this fixes that. it implements them. it implements color_class to replace color=xxx but also supports color=cc:colorclassname (so backing_color=cc:xxx works too to specify a colorclass for a backing color, and underline and so on). so now it's implemented and actually works... it can be used. this SHOULD have alwasy worked... but hey. apoparently not. @fix
Diffstat (limited to '')
-rw-r--r--src/lib/edje/edje_textblock_styles.c156
1 files changed, 148 insertions, 8 deletions
diff --git a/src/lib/edje/edje_textblock_styles.c b/src/lib/edje/edje_textblock_styles.c
index 88d11207ea..f1461c5890 100644
--- a/src/lib/edje/edje_textblock_styles.c
+++ b/src/lib/edje/edje_textblock_styles.c
@@ -145,7 +145,7 @@ _edje_format_reparse(Edje_File *edf, const char *str, Edje_Style_Tag *tag_ret, E
145 else if (_IS_STRINGS_EQUAL(key, key_len, "text_class", 10)) 145 else if (_IS_STRINGS_EQUAL(key, key_len, "text_class", 10))
146 { 146 {
147 if (tag_ret) 147 if (tag_ret)
148 tag_ret->text_class = eina_stringshare_add(val); 148 eina_stringshare_replace(&(tag_ret->text_class), val);
149 149
150 // no need to add text_class tag to style 150 // no need to add text_class tag to style
151 // as evas_textblock_style has no idea about 151 // as evas_textblock_style has no idea about
@@ -153,6 +153,17 @@ _edje_format_reparse(Edje_File *edf, const char *str, Edje_Style_Tag *tag_ret, E
153 free(item); 153 free(item);
154 continue; 154 continue;
155 } 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 }
156 else if (_IS_STRINGS_EQUAL(key, key_len, "font_size", 9)) 167 else if (_IS_STRINGS_EQUAL(key, key_len, "font_size", 9))
157 { 168 {
158 if (tag_ret) 169 if (tag_ret)
@@ -166,7 +177,7 @@ _edje_format_reparse(Edje_File *edf, const char *str, Edje_Style_Tag *tag_ret, E
166 { 177 {
167 char buffer[120]; 178 char buffer[120];
168 snprintf(buffer, sizeof(buffer), "edje/fonts/%s", val); 179 snprintf(buffer, sizeof(buffer), "edje/fonts/%s", val);
169 tag_ret->font = eina_stringshare_add(buffer); 180 eina_stringshare_replace(&tag_ret->font, buffer);
170 if (eina_strbuf_length_get(result)) eina_strbuf_append(result, " "); 181 if (eina_strbuf_length_get(result)) eina_strbuf_append(result, " ");
171 eina_strbuf_append(result, "font="); 182 eina_strbuf_append(result, "font=");
172 eina_strbuf_append(result, buffer); 183 eina_strbuf_append(result, buffer);
@@ -178,6 +189,63 @@ _edje_format_reparse(Edje_File *edf, const char *str, Edje_Style_Tag *tag_ret, E
178 } 189 }
179 } 190 }
180 } 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
181 s2 = eina_str_escape(item); 249 s2 = eina_str_escape(item);
182 if (s2) 250 if (s2)
183 { 251 {
@@ -261,6 +329,7 @@ _edje_textblock_style_update(Edje *ed, Edje_Style *stl)
261 Eina_Strbuf *txt = NULL; 329 Eina_Strbuf *txt = NULL;
262 Edje_Style_Tag *tag; 330 Edje_Style_Tag *tag;
263 Edje_Text_Class *tc; 331 Edje_Text_Class *tc;
332 Edje_Color_Class *cc;
264 char *fontset = _edje_fontset_append_escaped, *fontsource = NULL; 333 char *fontset = _edje_fontset_append_escaped, *fontsource = NULL;
265 334
266 if (!ed->file) return; 335 if (!ed->file) return;
@@ -298,7 +367,8 @@ _edje_textblock_style_update(Edje *ed, Edje_Style *stl)
298 eina_strbuf_append(txt, "='"); 367 eina_strbuf_append(txt, "='");
299 368
300 /* Configure fonts from text class if it exists */ 369 /* Configure fonts from text class if it exists */
301 tc = _edje_text_class_find(ed, tag->text_class); 370 if (tag->text_class) tc = _edje_text_class_find(ed, tag->text_class);
371 else tc = NULL;
302 372
303 /* Add and Handle tag parsed data */ 373 /* Add and Handle tag parsed data */
304 eina_strbuf_append(txt, tag->value); 374 eina_strbuf_append(txt, tag->value);
@@ -335,6 +405,56 @@ _edje_textblock_style_update(Edje *ed, Edje_Style *stl)
335 405
336 if (sfont) free(sfont); 406 if (sfont) free(sfont);
337 } 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 }
338 458
339 eina_strbuf_append(txt, "'"); 459 eina_strbuf_append(txt, "'");
340 } 460 }
@@ -343,8 +463,7 @@ _edje_textblock_style_update(Edje *ed, Edje_Style *stl)
343 /* Configure the style */ 463 /* Configure the style */
344 stl->cache = EINA_TRUE; 464 stl->cache = EINA_TRUE;
345 evas_textblock_style_set(stl->style, eina_strbuf_string_get(txt)); 465 evas_textblock_style_set(stl->style, eina_strbuf_string_get(txt));
346 if (txt) 466 if (txt) eina_strbuf_free(txt);
347 eina_strbuf_free(txt);
348} 467}
349 468
350static inline Edje_Style * 469static inline Edje_Style *
@@ -630,6 +749,16 @@ _edje_file_textblock_style_parse_and_fix(Edje_File *edf)
630 eina_strbuf_append(styleBuffer, "'"); 749 eina_strbuf_append(styleBuffer, "'");
631 750
632 if (tag->text_class) stl->readonly = EINA_FALSE; 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;
633 } 762 }
634 /* Configure the style only if it will never change again*/ 763 /* Configure the style only if it will never change again*/
635 if (stl->readonly) 764 if (stl->readonly)
@@ -658,10 +787,21 @@ _edje_file_textblock_style_cleanup(Edje_File *edf)
658 eina_stringshare_del(tag->value); 787 eina_stringshare_del(tag->value);
659 if (edf->free_strings) 788 if (edf->free_strings)
660 { 789 {
661 if (tag->key) eina_stringshare_del(tag->key); 790#define STRSHRDEL(_x) if (tag->_x) eina_stringshare_del(tag->_x)
791 STRSHRDEL(key);
662/* FIXME: Find a proper way to handle it. */ 792/* FIXME: Find a proper way to handle it. */
663 if (tag->text_class) eina_stringshare_del(tag->text_class); 793 STRSHRDEL(text_class);
664 if (tag->font) eina_stringshare_del(tag->font); 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);
665 } 805 }
666 free(tag); 806 free(tag);
667 } 807 }