summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBowon Ryu <bowon.ryu@samsung.com>2020-07-22 19:16:32 +0900
committerWooHyun Jung <wh0705.jung@samsung.com>2020-07-22 19:16:32 +0900
commit59b9bbc496c0503ece2fa39d8d031d2933f10bc0 (patch)
tree33aadf7fb47fed51f3879b63e065a1c28e00ab02
parent534457c51d0afc9a3a50a71bb0823e786f0b1bb8 (diff)
edje_textblock: remove duplicated textblock style properties
Summary: When there is "font" and "font_size" in textblock style (already defined), If "font" and "font_size" are set using edje_text_class_set(), then "font" and "font_size" are defined duplicated in texblock style through eina_strbuf_append. Duplicate properties use memory unnecessarily, and also it is possible to cause confusion at debbuging. This patch replaces duplicate properties "font", "font_size" using eina_strbuf_replace. Test Plan: * textblock style in edc "font=Sans font_size=20 wrap=mixed text_class=TEXT_CLASS"; * edje_text_class_set in c edje_text_class_set("TEXT_CLASS", "font=DejavuSans", 40); * textblock style at runtime (BEFORE) DEFAULT='font=Sans font_size=20 wrap=mixed font_size=40.0 font=DejavuSans' * textblock style at runtime (AFTER) DEFAULT='font=DejavuSans font_size=40 wrap=mixed' Reviewers: subodh6129, woohyun, ali.alzyod Reviewed By: ali.alzyod Subscribers: cedric, #reviewers, #committers Tags: #efl Differential Revision: https://phab.enlightenment.org/D11962
-rw-r--r--src/lib/edje/edje_textblock_styles.c62
1 files changed, 54 insertions, 8 deletions
diff --git a/src/lib/edje/edje_textblock_styles.c b/src/lib/edje/edje_textblock_styles.c
index 340e77abbc..88d11207ea 100644
--- a/src/lib/edje/edje_textblock_styles.c
+++ b/src/lib/edje/edje_textblock_styles.c
@@ -1,4 +1,5 @@
1#include "edje_private.h" 1#include "edje_private.h"
2#include <ctype.h>
2 3
3void _edje_textblock_style_update(Edje *ed, Edje_Style *stl); 4void _edje_textblock_style_update(Edje *ed, Edje_Style *stl);
4 5
@@ -194,6 +195,57 @@ _edje_format_reparse(Edje_File *edf, const char *str, Edje_Style_Tag *tag_ret, E
194 } 195 }
195} 196}
196 197
198static void
199_edje_textblock_tag_update(Eina_Strbuf *style, const char *key, const char *new_tag)
200{
201 char *ptr = strstr(eina_strbuf_string_get(style), key);
202 char *last = NULL;
203
204 while (ptr != NULL)
205 {
206 last = ptr;
207 ptr = strstr(ptr + 1, key);
208 }
209
210 if (last)
211 {
212 char *tok = strdup(last);
213 int cnt = 0;
214 while (*tok && !isspace(*tok))
215 {
216 tok++;
217 cnt++;
218 }
219 if (*tok) *tok = 0;
220 tok -= cnt;
221
222 eina_strbuf_replace_last(style, tok, new_tag);
223 free(tok);
224 }
225 else
226 {
227 eina_strbuf_append(style, " ");
228 eina_strbuf_append(style, new_tag);
229 }
230}
231
232static void
233_edje_textblock_font_tag_update(Eina_Strbuf *style, const char *new_value)
234{
235 const char *font_key = "font=";
236 char new_font[256] = {0,};
237 snprintf(new_font, sizeof(new_font), "%s%s", font_key, new_value);
238 _edje_textblock_tag_update(style, font_key, new_font);
239}
240
241static void
242_edje_textblock_font_size_tag_update(Eina_Strbuf *style, double new_value)
243{
244 const char *font_size_key = "font_size=";
245 char new_font_size[32] = {0,};
246 snprintf(new_font_size, sizeof(new_font_size), "%s%.1f", font_size_key, new_value);
247 _edje_textblock_tag_update(style, font_size_key, new_font_size);
248}
197 249
198/* Update the given evas_style 250/* Update the given evas_style
199 * 251 *
@@ -269,11 +321,7 @@ _edje_textblock_style_update(Edje *ed, Edje_Style *stl)
269 double new_size = _edje_text_size_calc(tag->font_size, tc); 321 double new_size = _edje_text_size_calc(tag->font_size, tc);
270 if (!EINA_DBL_EQ(tag->font_size, new_size)) 322 if (!EINA_DBL_EQ(tag->font_size, new_size))
271 { 323 {
272 char buffer[32]; 324 _edje_textblock_font_size_tag_update(txt, new_size);
273
274 snprintf(buffer, sizeof(buffer), "%.1f", new_size);
275 eina_strbuf_append(txt, " font_size=");
276 eina_strbuf_append(txt, buffer);
277 } 325 }
278 } 326 }
279 /* Add font name last to save evas from multiple loads */ 327 /* Add font name last to save evas from multiple loads */
@@ -282,10 +330,8 @@ _edje_textblock_style_update(Edje *ed, Edje_Style *stl)
282 const char *f; 330 const char *f;
283 char *sfont = NULL; 331 char *sfont = NULL;
284 332
285 eina_strbuf_append(txt, " font=");
286
287 f = _edje_text_font_get(tag->font, tc->font, &sfont); 333 f = _edje_text_font_get(tag->font, tc->font, &sfont);
288 eina_strbuf_append_escaped(txt, f); 334 _edje_textblock_font_tag_update(txt, f);
289 335
290 if (sfont) free(sfont); 336 if (sfont) free(sfont);
291 } 337 }