diff options
Diffstat (limited to '')
-rw-r--r-- | src/lib/evas/canvas/evas_object_textblock.c | 70 | ||||
-rw-r--r-- | src/tests/evas/evas_test_textblock.c | 5 |
2 files changed, 45 insertions, 30 deletions
diff --git a/src/lib/evas/canvas/evas_object_textblock.c b/src/lib/evas/canvas/evas_object_textblock.c index 87d6664287..a3aa98e219 100644 --- a/src/lib/evas/canvas/evas_object_textblock.c +++ b/src/lib/evas/canvas/evas_object_textblock.c | |||
@@ -2936,7 +2936,7 @@ _layout_format_pop(Ctxt *c, const char *format) | |||
2936 | Eina_List *redo_nodes = NULL; | 2936 | Eina_List *redo_nodes = NULL; |
2937 | 2937 | ||
2938 | /* Generic pop, should just pop. */ | 2938 | /* Generic pop, should just pop. */ |
2939 | if (((format[0] == ' ') && !format[1]) || | 2939 | if (((format[0] == '/') && !format[1]) || |
2940 | !format[0]) | 2940 | !format[0]) |
2941 | { | 2941 | { |
2942 | _format_unref_free(c->obj, fmt); | 2942 | _format_unref_free(c->obj, fmt); |
@@ -2962,7 +2962,7 @@ _layout_format_pop(Ctxt *c, const char *format) | |||
2962 | * starting tag, and the starting tag's next char is either | 2962 | * starting tag, and the starting tag's next char is either |
2963 | * NULL or white. Skip the starting '+'. */ | 2963 | * NULL or white. Skip the starting '+'. */ |
2964 | if (_FORMAT_IS_CLOSER_OF( | 2964 | if (_FORMAT_IS_CLOSER_OF( |
2965 | fmt->fnode->orig_format, format, len)) | 2965 | fmt->fnode->orig_format, format + 1, len - 1)) |
2966 | { | 2966 | { |
2967 | _format_unref_free(c->obj, fmt); | 2967 | _format_unref_free(c->obj, fmt); |
2968 | break; | 2968 | break; |
@@ -4993,7 +4993,7 @@ _format_changes_invalidate_text_nodes(Ctxt *c) | |||
4993 | size_t fstr_len; | 4993 | size_t fstr_len; |
4994 | fstr_len = strlen(fstr); | 4994 | fstr_len = strlen(fstr); |
4995 | /* Generic popper, just pop */ | 4995 | /* Generic popper, just pop */ |
4996 | if (((fstr[0] == ' ') && !fstr[1]) || !fstr[0]) | 4996 | if (((fstr[0] == '/') && !fstr[1]) || !fstr[0]) |
4997 | { | 4997 | { |
4998 | fstack = eina_list_remove_list(fstack, fstack); | 4998 | fstack = eina_list_remove_list(fstack, fstack); |
4999 | balance--; | 4999 | balance--; |
@@ -5007,7 +5007,7 @@ _format_changes_invalidate_text_nodes(Ctxt *c) | |||
5007 | EINA_LIST_FOREACH(fstack, i, fnode2) | 5007 | EINA_LIST_FOREACH(fstack, i, fnode2) |
5008 | { | 5008 | { |
5009 | if (_FORMAT_IS_CLOSER_OF( | 5009 | if (_FORMAT_IS_CLOSER_OF( |
5010 | fnode2->orig_format, fstr, fstr_len)) | 5010 | fnode2->orig_format, fstr + 1, fstr_len - 1)) |
5011 | { | 5011 | { |
5012 | fstack = eina_list_remove_list(fstack, i); | 5012 | fstack = eina_list_remove_list(fstack, i); |
5013 | break; | 5013 | break; |
@@ -5901,21 +5901,11 @@ _textblock_style_generic_set(Evas_Object *eo_obj, Evas_Textblock_Style *ts, | |||
5901 | const char *match; | 5901 | const char *match; |
5902 | size_t format_len = eina_stringshare_strlen(fnode->orig_format); | 5902 | size_t format_len = eina_stringshare_strlen(fnode->orig_format); |
5903 | /* Is this safe to use alloca here? Strings might possibly get large */ | 5903 | /* Is this safe to use alloca here? Strings might possibly get large */ |
5904 | char *format = alloca(format_len + 2); | ||
5905 | 5904 | ||
5906 | if (!fnode->opener) | 5905 | if (fnode->own_closer) |
5907 | { | 5906 | format_len--; |
5908 | format[0] = '/'; | ||
5909 | format[1] = '\0'; | ||
5910 | } | ||
5911 | else | ||
5912 | { | ||
5913 | format[0] = '\0'; | ||
5914 | } | ||
5915 | |||
5916 | strcat(format, fnode->orig_format); | ||
5917 | 5907 | ||
5918 | match = _textblock_format_node_from_style_tag(o, fnode, format, | 5908 | match = _textblock_format_node_from_style_tag(o, fnode, fnode->orig_format, |
5919 | format_len); | 5909 | format_len); |
5920 | 5910 | ||
5921 | if (match && fnode->format && strcmp(match, fnode->format)) | 5911 | if (match && fnode->format && strcmp(match, fnode->format)) |
@@ -6401,11 +6391,7 @@ _markup_get_format_append(Eina_Strbuf *txt, Evas_Object_Textblock_Node_Format *f | |||
6401 | 6391 | ||
6402 | // FIXME: need to escape | 6392 | // FIXME: need to escape |
6403 | s = fnode->orig_format; | 6393 | s = fnode->orig_format; |
6404 | if (!fnode->opener && !fnode->own_closer) | ||
6405 | eina_strbuf_append_char(txt, '/'); | ||
6406 | eina_strbuf_append(txt, s); | 6394 | eina_strbuf_append(txt, s); |
6407 | if (fnode->own_closer) | ||
6408 | eina_strbuf_append_char(txt, '/'); | ||
6409 | } | 6395 | } |
6410 | eina_strbuf_append_char(txt, '>'); | 6396 | eina_strbuf_append_char(txt, '>'); |
6411 | } | 6397 | } |
@@ -7077,7 +7063,7 @@ _evas_textblock_node_format_remove_pair(Eo *eo_obj, Evas_Textblock_Data *o, Evas | |||
7077 | size_t fstr_len; | 7063 | size_t fstr_len; |
7078 | fstr_len = strlen(fstr); | 7064 | fstr_len = strlen(fstr); |
7079 | /* Generic popper, just pop */ | 7065 | /* Generic popper, just pop */ |
7080 | if (((fstr[0] == ' ') && !fstr[1]) || !fstr[0]) | 7066 | if (((fstr[0] == '/') && !fstr[1]) || !fstr[0]) |
7081 | { | 7067 | { |
7082 | fstack = eina_list_remove_list(fstack, fstack); | 7068 | fstack = eina_list_remove_list(fstack, fstack); |
7083 | if (!fstack) | 7069 | if (!fstack) |
@@ -7095,7 +7081,7 @@ _evas_textblock_node_format_remove_pair(Eo *eo_obj, Evas_Textblock_Data *o, Evas | |||
7095 | EINA_LIST_FOREACH(fstack, i, fnode) | 7081 | EINA_LIST_FOREACH(fstack, i, fnode) |
7096 | { | 7082 | { |
7097 | if (_FORMAT_IS_CLOSER_OF( | 7083 | if (_FORMAT_IS_CLOSER_OF( |
7098 | fnode->orig_format, fstr, fstr_len)) | 7084 | fnode->orig_format, fstr + 1, fstr_len - 1)) |
7099 | { | 7085 | { |
7100 | /* Last one, this is our item! */ | 7086 | /* Last one, this is our item! */ |
7101 | if (!eina_list_next(i)) | 7087 | if (!eina_list_next(i)) |
@@ -7723,7 +7709,7 @@ _evas_textblock_node_format_remove_matching(Evas_Textblock_Data *o, | |||
7723 | size_t fstr_len; | 7709 | size_t fstr_len; |
7724 | fstr_len = strlen(fstr); | 7710 | fstr_len = strlen(fstr); |
7725 | /* Generic popper, just pop (if there's anything to pop). */ | 7711 | /* Generic popper, just pop (if there's anything to pop). */ |
7726 | if (formats && (((fstr[0] == ' ') && !fstr[1]) || !fstr[0])) | 7712 | if (formats && (((fstr[0] == '/') && !fstr[1]) || !fstr[0])) |
7727 | { | 7713 | { |
7728 | fnode = eina_list_data_get(formats); | 7714 | fnode = eina_list_data_get(formats); |
7729 | formats = eina_list_remove_list(formats, formats); | 7715 | formats = eina_list_remove_list(formats, formats); |
@@ -7738,7 +7724,7 @@ _evas_textblock_node_format_remove_matching(Evas_Textblock_Data *o, | |||
7738 | EINA_LIST_FOREACH_SAFE(formats, i, next, fnode) | 7724 | EINA_LIST_FOREACH_SAFE(formats, i, next, fnode) |
7739 | { | 7725 | { |
7740 | if (_FORMAT_IS_CLOSER_OF( | 7726 | if (_FORMAT_IS_CLOSER_OF( |
7741 | fnode->orig_format, fstr, fstr_len)) | 7727 | fnode->orig_format, fstr + 1, fstr_len - 1)) |
7742 | { | 7728 | { |
7743 | fnode = eina_list_data_get(i); | 7729 | fnode = eina_list_data_get(i); |
7744 | formats = eina_list_remove_list(formats, i); | 7730 | formats = eina_list_remove_list(formats, i); |
@@ -8519,6 +8505,7 @@ _evas_textblock_node_format_new(Evas_Textblock_Data *o, const char *_format) | |||
8519 | if ((format_len > 0) && format[format_len - 1] == '>') | 8505 | if ((format_len > 0) && format[format_len - 1] == '>') |
8520 | { | 8506 | { |
8521 | format_len--; /* We don't care about '>' */ | 8507 | format_len--; /* We don't care about '>' */ |
8508 | n->orig_format = eina_stringshare_add_length(format, format_len); | ||
8522 | /* Check if it closes itself, i.e. one of the following: | 8509 | /* Check if it closes itself, i.e. one of the following: |
8523 | * 1. Ends with a "/" e.g. "<my_tag/>" | 8510 | * 1. Ends with a "/" e.g. "<my_tag/>" |
8524 | * 2. Is a paragraph separator */ | 8511 | * 2. Is a paragraph separator */ |
@@ -8562,8 +8549,6 @@ _evas_textblock_node_format_new(Evas_Textblock_Data *o, const char *_format) | |||
8562 | } | 8549 | } |
8563 | } | 8550 | } |
8564 | 8551 | ||
8565 | n->orig_format = eina_stringshare_add_length(format, format_len); | ||
8566 | |||
8567 | if (!pre_stripped_format) | 8552 | if (!pre_stripped_format) |
8568 | pre_stripped_format = n->orig_format; | 8553 | pre_stripped_format = n->orig_format; |
8569 | } | 8554 | } |
@@ -8591,12 +8576,23 @@ _evas_textblock_node_format_new(Evas_Textblock_Data *o, const char *_format) | |||
8591 | /* Strip format */ | 8576 | /* Strip format */ |
8592 | { | 8577 | { |
8593 | const char *tmp = pre_stripped_format; | 8578 | const char *tmp = pre_stripped_format; |
8579 | int len = strlen(tmp); | ||
8594 | if ((*tmp == '+') || (*tmp == '-')) | 8580 | if ((*tmp == '+') || (*tmp == '-')) |
8595 | { | 8581 | { |
8582 | len--; | ||
8596 | tmp++; | 8583 | tmp++; |
8597 | while (*tmp == ' ') tmp++; | 8584 | while (*tmp == ' ') tmp++; |
8598 | } | 8585 | } |
8599 | n->format = eina_stringshare_add(tmp); | 8586 | if (tmp[len - 1] == '/') |
8587 | { | ||
8588 | len--; | ||
8589 | } | ||
8590 | else if (tmp[0] == '/') | ||
8591 | { | ||
8592 | len--; | ||
8593 | tmp++; | ||
8594 | } | ||
8595 | n->format = eina_stringshare_add_length(tmp, len); | ||
8600 | } | 8596 | } |
8601 | format = n->format; | 8597 | format = n->format; |
8602 | 8598 | ||
@@ -9286,11 +9282,25 @@ evas_textblock_node_format_text_get(const Evas_Object_Textblock_Node_Format *fmt | |||
9286 | { | 9282 | { |
9287 | static char *ret = NULL; | 9283 | static char *ret = NULL; |
9288 | char *tmp; | 9284 | char *tmp; |
9285 | const char *stripped; | ||
9286 | size_t stripped_len; | ||
9289 | 9287 | ||
9290 | if (!fmt) return NULL; | 9288 | if (!fmt) return NULL; |
9291 | 9289 | ||
9292 | if (ret) free(ret); | 9290 | if (ret) free(ret); |
9293 | ret = malloc(strlen(fmt->orig_format) + 2 + 1); | 9291 | stripped = fmt->orig_format; |
9292 | stripped_len = strlen(fmt->orig_format); | ||
9293 | if (stripped[stripped_len - 1] == '/') | ||
9294 | { | ||
9295 | stripped_len--; | ||
9296 | } | ||
9297 | else if (stripped[0] == '/') | ||
9298 | { | ||
9299 | stripped++; | ||
9300 | stripped_len--; | ||
9301 | } | ||
9302 | |||
9303 | ret = calloc(stripped_len + 2 + 1, sizeof(char)); | ||
9294 | tmp = ret; | 9304 | tmp = ret; |
9295 | 9305 | ||
9296 | if (fmt->opener && !fmt->own_closer) | 9306 | if (fmt->opener && !fmt->own_closer) |
@@ -9303,7 +9313,7 @@ evas_textblock_node_format_text_get(const Evas_Object_Textblock_Node_Format *fmt | |||
9303 | *(tmp++) = '-'; | 9313 | *(tmp++) = '-'; |
9304 | *(tmp++) = ' '; | 9314 | *(tmp++) = ' '; |
9305 | } | 9315 | } |
9306 | strcpy(tmp, fmt->orig_format); | 9316 | strncpy(tmp, stripped, stripped_len); |
9307 | return ret; | 9317 | return ret; |
9308 | } | 9318 | } |
9309 | 9319 | ||
diff --git a/src/tests/evas/evas_test_textblock.c b/src/tests/evas/evas_test_textblock.c index 63ba40eda6..76aede3229 100644 --- a/src/tests/evas/evas_test_textblock.c +++ b/src/tests/evas/evas_test_textblock.c | |||
@@ -2662,6 +2662,11 @@ START_TEST(evas_textblock_style) | |||
2662 | evas_object_textblock_size_formatted_get(tb, &nw, &nh); | 2662 | evas_object_textblock_size_formatted_get(tb, &nw, &nh); |
2663 | fail_if((w >= nw) || (h >= nh)); | 2663 | fail_if((w >= nw) || (h >= nh)); |
2664 | 2664 | ||
2665 | /* Style tag test */ | ||
2666 | buf = "Test <br><br/><ps><ps/><tab><tab/>"; | ||
2667 | evas_object_textblock_text_markup_set(tb, buf); | ||
2668 | fail_if(strcmp(buf, evas_object_textblock_text_markup_get(tb))); | ||
2669 | |||
2665 | /* Style padding. */ | 2670 | /* Style padding. */ |
2666 | evas_object_textblock_text_markup_set(tb, "Test"); | 2671 | evas_object_textblock_text_markup_set(tb, "Test"); |
2667 | evas_object_textblock_style_insets_get(tb, &l, &r, &t, &b); | 2672 | evas_object_textblock_style_insets_get(tb, &l, &r, &t, &b); |