9 #include "evas_suite.h"
12 #include "evas_tests_helpers.h"
14 /* Functions defined in evas_object_textblock.c */
16 _evas_textblock_check_item_node_link(Evas_Object *obj);
18 _evas_textblock_format_offset_get(const Evas_Object_Textblock_Node_Format *n);
19 /* end of functions defined in evas_object_textblock.c */
22 static const char *style_buf =
23 "DEFAULT='font=Sans font_size=10 color=#000 text_class=entry'"
25 "b='+ font=Sans:style=bold'";
27 #define START_TB_TEST() \
30 Evas_Textblock_Style *st; \
31 Evas_Textblock_Cursor *cur; \
32 evas = EVAS_TEST_INIT_EVAS(); \
33 evas_font_hinting_set(evas, EVAS_FONT_HINTING_AUTO); \
34 tb = evas_object_textblock_add(evas); \
36 evas_object_textblock_legacy_newline_set(tb, EINA_FALSE); \
37 st = evas_textblock_style_new(); \
39 evas_textblock_style_set(st, style_buf); \
40 fail_if(strcmp(style_buf, evas_textblock_style_get(st))); \
41 evas_object_textblock_style_set(tb, st); \
42 cur = evas_object_textblock_cursor_new(tb); \
48 #define END_TB_TEST() \
51 evas_textblock_cursor_free(cur); \
52 evas_object_del(tb); \
53 evas_textblock_style_free(st); \
59 START_TEST(evas_textblock_simple)
62 const char *buf = "Th<i>i</i>s is a <br/> te<b>s</b>t.";
63 evas_object_textblock_text_markup_set(tb, buf);
64 fail_if(strcmp(evas_object_textblock_text_markup_get(tb), buf));
69 #define _CHECK_CURSOR_COORDS() \
72 Evas_Coord cx, cy, cw, ch; \
74 ret = evas_textblock_cursor_geometry_get(cur, &cx, &cy, &cw, &ch, \
75 NULL, EVAS_TEXTBLOCK_CURSOR_UNDER); \
77 ret = evas_textblock_cursor_geometry_get(cur, &cx, &cy, &cw, &ch, \
78 NULL, EVAS_TEXTBLOCK_CURSOR_BEFORE); \
80 ret = evas_textblock_cursor_char_geometry_get(cur, \
81 &cx, &cy, &cw, &ch); \
83 ret = evas_textblock_cursor_pen_geometry_get(cur, &cx, &cy, &cw, &ch); \
85 ret = evas_textblock_cursor_line_geometry_get(cur, \
86 &cx, &cy, &cw, &ch); \
90 START_TEST(evas_textblock_cursor)
93 Evas_Coord x, y, w, h;
96 const char *buf = "This is a<br/> test.<ps/>Lets see if this works.<ps/>עוד פסקה.";
98 /* Walk the textblock using cursor_char_next */
99 evas_object_textblock_text_markup_set(tb, buf);
100 fail_if(strcmp(evas_object_textblock_text_markup_get(tb), buf));
101 len = eina_unicode_utf8_get_len(buf) - 12; /* 12 because len(<br/>) == 1 and len(<ps/>) == 1 */
102 for (i = 0 ; i < len ; i++)
104 _CHECK_CURSOR_COORDS();
106 fail_if(evas_textblock_cursor_pos_get(cur) != (int) i);
108 fail_if(!evas_textblock_cursor_char_next(cur) && (i < len - 1));
110 fail_if(evas_textblock_cursor_char_next(cur));
112 /* Jump to positions all aronud the textblock */
113 evas_textblock_cursor_pos_set(cur, -1);
114 fail_if(evas_textblock_cursor_pos_get(cur) != 0);
116 evas_textblock_cursor_pos_set(cur, len + 5);
117 fail_if(evas_textblock_cursor_pos_get(cur) != (int) len);
119 for (i = 0 ; i < len ; i++)
121 evas_textblock_cursor_pos_set(cur, i);
123 _CHECK_CURSOR_COORDS();
125 fail_if(evas_textblock_cursor_pos_get(cur) != (int) i);
128 /* Create another cursor and insert text, making sure everything
130 evas_object_textblock_clear(tb);
131 Evas_Textblock_Cursor *main_cur = evas_object_textblock_cursor_get(tb);
132 evas_textblock_cursor_copy(main_cur, cur);
133 fail_if(evas_textblock_cursor_pos_get(cur) !=
134 evas_textblock_cursor_pos_get(main_cur));
136 evas_textblock_cursor_text_prepend(main_cur, "a");
137 fail_if(evas_textblock_cursor_pos_get(cur) ==
138 evas_textblock_cursor_pos_get(main_cur));
139 evas_textblock_cursor_text_prepend(main_cur, "a");
140 fail_if(evas_textblock_cursor_pos_get(cur) ==
141 evas_textblock_cursor_pos_get(main_cur));
143 /* Insert text to a non-empty textblock */
144 evas_object_textblock_clear(tb);
145 evas_object_textblock_text_markup_set(tb, buf);
146 evas_textblock_cursor_copy(main_cur, cur);
147 fail_if(evas_textblock_cursor_pos_get(cur) !=
148 evas_textblock_cursor_pos_get(main_cur));
150 evas_textblock_cursor_text_prepend(main_cur, "a");
151 fail_if(evas_textblock_cursor_pos_get(cur) ==
152 evas_textblock_cursor_pos_get(main_cur));
153 evas_textblock_cursor_text_prepend(main_cur, "a");
154 fail_if(evas_textblock_cursor_pos_get(cur) ==
155 evas_textblock_cursor_pos_get(main_cur));
157 /* Make sure append works */
158 evas_textblock_cursor_copy(main_cur, cur);
159 fail_if(evas_textblock_cursor_pos_get(cur) !=
160 evas_textblock_cursor_pos_get(main_cur));
161 evas_textblock_cursor_text_append(main_cur, "a");
162 fail_if(evas_textblock_cursor_pos_get(cur) !=
163 evas_textblock_cursor_pos_get(main_cur));
165 /* Cursor comparison */
166 evas_textblock_cursor_pos_set(cur, 1);
167 evas_textblock_cursor_pos_set(main_cur, 2);
168 fail_if(evas_textblock_cursor_compare(cur, main_cur) != -1);
170 evas_textblock_cursor_pos_set(cur, 2);
171 evas_textblock_cursor_pos_set(main_cur, 2);
172 fail_if(evas_textblock_cursor_compare(cur, main_cur) != 0);
174 evas_textblock_cursor_pos_set(cur, 3);
175 evas_textblock_cursor_pos_set(main_cur, 2);
176 fail_if(evas_textblock_cursor_compare(cur, main_cur) != 1);
178 /* Paragraph first */
179 evas_object_textblock_text_markup_set(tb, buf);
180 for (i = 0 ; i < len ; i++)
182 evas_textblock_cursor_pos_set(cur, i);
184 evas_textblock_cursor_paragraph_first(cur);
185 fail_if(evas_textblock_cursor_pos_get(cur) != 0);
189 for (i = 0 ; i < len ; i++)
191 evas_textblock_cursor_pos_set(cur, i);
193 evas_textblock_cursor_paragraph_last(cur);
194 fail_if(evas_textblock_cursor_pos_get(cur) != (int) len);
198 evas_textblock_cursor_paragraph_last(cur);
199 fail_if(evas_textblock_cursor_paragraph_next(cur));
201 evas_textblock_cursor_paragraph_first(cur);
202 fail_if(!evas_textblock_cursor_paragraph_next(cur));
203 fail_if(!evas_textblock_cursor_paragraph_next(cur));
206 evas_textblock_cursor_paragraph_first(cur);
207 fail_if(evas_textblock_cursor_paragraph_prev(cur));
209 evas_textblock_cursor_paragraph_last(cur);
210 fail_if(!evas_textblock_cursor_paragraph_prev(cur));
211 fail_if(!evas_textblock_cursor_paragraph_prev(cur));
214 evas_textblock_cursor_paragraph_last(cur);
215 fail_if(evas_textblock_cursor_char_next(cur));
217 evas_textblock_cursor_paragraph_first(cur);
218 fail_if(!evas_textblock_cursor_char_next(cur));
219 fail_if(!evas_textblock_cursor_paragraph_next(cur));
220 fail_if(!evas_textblock_cursor_char_next(cur));
221 fail_if(!evas_textblock_cursor_paragraph_next(cur));
222 fail_if(!evas_textblock_cursor_char_next(cur));
225 evas_textblock_cursor_paragraph_first(cur);
226 fail_if(evas_textblock_cursor_char_prev(cur));
228 evas_textblock_cursor_paragraph_last(cur);
229 fail_if(!evas_textblock_cursor_char_prev(cur));
230 fail_if(!evas_textblock_cursor_paragraph_prev(cur));
231 fail_if(!evas_textblock_cursor_char_prev(cur));
233 /* Paragraph char first */
234 evas_textblock_cursor_paragraph_first(main_cur);
235 evas_textblock_cursor_paragraph_first(cur);
236 fail_if(!evas_textblock_cursor_char_next(cur));
237 evas_textblock_cursor_paragraph_char_first(cur);
238 fail_if(evas_textblock_cursor_compare(cur, main_cur));
240 /* Paragraph char last */
241 evas_textblock_cursor_paragraph_last(main_cur);
242 evas_textblock_cursor_paragraph_last(cur);
243 fail_if(!evas_textblock_cursor_char_prev(cur));
244 evas_textblock_cursor_paragraph_char_last(cur);
245 fail_if(evas_textblock_cursor_compare(cur, main_cur));
247 /* Line char first */
248 evas_textblock_cursor_paragraph_first(main_cur);
249 evas_textblock_cursor_paragraph_first(cur);
250 fail_if(!evas_textblock_cursor_char_next(cur));
251 evas_textblock_cursor_line_char_first(cur);
252 fail_if(evas_textblock_cursor_compare(cur, main_cur));
254 evas_textblock_cursor_pos_set(cur, 12);
255 evas_textblock_cursor_line_char_first(cur);
256 fail_if(evas_textblock_cursor_pos_get(cur) != 10);
258 /* Line char first */
259 evas_textblock_cursor_paragraph_last(main_cur);
260 evas_textblock_cursor_paragraph_last(cur);
261 fail_if(!evas_textblock_cursor_char_prev(cur));
262 evas_textblock_cursor_line_char_last(cur);
263 fail_if(evas_textblock_cursor_compare(cur, main_cur));
265 evas_textblock_cursor_pos_set(cur, 12);
266 evas_textblock_cursor_line_char_last(cur);
267 fail_if(evas_textblock_cursor_pos_get(cur) != 16);
270 evas_textblock_cursor_paragraph_first(main_cur);
271 evas_textblock_cursor_paragraph_last(cur);
273 fail_if(!evas_textblock_cursor_line_set(cur, 0));
274 fail_if(evas_textblock_cursor_compare(cur, main_cur));
275 fail_if(!evas_textblock_cursor_line_set(cur, 1));
276 fail_if(!evas_textblock_cursor_line_set(cur, 2));
277 fail_if(!evas_textblock_cursor_line_set(cur, 3));
279 fail_if(evas_textblock_cursor_line_set(cur, -1));
280 fail_if(evas_textblock_cursor_line_set(cur, 99));
282 /* Paragraph text get */
283 evas_textblock_cursor_paragraph_first(cur);
284 fail_if(strcmp(evas_textblock_cursor_paragraph_text_get(cur),
285 "This is a<br/> test."));
286 evas_textblock_cursor_paragraph_next(cur);
287 fail_if(strcmp(evas_textblock_cursor_paragraph_text_get(cur),
288 "Lets see if this works."));
289 evas_textblock_cursor_paragraph_next(cur);
290 fail_if(strcmp(evas_textblock_cursor_paragraph_text_get(cur),
293 /* Paragraph length get */
294 evas_textblock_cursor_paragraph_first(cur);
295 /* -4 because len(<br/>) == 1 */
296 fail_if(evas_textblock_cursor_paragraph_text_length_get(cur) !=
297 eina_unicode_utf8_get_len("This is a<br/> test.") - 4);
298 evas_textblock_cursor_paragraph_next(cur);
299 fail_if(evas_textblock_cursor_paragraph_text_length_get(cur) !=
300 eina_unicode_utf8_get_len("Lets see if this works."));
301 evas_textblock_cursor_paragraph_next(cur);
302 fail_if(evas_textblock_cursor_paragraph_text_length_get(cur) !=
303 eina_unicode_utf8_get_len("עוד פסקה."));
305 /* Cursor content get */
306 evas_textblock_cursor_pos_set(cur, 0);
307 fail_if(strcmp(evas_textblock_cursor_content_get(cur), "T"));
308 evas_textblock_cursor_pos_set(cur, 9);
309 fail_if(strcmp(evas_textblock_cursor_content_get(cur), "<br/>"));
310 evas_textblock_cursor_pos_set(cur, 43);
311 fail_if(strcmp(evas_textblock_cursor_content_get(cur), "ד"));
314 for (i = 0 ; i < len ; i++)
316 evas_textblock_cursor_pos_set(cur, i);
317 evas_textblock_cursor_copy(cur, main_cur);
318 evas_textblock_cursor_line_char_last(main_cur);
320 if (!evas_textblock_cursor_compare(cur, main_cur))
322 fail_if(!evas_textblock_cursor_eol_get(cur));
326 fail_if(evas_textblock_cursor_eol_get(cur));
330 /* Format positions */
331 const Evas_Object_Textblock_Node_Format *fnode;
332 fnode = evas_textblock_node_format_first_get(tb);
334 evas_textblock_cursor_at_format_set(cur, fnode);
335 evas_textblock_cursor_copy(cur, main_cur);
336 fail_if(evas_textblock_cursor_pos_get(cur) != 9);
337 fail_if(evas_textblock_cursor_format_get(cur) != fnode);
339 fnode = evas_textblock_node_format_next_get(fnode);
341 evas_textblock_cursor_at_format_set(cur, fnode);
342 fail_if(evas_textblock_cursor_pos_get(cur) != 16);
343 fail_if(evas_textblock_cursor_format_get(cur) != fnode);
344 evas_textblock_cursor_format_next(main_cur);
345 fail_if(evas_textblock_cursor_compare(main_cur, cur));
347 fnode = evas_textblock_node_format_prev_get(fnode);
349 evas_textblock_cursor_at_format_set(cur, fnode);
350 fail_if(evas_textblock_cursor_pos_get(cur) != 9);
351 fail_if(evas_textblock_cursor_format_get(cur) != fnode);
352 evas_textblock_cursor_format_prev(main_cur);
353 fail_if(evas_textblock_cursor_compare(main_cur, cur));
355 evas_textblock_cursor_char_next(main_cur);
356 evas_textblock_cursor_format_prev(main_cur);
357 fail_if(evas_textblock_cursor_compare(main_cur, cur));
360 evas_object_textblock_text_markup_set(tb, buf);
362 /* Check that pen geometry and getting char at coord are in sync. */
367 /* Check if it's the last char, if it is, break, otherwise, go back
368 * to the current char because our test advanced the cursor. */
369 if (!evas_textblock_cursor_char_next(cur))
372 evas_textblock_cursor_char_prev(cur);
374 cur_pos = evas_textblock_cursor_pos_get(cur);
375 evas_textblock_cursor_pen_geometry_get(cur, &x, &y, &w, &h);
376 evas_textblock_cursor_char_coord_set(cur, x + (w / 2), y + (h / 2));
377 fail_if(cur_pos != evas_textblock_cursor_pos_get(cur));
379 while (evas_textblock_cursor_char_next(cur));
381 /* Try positions before the first paragraph, and after the last paragraph */
382 evas_object_textblock_text_markup_set(tb, buf);
383 evas_object_textblock_size_native_get(tb, &nw, &nh);
384 evas_object_resize(tb, nw, nh);
385 evas_textblock_cursor_pos_set(cur, 5);
386 evas_textblock_cursor_char_coord_set(cur, nw / 2,
388 evas_textblock_cursor_paragraph_first(main_cur);
389 fail_if(evas_textblock_cursor_compare(cur, main_cur));
391 evas_textblock_cursor_pos_set(cur, 5);
392 evas_textblock_cursor_char_coord_set(cur, nw / 2,
394 evas_textblock_cursor_paragraph_last(main_cur);
395 fail_if(evas_textblock_cursor_compare(cur, main_cur));
397 /* Try positions beyond the left/right limits of lines. */
398 for (i = 0 ; i < 2 ; i++)
400 evas_textblock_cursor_line_set(cur, i);
401 evas_textblock_cursor_line_geometry_get(cur, &x, &y, &w, &h);
403 evas_textblock_cursor_pos_set(main_cur, 5);
404 evas_textblock_cursor_char_coord_set(main_cur, x - 50, y);
405 fail_if(evas_textblock_cursor_compare(main_cur, cur));
407 evas_textblock_cursor_line_char_last(cur);
408 evas_textblock_cursor_pos_set(main_cur, 5);
409 evas_textblock_cursor_char_coord_set(main_cur, x + w + 50, y);
410 fail_if(evas_textblock_cursor_compare(main_cur, cur));
414 evas_object_textblock_text_markup_set(tb,
415 "testנסיוןtestנסיון<ps/>"
416 "נסיוןtestנסיוןtest<ps/>"
418 "נסיוןtestנסיון<ps/>"
419 "testנסיון<br/>נסיון<ps/>"
423 for (i = 0 ; i < 8 ; i++)
425 evas_textblock_cursor_line_set(cur, i);
426 evas_textblock_cursor_line_geometry_get(cur, &x, &y, &w, &h);
434 evas_textblock_cursor_pos_set(main_cur, 7);
435 evas_textblock_cursor_char_coord_set(main_cur, x - 50, y);
436 fail_if(evas_textblock_cursor_compare(main_cur, cur));
438 evas_textblock_cursor_line_char_last(cur);
439 evas_textblock_cursor_pos_set(main_cur, 7);
440 evas_textblock_cursor_char_coord_set(main_cur, x + w + 50, y);
441 fail_if(evas_textblock_cursor_compare(main_cur, cur));
448 evas_textblock_cursor_line_char_last(cur);
449 evas_textblock_cursor_pos_set(main_cur, 7);
450 evas_textblock_cursor_char_coord_set(main_cur, x - 50, y);
451 fail_if(evas_textblock_cursor_compare(main_cur, cur));
453 evas_textblock_cursor_line_char_first(cur);
454 evas_textblock_cursor_pos_set(main_cur, 7);
455 evas_textblock_cursor_char_coord_set(main_cur, x + w + 50, y);
456 fail_if(evas_textblock_cursor_compare(main_cur, cur));
462 evas_object_textblock_text_markup_set(tb, buf);
463 /* Testing line geometry.*/
465 Evas_Coord lx, ly, lw, lh;
466 Evas_Coord plx, ply, plw, plh;
467 evas_textblock_cursor_line_set(cur, 0);
468 evas_textblock_cursor_copy(cur, main_cur);
469 evas_textblock_cursor_line_char_last(main_cur);
470 evas_textblock_cursor_line_geometry_get(cur, &plx, &ply, &plw, &plh);
472 while (evas_textblock_cursor_compare(cur, main_cur) <= 0)
474 evas_textblock_cursor_pen_geometry_get(cur, &x, &y, &w, &h);
475 fail_if(0 != evas_textblock_cursor_line_geometry_get(
476 cur, &lx, &ly, &lw, &lh));
477 fail_if((x < lx) || (x + w > lx + lw) ||
478 (y < ly) || (y + h > ly + lh));
479 fail_if((lx != plx) || (ly != ply) || (lw != plw) || (lh != plh));
485 evas_textblock_cursor_char_next(cur);
488 evas_textblock_cursor_line_set(cur, 1);
489 evas_textblock_cursor_copy(cur, main_cur);
490 evas_textblock_cursor_line_char_last(main_cur);
491 evas_textblock_cursor_line_geometry_get(cur, &plx, &ply, &plw, &plh);
493 while (evas_textblock_cursor_compare(cur, main_cur) <= 0)
495 evas_textblock_cursor_pen_geometry_get(cur, &x, &y, &w, &h);
496 fail_if(1 != evas_textblock_cursor_line_geometry_get(
497 cur, &lx, &ly, &lw, &lh));
498 fail_if((x < lx) || (x + w > lx + lw) ||
499 (y < ly) || (y + h > ly + lh));
500 fail_if((lx != plx) || (ly != ply) || (lw != plw) || (lh != plh));
506 evas_textblock_cursor_char_next(cur);
509 evas_textblock_cursor_paragraph_last(cur);
510 evas_textblock_cursor_line_set(cur, 0);
511 evas_textblock_cursor_line_geometry_get(cur, &plx, &ply, &plw, &plh);
512 evas_object_textblock_line_number_geometry_get(tb, 0,
514 fail_if((lx != plx) || (ly != ply) || (lw != plw) || (lh != plh));
515 fail_if(0 != evas_textblock_cursor_line_coord_set(cur, ly + (lh / 2)));
517 evas_textblock_cursor_line_set(cur, 1);
518 evas_textblock_cursor_line_geometry_get(cur, &plx, &ply, &plw, &plh);
519 evas_object_textblock_line_number_geometry_get(tb, 1,
521 fail_if((lx != plx) || (ly != ply) || (lw != plw) || (lh != plh));
522 fail_if(1 != evas_textblock_cursor_line_coord_set(cur, ly + (lh / 2)));
524 /* Before the start of the textblock */
525 fail_if(0 != evas_textblock_cursor_line_coord_set(cur, -50));
526 fail_if(3 != evas_textblock_cursor_line_coord_set(cur, 100000));
528 /* And now with a valigned textblock. */
529 evas_object_textblock_text_markup_set(tb, buf);
530 evas_object_textblock_size_native_get(tb, &nw, &nh);
531 evas_object_resize(tb, 2 * nw, 2 * nh);
533 evas_object_textblock_valign_set(tb, 0.5);
534 evas_textblock_cursor_paragraph_first(cur);
535 evas_textblock_cursor_pen_geometry_get(cur, &x, &y, &w, &h);
538 evas_textblock_cursor_paragraph_last(main_cur);
539 evas_textblock_cursor_char_coord_set(main_cur, x + w, y / 2);
540 fail_if(evas_textblock_cursor_compare(main_cur, cur));
542 evas_textblock_cursor_paragraph_last(main_cur);
543 evas_textblock_cursor_line_coord_set(main_cur, y / 2);
544 fail_if(evas_textblock_cursor_compare(main_cur, cur));
546 /* Fail if they are equal, i.e if it for some reason thinks it should
548 evas_textblock_cursor_paragraph_first(main_cur);
549 evas_textblock_cursor_paragraph_last(cur);
550 evas_textblock_cursor_char_coord_set(main_cur, x + w, nh + 1);
551 fail_if(!evas_textblock_cursor_compare(main_cur, cur));
553 evas_textblock_cursor_paragraph_first(main_cur);
554 evas_textblock_cursor_paragraph_last(cur);
555 evas_textblock_cursor_line_coord_set(main_cur, nh + 1);
556 fail_if(!evas_textblock_cursor_compare(main_cur, cur));
558 /* Fail if it doesn't go to the end. */
559 evas_textblock_cursor_paragraph_last(cur);
560 evas_textblock_cursor_paragraph_first(main_cur);
561 evas_textblock_cursor_char_coord_set(main_cur, x + w, (2 * nh) - 1);
562 fail_if(evas_textblock_cursor_compare(main_cur, cur));
564 evas_textblock_cursor_paragraph_first(main_cur);
565 evas_textblock_cursor_line_coord_set(main_cur, (2 * nh) - 1);
566 fail_if(evas_textblock_cursor_compare(main_cur, cur));
570 const char *buf_wb = "a This is_a t:e.s't a";
571 evas_object_textblock_text_markup_set(tb, buf_wb);
574 evas_textblock_cursor_pos_set(cur, 3);
575 evas_textblock_cursor_word_start(cur);
576 fail_if(2 != evas_textblock_cursor_pos_get(cur));
577 evas_textblock_cursor_word_end(cur);
578 fail_if(5 != evas_textblock_cursor_pos_get(cur));
580 evas_textblock_cursor_pos_set(cur, 13);
581 evas_textblock_cursor_word_end(cur);
582 fail_if(18 != evas_textblock_cursor_pos_get(cur));
583 evas_textblock_cursor_word_start(cur);
584 fail_if(12 != evas_textblock_cursor_pos_get(cur));
585 evas_textblock_cursor_word_start(cur);
586 fail_if(12 != evas_textblock_cursor_pos_get(cur));
587 evas_textblock_cursor_word_start(cur);
588 fail_if(12 != evas_textblock_cursor_pos_get(cur));
589 evas_textblock_cursor_word_end(cur);
590 fail_if(18 != evas_textblock_cursor_pos_get(cur));
591 evas_textblock_cursor_word_end(cur);
592 fail_if(18 != evas_textblock_cursor_pos_get(cur));
599 START_TEST(evas_textblock_format_removal)
603 const char *buf = "Th<b>is a<a>tes</a>st</b>.";
604 const Evas_Object_Textblock_Node_Format *fnode;
605 Evas_Textblock_Cursor *main_cur = evas_object_textblock_cursor_get(tb);
606 evas_object_textblock_text_markup_set(tb, buf);
608 /* Remove the "b" pair. */
609 fnode = evas_textblock_node_format_first_get(tb);
610 evas_textblock_node_format_remove_pair(tb,
611 (Evas_Object_Textblock_Node_Format *) fnode);
613 fnode = evas_textblock_node_format_first_get(tb);
615 fail_if(strcmp(evas_textblock_node_format_text_get(fnode),
618 fnode = evas_textblock_node_format_next_get(fnode);
620 fail_if(strcmp(evas_textblock_node_format_text_get(fnode),
623 fnode = evas_textblock_node_format_next_get(fnode);
626 /* Now also remove the a pair */
627 fnode = evas_textblock_node_format_first_get(tb);
628 evas_textblock_node_format_remove_pair(tb,
629 (Evas_Object_Textblock_Node_Format *) fnode);
630 fnode = evas_textblock_node_format_first_get(tb);
633 /* Remove the "a" pair. */
634 evas_object_textblock_text_markup_set(tb, buf);
636 fnode = evas_textblock_node_format_first_get(tb);
637 fnode = evas_textblock_node_format_next_get(fnode);
638 evas_textblock_node_format_remove_pair(tb,
639 (Evas_Object_Textblock_Node_Format *) fnode);
641 fnode = evas_textblock_node_format_first_get(tb);
643 fail_if(strcmp(evas_textblock_node_format_text_get(fnode),
646 fnode = evas_textblock_node_format_next_get(fnode);
648 fail_if(strcmp(evas_textblock_node_format_text_get(fnode),
651 fnode = evas_textblock_node_format_next_get(fnode);
654 /* Now also remove the b pair */
655 fnode = evas_textblock_node_format_first_get(tb);
656 evas_textblock_node_format_remove_pair(tb,
657 (Evas_Object_Textblock_Node_Format *) fnode);
658 fnode = evas_textblock_node_format_first_get(tb);
661 /* Now remove formats by removing text */
662 evas_object_textblock_text_markup_set(tb, buf);
663 evas_textblock_cursor_pos_set(cur, 6);
664 evas_textblock_cursor_char_delete(cur);
665 evas_textblock_cursor_char_delete(cur);
666 evas_textblock_cursor_char_delete(cur);
667 /* Only b formats should remain */
668 fnode = evas_textblock_node_format_first_get(tb);
670 fail_if(strcmp(evas_textblock_node_format_text_get(fnode),
673 fnode = evas_textblock_node_format_next_get(fnode);
675 fail_if(strcmp(evas_textblock_node_format_text_get(fnode),
678 fnode = evas_textblock_node_format_next_get(fnode);
681 /* No formats should remain. */
682 evas_textblock_cursor_pos_set(cur, 2);
683 evas_textblock_cursor_char_delete(cur);
684 evas_textblock_cursor_char_delete(cur);
685 evas_textblock_cursor_char_delete(cur);
686 evas_textblock_cursor_char_delete(cur);
687 evas_textblock_cursor_char_delete(cur);
688 evas_textblock_cursor_char_delete(cur);
689 fnode = evas_textblock_node_format_first_get(tb);
692 /* Try to remove the formats in a way that shouldn't remove them */
693 evas_object_textblock_text_markup_set(tb, buf);
694 evas_textblock_cursor_pos_set(cur, 7);
695 evas_textblock_cursor_char_delete(cur);
696 evas_textblock_cursor_char_delete(cur);
697 evas_textblock_cursor_char_delete(cur);
698 evas_textblock_cursor_char_delete(cur);
699 fnode = evas_textblock_node_format_first_get(tb);
701 fail_if(strcmp(evas_textblock_node_format_text_get(fnode),
704 fnode = evas_textblock_node_format_next_get(fnode);
706 fail_if(strcmp(evas_textblock_node_format_text_get(fnode),
709 fnode = evas_textblock_node_format_next_get(fnode);
711 fail_if(strcmp(evas_textblock_node_format_text_get(fnode),
714 fnode = evas_textblock_node_format_next_get(fnode);
716 fail_if(strcmp(evas_textblock_node_format_text_get(fnode),
719 fnode = evas_textblock_node_format_next_get(fnode);
722 /* Try range deletion to delete a */
723 evas_object_textblock_text_markup_set(tb, buf);
724 evas_textblock_cursor_pos_set(cur, 6);
725 evas_textblock_cursor_pos_set(main_cur, 9);
726 evas_textblock_cursor_range_delete(cur, main_cur);
727 fnode = evas_textblock_node_format_first_get(tb);
729 fail_if(strcmp(evas_textblock_node_format_text_get(fnode),
732 fnode = evas_textblock_node_format_next_get(fnode);
734 fail_if(strcmp(evas_textblock_node_format_text_get(fnode),
737 fnode = evas_textblock_node_format_next_get(fnode);
740 /* Range deletion to delete both */
741 evas_object_textblock_text_markup_set(tb, buf);
742 evas_textblock_cursor_pos_set(cur, 2);
743 evas_textblock_cursor_pos_set(main_cur, 11);
744 evas_textblock_cursor_range_delete(cur, main_cur);
745 fnode = evas_textblock_node_format_first_get(tb);
748 /* Range deletion across paragraphs */
749 evas_object_textblock_text_markup_set(tb,
750 "Th<b>is a<a>te<ps/>"
752 evas_textblock_cursor_pos_set(cur, 6);
753 evas_textblock_cursor_pos_set(main_cur, 10);
754 evas_textblock_cursor_range_delete(cur, main_cur);
755 fnode = evas_textblock_node_format_first_get(tb);
757 fail_if(strcmp(evas_textblock_node_format_text_get(fnode),
760 fnode = evas_textblock_node_format_next_get(fnode);
762 fail_if(strcmp(evas_textblock_node_format_text_get(fnode),
765 fnode = evas_textblock_node_format_next_get(fnode);
768 /* Two formats in the same place. */
769 evas_object_textblock_text_markup_set(tb, "a<b><a>b</a></b>b");
770 evas_textblock_cursor_pos_set(cur, 1);
771 evas_textblock_cursor_char_delete(cur);
772 fnode = evas_textblock_node_format_first_get(tb);
775 /* Two formats across different paragraphs with notihng in between. */
776 evas_object_textblock_text_markup_set(tb, "<b><ps/></b>");
777 evas_textblock_cursor_pos_set(cur, 0);
778 evas_textblock_cursor_char_delete(cur);
779 fnode = evas_textblock_node_format_first_get(tb);
783 evas_object_textblock_text_markup_set(tb, "<b><ps/></b>");
784 evas_textblock_cursor_pos_set(cur, 0);
785 evas_textblock_cursor_pos_set(main_cur, 1);
786 evas_textblock_cursor_range_delete(cur, main_cur);
787 fnode = evas_textblock_node_format_first_get(tb);
790 /* Verify fmt position and REP_CHAR positions are the same */
791 evas_object_textblock_text_markup_set(tb,
792 "This is<ps/>an <item absize=93x152 vsize=ascent></>a.");
793 evas_textblock_cursor_pos_set(cur, 7);
794 evas_textblock_cursor_char_delete(cur);
795 fnode = evas_textblock_node_format_first_get(tb);
796 fail_if(_evas_textblock_format_offset_get(fnode) != 10);
798 /* Out of order <b><i></b></i> mixes. */
799 evas_object_textblock_text_markup_set(tb, "a<b>b<i>c</b>d</i>e");
800 evas_textblock_cursor_pos_set(cur, 2);
802 for (i = 0 ; i < 2 ; i++)
804 fnode = evas_textblock_node_format_first_get(tb);
806 fail_if(strcmp(evas_textblock_node_format_text_get(fnode), "+ b"));
808 fnode = evas_textblock_node_format_next_get(fnode);
810 fail_if(strcmp(evas_textblock_node_format_text_get(fnode), "+ i"));
812 fnode = evas_textblock_node_format_next_get(fnode);
814 fail_if(strcmp(evas_textblock_node_format_text_get(fnode), "- b"));
816 fnode = evas_textblock_node_format_next_get(fnode);
818 fail_if(strcmp(evas_textblock_node_format_text_get(fnode), "- i"));
820 fnode = evas_textblock_node_format_next_get(fnode);
823 evas_textblock_cursor_char_delete(cur);
825 fnode = evas_textblock_node_format_first_get(tb);
827 fail_if(strcmp(evas_textblock_node_format_text_get(fnode), "+ b"));
829 fnode = evas_textblock_node_format_next_get(fnode);
831 fail_if(strcmp(evas_textblock_node_format_text_get(fnode), "- b"));
833 fnode = evas_textblock_node_format_next_get(fnode);
836 /* This time with a generic closer */
837 evas_object_textblock_text_markup_set(tb, "a<b>b<i>c</b>d</>e");
838 evas_textblock_cursor_pos_set(cur, 2);
840 for (i = 0 ; i < 2 ; i++)
842 fnode = evas_textblock_node_format_first_get(tb);
844 fail_if(strcmp(evas_textblock_node_format_text_get(fnode), "+ b"));
846 fnode = evas_textblock_node_format_next_get(fnode);
848 fail_if(strcmp(evas_textblock_node_format_text_get(fnode), "+ i"));
850 fnode = evas_textblock_node_format_next_get(fnode);
852 fail_if(strcmp(evas_textblock_node_format_text_get(fnode), "- b"));
854 fnode = evas_textblock_node_format_next_get(fnode);
856 fail_if(strcmp(evas_textblock_node_format_text_get(fnode), "- "));
858 fnode = evas_textblock_node_format_next_get(fnode);
861 evas_textblock_cursor_char_delete(cur);
863 fnode = evas_textblock_node_format_first_get(tb);
865 fail_if(strcmp(evas_textblock_node_format_text_get(fnode), "+ b"));
867 fnode = evas_textblock_node_format_next_get(fnode);
869 fail_if(strcmp(evas_textblock_node_format_text_get(fnode), "- b"));
871 fnode = evas_textblock_node_format_next_get(fnode);
874 /* And now with remove pair. */
875 evas_object_textblock_text_markup_set(tb, "a<b>b<i>c</b>d</i>e");
876 evas_textblock_cursor_pos_set(cur, 2);
877 fnode = evas_textblock_node_format_first_get(tb);
878 evas_textblock_node_format_remove_pair(tb,
879 (Evas_Object_Textblock_Node_Format *) fnode);
881 fnode = evas_textblock_node_format_first_get(tb);
883 fail_if(strcmp(evas_textblock_node_format_text_get(fnode), "+ i"));
885 fnode = evas_textblock_node_format_next_get(fnode);
887 fail_if(strcmp(evas_textblock_node_format_text_get(fnode), "- i"));
889 fnode = evas_textblock_node_format_next_get(fnode);
892 /* Remove the other pair */
893 evas_object_textblock_text_markup_set(tb, "a<b>b<i>c</>d</i>e");
894 evas_textblock_cursor_pos_set(cur, 2);
895 fnode = evas_textblock_node_format_first_get(tb);
896 fnode = evas_textblock_node_format_next_get(fnode);
897 evas_textblock_node_format_remove_pair(tb,
898 (Evas_Object_Textblock_Node_Format *) fnode);
900 fnode = evas_textblock_node_format_first_get(tb);
902 fail_if(strcmp(evas_textblock_node_format_text_get(fnode), "+ b"));
904 fnode = evas_textblock_node_format_next_get(fnode);
906 fail_if(strcmp(evas_textblock_node_format_text_get(fnode), "- i"));
908 fnode = evas_textblock_node_format_next_get(fnode);
911 /* Remove two pairs with the same name and same positions. */
912 evas_object_textblock_text_markup_set(tb, "<a><a>A</a></a>");
913 evas_textblock_cursor_pos_set(cur, 0);
914 evas_textblock_cursor_char_delete(cur);
916 fnode = evas_textblock_node_format_first_get(tb);
919 /* Try to remove a format that doesn't have a pair (with a bad mkup) */
920 evas_object_textblock_text_markup_set(tb, "a<b>b<i>c</>d</i>e");
921 evas_textblock_cursor_pos_set(cur, 2);
922 fnode = evas_textblock_node_format_first_get(tb);
923 evas_textblock_node_format_remove_pair(tb,
924 (Evas_Object_Textblock_Node_Format *) fnode);
926 fnode = evas_textblock_node_format_first_get(tb);
928 fail_if(strcmp(evas_textblock_node_format_text_get(fnode), "+ i"));
930 fnode = evas_textblock_node_format_next_get(fnode);
932 fail_if(strcmp(evas_textblock_node_format_text_get(fnode), "- "));
934 fnode = evas_textblock_node_format_next_get(fnode);
936 fail_if(strcmp(evas_textblock_node_format_text_get(fnode), "- i"));
938 fnode = evas_textblock_node_format_next_get(fnode);
946 START_TEST(evas_textblock_items)
948 Evas_Coord w, h, w2, h2, nw, nh, ih;
950 const char *buf = "This is an <item absize=93x152></>.";
952 /* Absolute item size */
953 buf = "This is an <item absize=93x152 vsize=full></>.";
954 evas_object_textblock_text_markup_set(tb, buf);
955 evas_object_textblock_size_formatted_get(tb, &w, &h);
956 fail_if((w < 93) || (h != 152));
957 evas_textblock_cursor_pos_set(cur, 11);
958 evas_textblock_cursor_format_item_geometry_get(cur, NULL, NULL, &w, &h);
959 fail_if((w != 93) || (h != 152));
961 buf = "This is an <item absize=93x152 vsize=ascent></>.";
962 evas_object_textblock_text_markup_set(tb, buf);
963 evas_object_textblock_size_formatted_get(tb, &w, &h);
964 fail_if((w < 93) || (h <= 152));
965 evas_textblock_cursor_pos_set(cur, 11);
966 evas_textblock_cursor_format_item_geometry_get(cur, NULL, NULL, &w, &h);
967 fail_if((w != 93) || (h != 152));
969 /* Size is the same as abssize, unless there's scaling applied. */
970 buf = "This is an <item size=93x152 vsize=full></>.";
971 evas_object_textblock_text_markup_set(tb, buf);
972 evas_object_textblock_size_formatted_get(tb, &w, &h);
973 fail_if((w < 93) || (h != 152));
974 evas_textblock_cursor_pos_set(cur, 11);
975 evas_textblock_cursor_format_item_geometry_get(cur, NULL, NULL, &w, &h);
976 fail_if((w != 93) || (h != 152));
978 buf = "This is an <item size=93x152 vsize=ascent></>.";
979 evas_object_textblock_text_markup_set(tb, buf);
980 evas_object_textblock_size_formatted_get(tb, &w, &h);
981 fail_if((w < 93) || (h <= 152));
982 evas_textblock_cursor_pos_set(cur, 11);
983 evas_textblock_cursor_format_item_geometry_get(cur, NULL, NULL, &w, &h);
984 fail_if((w != 93) || (h != 152));
986 evas_object_scale_set(tb, 2.0);
987 buf = "This is an <item size=93x152 vsize=full></>.";
988 evas_object_textblock_text_markup_set(tb, buf);
989 evas_object_textblock_size_formatted_get(tb, &w, &h);
990 fail_if((w < (2 * 93)) || (h != (2 * 152)));
991 evas_textblock_cursor_pos_set(cur, 11);
992 evas_textblock_cursor_format_item_geometry_get(cur, NULL, NULL, &w, &h);
993 fail_if((w != (2 * 93)) || (h != (2 * 152)));
994 evas_textblock_cursor_pos_set(cur, 11);
995 evas_textblock_cursor_format_item_geometry_get(cur, NULL, NULL, &w, &h);
996 fail_if((w != (2 * 93)) || (h != (2 * 152)));
998 buf = "This is an <item size=93x152 vsize=ascent></>.";
999 evas_object_textblock_text_markup_set(tb, buf);
1000 evas_object_textblock_size_formatted_get(tb, &w, &h);
1001 fail_if((w < (2 * 93)) || (h <= (2 * 152)));
1002 evas_textblock_cursor_pos_set(cur, 11);
1003 evas_textblock_cursor_format_item_geometry_get(cur, NULL, NULL, &w, &h);
1004 fail_if((w != (2 * 93)) || (h != (2 * 152)));
1006 evas_object_scale_set(tb, 1.0);
1009 /* relsize means it should adjust itself to the size of the line */
1010 buf = "This is an <item relsize=93x152 vsize=full></>.";
1011 evas_object_textblock_text_markup_set(tb, buf);
1012 evas_object_textblock_size_formatted_get(tb, &w, &h);
1013 fail_if((w >= 93) || (h >= 152));
1014 evas_textblock_cursor_pos_set(cur, 11);
1015 evas_textblock_cursor_format_item_geometry_get(cur, NULL, NULL, &w, &ih);
1016 fail_if((w > 90) || (h != ih));
1018 buf = "This is an <item relize=93x152 vsize=ascent></>.";
1019 evas_object_textblock_text_markup_set(tb, buf);
1020 evas_object_textblock_size_formatted_get(tb, &w, &h);
1021 fail_if((w >= 93) || (h >= 152));
1022 evas_textblock_cursor_pos_set(cur, 11);
1023 evas_textblock_cursor_format_item_geometry_get(cur, NULL, NULL, &w, &ih);
1024 fail_if((w > 90) || (h <= ih));
1026 /* Relsize and abs size in the same line, all should be the same size */
1027 buf = "<item relsize=64x64 vsize=ascent href=emoticon/knowing-grin></item><item absize=64x64 vsize=ascent href=emoticon/knowing-grin></item><item relsize=64x64 vsize=ascent href=emoticon/knowing-grin></item>";
1028 evas_object_textblock_text_markup_set(tb, buf);
1029 evas_object_textblock_size_formatted_get(tb, &w, &h);
1030 evas_object_textblock_size_native_get(tb, &nw, &nh);
1031 fail_if((nw != w) || (nh != h));
1032 evas_textblock_cursor_format_item_geometry_get(cur, NULL, NULL, &w, &h);
1033 evas_textblock_cursor_char_next(cur);
1034 evas_textblock_cursor_format_item_geometry_get(cur, NULL, NULL, &w2, &h2);
1035 fail_if((w != w2) || (h != h2));
1036 evas_textblock_cursor_format_item_geometry_get(cur, NULL, NULL, &w, &h);
1037 evas_textblock_cursor_char_next(cur);
1038 evas_textblock_cursor_format_item_geometry_get(cur, NULL, NULL, &w2, &h2);
1039 fail_if((w != w2) || (h != h2));
1041 /* FIXME: Also verify x,y positions of the item. */
1043 /* FIXME We need some item tests that involve line wrapping that make the
1044 * items move between lines that are in different sizes.
1045 * Also, tests that involve wrapping positions with relsized items. We
1046 * want to make sure the item gets a relsize on the correct time (before
1047 * the wrapping, and then is updated after the wrapping) and that
1048 * all the lines have the correct sizes afterwards. */
1054 /* Wrapping tests */
1055 START_TEST(evas_textblock_wrapping)
1057 Evas_Coord bw, bh, w, h, nw, nh;
1060 evas_object_textblock_text_markup_set(tb, "a");
1061 evas_object_textblock_size_formatted_get(tb, &bw, &bh);
1064 evas_object_textblock_text_markup_set(tb, "aaaaaaa");
1065 evas_textblock_cursor_format_prepend(cur, "+ wrap=char");
1066 evas_object_resize(tb, bw, bh);
1067 evas_object_textblock_size_formatted_get(tb, &w, &h);
1068 /* Wrap to minimum */
1072 /* Mixed - fallback to char wrap */
1073 evas_object_textblock_text_markup_set(tb, "aaaaaaa");
1074 evas_textblock_cursor_format_prepend(cur, "+ wrap=mixed");
1075 evas_object_resize(tb, bw, bh);
1076 evas_object_textblock_size_formatted_get(tb, &w, &h);
1077 /* Wrap to minimum */
1081 /* Basic Word wrap */
1082 evas_object_textblock_text_markup_set(tb, "aaaa");
1083 evas_object_textblock_size_formatted_get(tb, &bw, &bh);
1085 evas_object_textblock_text_markup_set(tb, "aaaa aa");
1086 evas_textblock_cursor_format_prepend(cur, "+ wrap=word");
1087 evas_object_resize(tb, bw, bh);
1088 evas_object_textblock_size_formatted_get(tb, &w, &h);
1089 /* Wrap to minimum */
1093 /* Mixed - fallback to word wrap */
1094 evas_object_textblock_text_markup_set(tb, "aaaa aa");
1095 evas_textblock_cursor_format_prepend(cur, "+ wrap=mixed");
1096 evas_object_resize(tb, bw + 1, bh);
1097 evas_object_textblock_size_formatted_get(tb, &w, &h);
1098 /* Wrap to minimum */
1102 /* Wrap and then expand again. */
1103 evas_object_textblock_text_markup_set(tb, "aaaa aa");
1104 evas_textblock_cursor_format_prepend(cur, "+ wrap=word");
1105 evas_object_resize(tb, bw, bh);
1106 evas_object_textblock_size_formatted_get(tb, &w, &h);
1107 evas_object_textblock_size_native_get(tb, &nw, &nh);
1108 evas_object_resize(tb, nw, nh);
1109 evas_object_textblock_size_formatted_get(tb, &w, &h);
1110 fail_if((w != nw) || (h != nh));
1112 /* Reduce size until reaching the minimum, making sure we don't
1113 * get something wrong along the way */
1115 evas_object_textblock_text_markup_set(tb, "a");
1116 evas_object_textblock_size_formatted_get(tb, &bw, &bh);
1117 evas_object_textblock_text_markup_set(tb,
1118 "aaaa aaaa aaa aa aaa<ps/>"
1119 "aaaa aaa aaa aaa aaa<ps/>"
1120 "a aaaaa aaaaaaaaaaaaaa<br/>aaaaa<ps/>"
1123 evas_textblock_cursor_format_prepend(cur, "+ wrap=char");
1124 evas_object_textblock_size_native_get(tb, &nw, &nh);
1127 for (iw = nw ; iw >= bw ; iw--)
1129 evas_object_resize(tb, iw, 1000);
1130 evas_object_textblock_size_formatted_get(tb, &w, &h);
1137 evas_object_textblock_text_markup_set(tb, "aaaaaa");
1138 evas_object_textblock_size_formatted_get(tb, &bw, &bh);
1139 evas_object_textblock_text_markup_set(tb,
1140 "aaaa aaaa aaa aa aaa<ps/>"
1141 "aaaa aaa aaa aaa aaa<ps/>"
1142 "a aaaaa aaaaaa<br/>aaaaa<ps/>"
1145 evas_textblock_cursor_format_prepend(cur, "+ wrap=word");
1146 evas_object_textblock_size_native_get(tb, &nw, &nh);
1148 for (iw = nw ; iw >= bw ; iw--)
1150 evas_object_resize(tb, iw, 1000);
1151 evas_object_textblock_size_formatted_get(tb, &w, &h);
1158 evas_object_textblock_text_markup_set(tb, "a");
1159 evas_object_textblock_size_formatted_get(tb, &bw, &bh);
1160 evas_object_textblock_text_markup_set(tb,
1161 "aaaa aaaa aaa aa aaa<ps/>"
1162 "aaaa aaa aaa aaa aaa<ps/>"
1163 "a aaaaa aaaaaa<br/>aaaaa<ps/>"
1166 evas_textblock_cursor_format_prepend(cur, "+ wrap=mixed");
1167 evas_object_textblock_size_native_get(tb, &nw, &nh);
1169 for (iw = nw ; iw >= bw ; iw--)
1171 evas_object_resize(tb, iw, 1000);
1172 evas_object_textblock_size_formatted_get(tb, &w, &h);
1178 /* Resize, making sure we keep going down in the minimum size. */
1179 char *wrap_style[] = { "+ wrap=word", "+ wrap=char", "+ wrap=mixed" };
1180 int wrap_items = sizeof(wrap_style) / sizeof(*wrap_style);
1182 evas_object_textblock_text_markup_set(tb,
1183 "This is an entry widget in this window that<br/>"
1184 "uses markup <b>like this</> for styling and<br/>"
1185 "formatting <em>like this</>, as well as<br/>"
1186 "<a href=X><link>links in the text</></a>, so enter text<br/>"
1187 "in here to edit it. By the way, links are<br/>"
1188 "called <a href=anc-02>Anchors</a> so you will need<br/>"
1189 "to refer to them this way.<br/>"
1192 "Also you can stick in items with (relsize + ascent): "
1193 "<item relsize=16x16 vsize=ascent href=emoticon/evil-laugh></item>"
1195 "<item relsize=16x16 vsize=full href=emoticon/guilty-smile></item>"
1196 " (to the left)<br/>"
1198 "Also (size + ascent): "
1199 "<item size=16x16 vsize=ascent href=emoticon/haha></item>"
1201 "<item size=16x16 vsize=full href=emoticon/happy-panting></item>"
1202 " (before this)<br/>"
1204 "And as well (absize + ascent): "
1205 "<item absize=64x64 vsize=ascent href=emoticon/knowing-grin></item>"
1207 "<item absize=64x64 vsize=full href=emoticon/not-impressed></item>"
1208 " or even paths to image files on disk too like: "
1209 "<item absize=96x128 vsize=full href=file://%s/images/sky_01.jpg></item>"
1213 /* Get minimum size */
1214 evas_object_textblock_size_native_get(tb, &nw, &nh);
1216 for (i = 0 ; i < wrap_items ; i++)
1218 evas_textblock_cursor_format_prepend(cur, wrap_style[i]);
1219 evas_object_resize(tb, 0, 0);
1220 evas_object_textblock_size_formatted_get(tb, &bw, &bh);
1222 for (iw = nw ; iw >= bw ; iw--)
1224 evas_object_resize(tb, iw, 1000);
1225 evas_object_textblock_size_formatted_get(tb, &w, &h);
1234 evas_object_textblock_text_markup_set(tb, "aaaaaaaaaa");
1235 evas_textblock_cursor_format_prepend(cur, "+ ellipsis=1.0");
1236 evas_object_textblock_size_native_get(tb, &nw, &nh);
1237 evas_object_resize(tb, nw / 2, nh);
1238 evas_object_textblock_size_formatted_get(tb, &w, &h);
1239 fail_if((w > (nw / 2)) || (h != nh));
1241 evas_object_textblock_text_markup_set(tb, "aaaaaaaaaaaaaaaaaa<br/>b");
1242 evas_textblock_cursor_format_prepend(cur, "+ ellipsis=1.0 wrap=word");
1243 evas_object_textblock_size_native_get(tb, &nw, &nh);
1244 evas_object_resize(tb, nw / 2, nh * 2);
1245 evas_object_textblock_size_formatted_get(tb, &w, &h);
1246 fail_if(w > (nw / 2));
1252 /* Various textblock stuff */
1253 START_TEST(evas_textblock_various)
1255 Evas_Coord w, h, bw, bh;
1257 const char *buf = "This<ps/>textblock<ps/>has<ps/>a<ps/>lot<ps/>of<ps/>lines<ps/>.";
1258 evas_object_textblock_text_markup_set(tb, buf);
1259 evas_object_textblock_size_formatted_get(tb, &w, &h);
1260 /* Move outside of the screen so it'll have to search for the correct
1261 * paragraph and etc. */
1262 evas_object_move(tb, -(w / 2), -(h / 2));
1264 /* Replacement char */
1265 evas_object_textblock_text_markup_set(tb, "*");
1266 evas_object_textblock_size_formatted_get(tb, &bw, &bh);
1267 evas_object_textblock_replace_char_set(tb, "*");
1268 evas_object_textblock_text_markup_set(tb, "|");
1269 evas_object_textblock_size_formatted_get(tb, &w, &h);
1270 fail_if((w != bw) || (h != bh));
1272 /* Items have correct text node information */
1273 evas_object_textblock_text_markup_set(tb, "");
1274 fail_if(!_evas_textblock_check_item_node_link(tb));
1275 evas_object_textblock_text_markup_set(tb, "<ps/>");
1276 fail_if(!_evas_textblock_check_item_node_link(tb));
1277 evas_object_textblock_text_markup_set(tb, "a<ps/>");
1278 fail_if(!_evas_textblock_check_item_node_link(tb));
1279 evas_object_textblock_text_markup_set(tb, "a<ps/>a");
1280 fail_if(!_evas_textblock_check_item_node_link(tb));
1281 evas_object_textblock_text_markup_set(tb, "a<ps/>a<ps/>");
1282 fail_if(!_evas_textblock_check_item_node_link(tb));
1283 evas_object_textblock_text_markup_set(tb, "a<ps/>a<ps/>a");
1284 fail_if(!_evas_textblock_check_item_node_link(tb));
1286 /* These shouldn't crash (although the desired outcome is not yet defined) */
1287 evas_object_textblock_text_markup_set(tb, "");
1288 evas_textblock_cursor_pos_set(cur, 0);
1289 evas_textblock_cursor_char_delete(cur);
1291 evas_object_textblock_text_markup_set(tb, "\xEF\xBF\xBC");
1292 evas_textblock_cursor_pos_set(cur, 0);
1293 evas_textblock_cursor_char_delete(cur);
1299 /* Various geometries. e.g. range geometry. */
1300 START_TEST(evas_textblock_geometries)
1303 const char *buf = "This is a <br/> test.";
1304 evas_object_textblock_text_markup_set(tb, buf);
1306 /* Single line range */
1307 Evas_Textblock_Cursor *main_cur = evas_object_textblock_cursor_get(tb);
1308 evas_textblock_cursor_pos_set(cur, 0);
1309 evas_textblock_cursor_pos_set(main_cur, 6);
1311 Eina_List *rects, *rects2;
1312 Evas_Textblock_Rectangle *tr, *tr2;
1313 rects = evas_textblock_cursor_range_geometry_get(cur, main_cur);
1315 rects2 = evas_textblock_cursor_range_geometry_get(main_cur, cur);
1318 fail_if(eina_list_count(rects) != 1);
1319 fail_if(eina_list_count(rects2) != 1);
1321 tr = eina_list_data_get(rects);
1322 fail_if((tr->h <= 0) || (tr->w <= 0));
1323 tr2 = eina_list_data_get(rects2);
1324 fail_if((tr2->h <= 0) || (tr2->w <= 0));
1326 fail_if((tr->x != tr2->x) || (tr->y != tr2->y) || (tr->w != tr2->w) ||
1329 /* Multiline range */
1330 evas_textblock_cursor_pos_set(cur, 0);
1331 evas_textblock_cursor_pos_set(main_cur, 14);
1333 rects = evas_textblock_cursor_range_geometry_get(cur, main_cur);
1335 rects2 = evas_textblock_cursor_range_geometry_get(main_cur, cur);
1338 fail_if(eina_list_count(rects) != 2);
1339 fail_if(eina_list_count(rects2) != 2);
1341 tr = eina_list_data_get(rects);
1342 fail_if((tr->h <= 0) || (tr->w <= 0));
1343 tr2 = eina_list_data_get(rects2);
1344 fail_if((tr2->h <= 0) || (tr2->w <= 0));
1346 fail_if((tr->x != tr2->x) || (tr->y != tr2->y) || (tr->w != tr2->w) ||
1349 tr = eina_list_data_get(eina_list_next(rects));
1350 fail_if((tr->h <= 0) || (tr->w <= 0));
1351 tr2 = eina_list_data_get(eina_list_next(rects2));
1352 fail_if((tr2->h <= 0) || (tr2->w <= 0));
1354 fail_if((tr->x != tr2->x) || (tr->y != tr2->y) || (tr->w != tr2->w) ||
1357 /* Check that the second line is positioned below the first */
1358 tr = eina_list_data_get(rects);
1359 tr2 = eina_list_data_get(eina_list_next(rects));
1360 fail_if(tr->y >= tr2->y);
1366 /* Should handle all the text editing. */
1367 START_TEST(evas_textblock_editing)
1370 const char *buf = "First par.<ps/>Second par.";
1371 evas_object_textblock_text_markup_set(tb, buf);
1372 Evas_Textblock_Cursor *main_cur = evas_object_textblock_cursor_get(tb);
1374 /* Check deletion works */
1375 /* Try deleting after the end of the textblock */
1378 evas_textblock_cursor_paragraph_last(cur);
1379 content = strdup(evas_object_textblock_text_markup_get(tb));
1380 evas_textblock_cursor_char_delete(cur);
1381 fail_if(strcmp(content, evas_object_textblock_text_markup_get(tb)));
1385 /* Delete the first char */
1386 evas_textblock_cursor_paragraph_first(cur);
1387 evas_textblock_cursor_char_delete(cur);
1388 fail_if(strcmp(evas_object_textblock_text_markup_get(tb),
1389 "irst par.<ps/>Second par."));
1391 /* Delete some arbitrary char */
1392 evas_textblock_cursor_char_next(cur);
1393 evas_textblock_cursor_char_next(cur);
1394 evas_textblock_cursor_char_next(cur);
1395 evas_textblock_cursor_char_delete(cur);
1396 fail_if(strcmp(evas_object_textblock_text_markup_get(tb),
1397 "irs par.<ps/>Second par."));
1399 /* Delete a range */
1400 evas_textblock_cursor_pos_set(main_cur, 1);
1401 evas_textblock_cursor_pos_set(cur, 6);
1402 evas_textblock_cursor_range_delete(cur, main_cur);
1403 fail_if(strcmp(evas_object_textblock_text_markup_get(tb),
1404 "ir.<ps/>Second par."));
1405 evas_textblock_cursor_paragraph_char_first(main_cur);
1406 evas_textblock_cursor_paragraph_char_last(cur);
1407 evas_textblock_cursor_char_next(cur);
1408 evas_textblock_cursor_range_delete(cur, main_cur);
1409 fail_if(strcmp(evas_object_textblock_text_markup_get(tb),
1412 evas_object_textblock_text_markup_set(tb, buf);
1413 evas_textblock_cursor_paragraph_last(main_cur);
1414 evas_object_textblock_text_markup_prepend(main_cur, "Test<b>bla</b>bla.");
1415 evas_textblock_cursor_paragraph_last(cur);
1416 evas_textblock_cursor_paragraph_char_first(main_cur);
1417 evas_textblock_cursor_range_delete(cur, main_cur);
1418 fail_if(strcmp(evas_object_textblock_text_markup_get(tb),
1419 "First par.<ps/>"));
1421 /* Merging paragraphs */
1422 evas_object_textblock_text_markup_set(tb, buf);
1423 evas_textblock_cursor_paragraph_char_last(cur);
1424 evas_textblock_cursor_copy(cur, main_cur);
1425 evas_textblock_cursor_char_delete(cur);
1427 evas_textblock_cursor_paragraph_first(cur);
1428 fail_if(evas_textblock_cursor_paragraph_next(cur));
1430 /* Split paragraphs */
1431 evas_textblock_cursor_format_prepend(cur, "ps");
1433 evas_textblock_cursor_paragraph_first(cur);
1434 fail_if(!evas_textblock_cursor_paragraph_next(cur));
1435 fail_if(evas_textblock_cursor_paragraph_next(cur));
1437 /* Merge paragraphs using range deletion */
1438 evas_object_textblock_text_markup_set(tb, buf);
1439 evas_textblock_cursor_paragraph_first(cur);
1440 evas_textblock_cursor_paragraph_char_last(cur);
1441 evas_textblock_cursor_copy(cur, main_cur);
1442 evas_textblock_cursor_char_prev(cur);
1443 evas_textblock_cursor_char_next(main_cur);
1445 evas_textblock_cursor_range_delete(cur, main_cur);
1446 evas_textblock_cursor_paragraph_first(cur);
1447 fail_if(evas_textblock_cursor_paragraph_next(cur));
1449 /* Insert illegal characters inside the format. */
1451 const char *content;
1452 evas_object_textblock_text_markup_set(tb, "a\n");
1453 evas_textblock_cursor_pos_set(cur, 1);
1454 content = evas_textblock_cursor_content_get(cur);
1456 evas_object_textblock_text_markup_set(tb, "a\t");
1457 evas_textblock_cursor_pos_set(cur, 1);
1458 content = evas_textblock_cursor_content_get(cur);
1460 evas_object_textblock_text_markup_set(tb, "a\xEF\xBF\xBC");
1461 evas_textblock_cursor_pos_set(cur, 1);
1462 content = evas_textblock_cursor_content_get(cur);
1464 evas_object_textblock_text_markup_set(tb, "a\xE2\x80\xA9");
1465 evas_textblock_cursor_pos_set(cur, 1);
1466 content = evas_textblock_cursor_content_get(cur);
1470 /* FIXME: Also add text appending/prepending */
1477 START_TEST(evas_textblock_text_getters)
1480 const char *buf = "This is a <br/> test.<ps/>"
1481 "טקסט בעברית<ps/>and now in english.";
1482 evas_object_textblock_text_markup_set(tb, buf);
1483 evas_textblock_cursor_paragraph_first(cur);
1485 fail_if(strcmp(evas_textblock_cursor_paragraph_text_get(cur),
1486 "This is a <br/> test."));
1488 evas_textblock_cursor_paragraph_next(cur);
1489 fail_if(strcmp(evas_textblock_cursor_paragraph_text_get(cur),
1492 evas_textblock_cursor_paragraph_next(cur);
1493 fail_if(strcmp(evas_textblock_cursor_paragraph_text_get(cur),
1494 "and now in english."));
1497 Evas_Textblock_Cursor *main_cur = evas_object_textblock_cursor_get(tb);
1498 evas_textblock_cursor_pos_set(main_cur, 2);
1499 evas_textblock_cursor_pos_set(cur, 2);
1500 fail_if(*evas_textblock_cursor_range_text_get(main_cur, cur,
1501 EVAS_TEXTBLOCK_TEXT_MARKUP));
1503 evas_textblock_cursor_pos_set(main_cur, 2);
1504 evas_textblock_cursor_pos_set(cur, 6);
1505 fail_if(strcmp(evas_textblock_cursor_range_text_get(main_cur, cur,
1506 EVAS_TEXTBLOCK_TEXT_MARKUP), "is i"));
1508 evas_textblock_cursor_pos_set(main_cur, 5);
1509 evas_textblock_cursor_pos_set(cur, 14);
1510 fail_if(strcmp(evas_textblock_cursor_range_text_get(main_cur, cur,
1511 EVAS_TEXTBLOCK_TEXT_MARKUP), "is a <br/> te"));
1513 evas_textblock_cursor_pos_set(main_cur, 14);
1514 evas_textblock_cursor_pos_set(cur, 20);
1515 fail_if(strcmp(evas_textblock_cursor_range_text_get(main_cur, cur,
1516 EVAS_TEXTBLOCK_TEXT_MARKUP), "st.<ps/>טק"));
1518 evas_textblock_cursor_pos_set(main_cur, 14);
1519 evas_textblock_cursor_pos_set(cur, 32);
1520 fail_if(strcmp(evas_textblock_cursor_range_text_get(main_cur, cur,
1521 EVAS_TEXTBLOCK_TEXT_MARKUP), "st.<ps/>טקסט בעברית<ps/>an"));
1523 /* Backward range get */
1524 evas_textblock_cursor_pos_set(main_cur, 2);
1525 evas_textblock_cursor_pos_set(cur, 2);
1526 fail_if(*evas_textblock_cursor_range_text_get(cur, main_cur,
1527 EVAS_TEXTBLOCK_TEXT_MARKUP));
1529 evas_textblock_cursor_pos_set(main_cur, 2);
1530 evas_textblock_cursor_pos_set(cur, 6);
1531 fail_if(strcmp(evas_textblock_cursor_range_text_get(cur, main_cur,
1532 EVAS_TEXTBLOCK_TEXT_MARKUP), "is i"));
1534 evas_textblock_cursor_pos_set(main_cur, 5);
1535 evas_textblock_cursor_pos_set(cur, 14);
1536 fail_if(strcmp(evas_textblock_cursor_range_text_get(cur, main_cur,
1537 EVAS_TEXTBLOCK_TEXT_MARKUP), "is a <br/> te"));
1539 evas_textblock_cursor_pos_set(main_cur, 14);
1540 evas_textblock_cursor_pos_set(cur, 20);
1541 fail_if(strcmp(evas_textblock_cursor_range_text_get(cur, main_cur,
1542 EVAS_TEXTBLOCK_TEXT_MARKUP), "st.<ps/>טק"));
1544 evas_textblock_cursor_pos_set(main_cur, 14);
1545 evas_textblock_cursor_pos_set(cur, 32);
1546 fail_if(strcmp(evas_textblock_cursor_range_text_get(cur, main_cur,
1547 EVAS_TEXTBLOCK_TEXT_MARKUP), "st.<ps/>טקסט בעברית<ps/>an"));
1549 /* Uninit cursors and other weird cases */
1550 evas_object_textblock_clear(tb);
1551 evas_textblock_cursor_copy(main_cur, cur);
1552 evas_textblock_cursor_text_prepend(main_cur, "aaa");
1553 fail_if(strcmp(evas_textblock_cursor_range_text_get(cur, main_cur,
1554 EVAS_TEXTBLOCK_TEXT_MARKUP), "aaa"));
1556 /* Markup to plain and vice versa */
1560 /* Real textblock object */
1561 tmp = evas_textblock_text_markup_to_utf8(tb, "<br/>aa<\n/>bb<\t/>");
1562 fail_if(strcmp(tmp, "\naa\nbb\t"));
1563 tmp2 = evas_textblock_text_utf8_to_markup(tb, tmp);
1564 fail_if(strcmp(tmp2, "<br/>aa<br/>bb<tab/>"));
1568 tmp = evas_textblock_text_markup_to_utf8(tb, "a<item></item>");
1569 fail_if(strcmp(tmp, "a\xEF\xBF\xBC"));
1570 tmp2 = evas_textblock_text_utf8_to_markup(tb, tmp);
1571 fail_if(strcmp(tmp2, "a"));
1575 tmp = evas_textblock_text_markup_to_utf8(tb, "a ");
1576 fail_if(strcmp(tmp, "a\xC2\xA0"));
1577 tmp2 = evas_textblock_text_utf8_to_markup(tb, tmp);
1578 fail_if(strcmp(tmp2, "a\xC2\xA0"));
1582 tmp = evas_textblock_text_markup_to_utf8(tb, "a<b>b</b><more></>a");
1583 fail_if(strcmp(tmp, "aba"));
1584 tmp2 = evas_textblock_text_utf8_to_markup(tb, tmp);
1585 fail_if(strcmp(tmp2, "aba"));
1589 tmp = evas_textblock_text_markup_to_utf8(tb, "a&a");
1590 fail_if(strcmp(tmp, "a&a"));
1591 tmp2 = evas_textblock_text_utf8_to_markup(tb, tmp);
1592 fail_if(strcmp(tmp2, "a&a"));
1596 tmp = evas_textblock_text_markup_to_utf8(tb, "a<newline/>a");
1597 fail_if(strcmp(tmp, "a\na"));
1598 tmp2 = evas_textblock_text_utf8_to_markup(tb, tmp);
1599 fail_if(strcmp(tmp2, "a<br/>a"));
1603 /* NULL textblock object */
1604 tmp = evas_textblock_text_markup_to_utf8(NULL, "<br/>aa<\n/>bb<\t/>");
1605 fail_if(strcmp(tmp, "\naa\nbb\t"));
1606 tmp2 = evas_textblock_text_utf8_to_markup(NULL, tmp);
1607 fail_if(strcmp(tmp2, "<br/>aa<br/>bb<tab/>"));
1611 tmp = evas_textblock_text_markup_to_utf8(NULL, "a<item></item>");
1612 fail_if(strcmp(tmp, "a\xEF\xBF\xBC"));
1613 tmp2 = evas_textblock_text_utf8_to_markup(NULL, tmp);
1614 fail_if(strcmp(tmp2, "a"));
1618 tmp = evas_textblock_text_markup_to_utf8(NULL, "a ");
1619 fail_if(strcmp(tmp, "a\xC2\xA0"));
1620 tmp2 = evas_textblock_text_utf8_to_markup(NULL, tmp);
1621 fail_if(strcmp(tmp2, "a\xC2\xA0"));
1625 tmp = evas_textblock_text_markup_to_utf8(NULL, "a<b>b</b><more></>a");
1626 fail_if(strcmp(tmp, "aba"));
1627 tmp2 = evas_textblock_text_utf8_to_markup(NULL, tmp);
1628 fail_if(strcmp(tmp2, "aba"));
1632 tmp = evas_textblock_text_markup_to_utf8(tb, "a&a");
1633 fail_if(strcmp(tmp, "a&a"));
1634 tmp2 = evas_textblock_text_utf8_to_markup(tb, tmp);
1635 fail_if(strcmp(tmp2, "a&a"));
1639 tmp = evas_textblock_text_markup_to_utf8(NULL, "a<newline/>a");
1640 fail_if(strcmp(tmp, "aa"));
1641 tmp2 = evas_textblock_text_utf8_to_markup(NULL, tmp);
1642 fail_if(strcmp(tmp2, "aa"));
1652 START_TEST(evas_textblock_formats)
1655 const char *buf = "Th<b>i<font_size=15 wrap=none>s i</font_size=13>s</> a <br/> te<ps/>st<item></>.";
1656 const Evas_Object_Textblock_Node_Format *fnode;
1657 evas_object_textblock_text_markup_set(tb, buf);
1659 /* Walk from the start */
1660 fnode = evas_textblock_node_format_first_get(tb);
1662 fail_if(strcmp(evas_textblock_node_format_text_get(fnode), "+ b"));
1664 fnode = evas_textblock_node_format_next_get(fnode);
1666 fail_if(strcmp(evas_textblock_node_format_text_get(fnode),
1667 "+ font_size=15 wrap=none"));
1669 fnode = evas_textblock_node_format_next_get(fnode);
1671 fail_if(strcmp(evas_textblock_node_format_text_get(fnode),
1674 fnode = evas_textblock_node_format_next_get(fnode);
1676 fail_if(strcmp(evas_textblock_node_format_text_get(fnode), "- "));
1678 fnode = evas_textblock_node_format_next_get(fnode);
1680 fail_if(strcmp(evas_textblock_node_format_text_get(fnode), "br"));
1682 fnode = evas_textblock_node_format_next_get(fnode);
1684 fail_if(strcmp(evas_textblock_node_format_text_get(fnode), "ps"));
1686 fnode = evas_textblock_node_format_next_get(fnode);
1688 fail_if(strcmp(evas_textblock_node_format_text_get(fnode), "+ item"));
1690 fnode = evas_textblock_node_format_next_get(fnode);
1692 fail_if(strcmp(evas_textblock_node_format_text_get(fnode), "- "));
1694 fnode = evas_textblock_node_format_next_get(fnode);
1697 /* Walk backwards */
1698 fnode = evas_textblock_node_format_last_get(tb);
1700 fail_if(strcmp(evas_textblock_node_format_text_get(fnode), "- "));
1702 fnode = evas_textblock_node_format_prev_get(fnode);
1704 fail_if(strcmp(evas_textblock_node_format_text_get(fnode), "+ item"));
1706 fnode = evas_textblock_node_format_prev_get(fnode);
1708 fail_if(strcmp(evas_textblock_node_format_text_get(fnode), "ps"));
1710 fnode = evas_textblock_node_format_prev_get(fnode);
1712 fail_if(strcmp(evas_textblock_node_format_text_get(fnode), "br"));
1714 fnode = evas_textblock_node_format_prev_get(fnode);
1716 fail_if(strcmp(evas_textblock_node_format_text_get(fnode), "- "));
1718 fnode = evas_textblock_node_format_prev_get(fnode);
1720 fail_if(strcmp(evas_textblock_node_format_text_get(fnode),
1723 fnode = evas_textblock_node_format_prev_get(fnode);
1725 fail_if(strcmp(evas_textblock_node_format_text_get(fnode),
1726 "+ font_size=15 wrap=none"));
1728 fnode = evas_textblock_node_format_prev_get(fnode);
1730 fail_if(strcmp(evas_textblock_node_format_text_get(fnode), "+ b"));
1732 fnode = evas_textblock_node_format_prev_get(fnode);
1735 /* Cursor and format detection */
1736 fnode = evas_textblock_node_format_first_get(tb);
1738 evas_textblock_cursor_at_format_set(cur, fnode);
1739 fail_if(evas_textblock_cursor_format_is_visible_get(cur));
1741 fnode = evas_textblock_node_format_next_get(fnode);
1743 evas_textblock_cursor_at_format_set(cur, fnode);
1744 fail_if(evas_textblock_cursor_format_is_visible_get(cur));
1746 fnode = evas_textblock_node_format_next_get(fnode);
1748 evas_textblock_cursor_at_format_set(cur, fnode);
1749 fail_if(evas_textblock_cursor_format_is_visible_get(cur));
1751 fnode = evas_textblock_node_format_next_get(fnode);
1753 evas_textblock_cursor_at_format_set(cur, fnode);
1754 fail_if(evas_textblock_cursor_format_is_visible_get(cur));
1756 fnode = evas_textblock_node_format_next_get(fnode);
1758 evas_textblock_cursor_at_format_set(cur, fnode);
1759 fail_if(!evas_textblock_cursor_format_is_visible_get(cur));
1761 fnode = evas_textblock_node_format_next_get(fnode);
1763 evas_textblock_cursor_at_format_set(cur, fnode);
1764 fail_if(!evas_textblock_cursor_format_is_visible_get(cur));
1767 evas_textblock_cursor_paragraph_first(cur);
1780 fail_if(!evas_textblock_cursor_is_format(cur));
1783 fail_if(evas_textblock_cursor_is_format(cur));
1784 fail_if(evas_textblock_cursor_format_is_visible_get(cur));
1789 while (evas_textblock_cursor_char_next(cur));
1791 /* Format text nodes invalidation */
1793 Evas_Coord w, h, nw, nh;
1794 evas_object_textblock_text_markup_set(tb, "Test");
1795 evas_object_textblock_size_formatted_get(tb, &w, &h);
1796 evas_textblock_cursor_paragraph_first(cur);
1797 evas_textblock_cursor_format_prepend(cur, "+ font_size=40");
1798 evas_object_textblock_size_formatted_get(tb, &nw, &nh);
1799 fail_if((w >= nw) || (h >= nh));
1801 /* FIXME: Should extend invalidation tests. */
1803 /* Various formats, just verify there's no seg, we can't really
1804 * verify them visually, well, we can some of them. Possibly in the
1806 evas_object_textblock_text_markup_set(tb,
1807 "<font_size=40>font_size=40</><ps/>"
1808 "<color=#F210B3FF>color=#F210B3FF</><ps/>"
1809 "<underline=single underline_color=#A2B3C4>underline=single underline_color=#A2B3C4</><ps/>"
1810 "<underline=double underline_color=#F00 underline2_color=#00F>underline=double underline_color=#F00 underline2_color=#00F</><ps/>"
1811 "<underline=dashed underline_dash_color=#0F0 underline_dash_width=2 underline_dash_gap=1>underline=dashed underline_dash_color=#0F0 underline_dash_width=2 underline_dash_gap=1</><ps/>"
1812 "<style=outline outline_color=#F0FA>style=outline outline_color=#F0FA</><ps/>"
1813 "<style=shadow shadow_color=#F0F>style=shadow shadow_color=#F0F</><ps/>"
1814 "<style=glow glow_color=#BBB>style=glow glow_color=#BBB</><ps/>"
1815 "<style=glow glow2_color=#0F0>style=glow glow2_color=#0F0</><ps/>"
1816 "<style=glow color=#fff glow2_color=#fe87 glow_color=#f214>style=glow color=#fff glow2_color=#fe87 glow_color=#f214</><ps/>"
1817 "<backing=on backing_color=#00F>backing=on backing_color=#00F</><ps/>"
1818 "<strikethrough=on strikethrough_color=#FF0>strikethrough=on strikethrough_color=#FF0</><ps/>"
1819 "<align=right>align=right</><ps/>"
1820 "<backing=on backing_color=#F008 valign=0.0>valign=0.0</><ps/>"
1821 "<backing=on backing_color=#0F08 tabstops=50>tabstops=<\\t></>50</><ps/>"
1822 "<backing=on backing_color=#00F8 linesize=40>linesize=40</><ps/>"
1823 "<backing=on backing_color=#F0F8 linerelsize=200%>linerelsize=200%</><ps/>"
1824 "<backing=on backing_color=#0FF8 linegap=20>linegap=20</><ps/>"
1825 "<backing=on backing_color=#FF08 linerelgap=100%>linerelgap=100%</><ps/>");
1827 /* Force a relayout */
1828 evas_object_textblock_size_formatted_get(tb, NULL, NULL);
1830 /* Removing paired formats. */
1831 evas_object_textblock_text_markup_set(tb, "<a>aa<b>bb</b>cc</a>");
1832 fnode = evas_textblock_node_format_first_get(tb);
1833 evas_textblock_node_format_remove_pair(tb, (Evas_Object_Textblock_Node_Format *) fnode);
1834 fnode = evas_textblock_node_format_first_get(tb);
1836 fail_if(strcmp(evas_textblock_node_format_text_get(fnode), "+ b"));
1837 fnode = evas_textblock_node_format_next_get(fnode);
1839 fail_if(strcmp(evas_textblock_node_format_text_get(fnode), "- b"));
1841 evas_object_textblock_text_markup_set(tb, "<a>aa<b>bb</b>cc</a>");
1842 fnode = evas_textblock_node_format_first_get(tb);
1843 fnode = evas_textblock_node_format_next_get(fnode);
1844 evas_textblock_node_format_remove_pair(tb, (Evas_Object_Textblock_Node_Format *) fnode);
1845 fnode = evas_textblock_node_format_first_get(tb);
1847 fail_if(strcmp(evas_textblock_node_format_text_get(fnode), "+ a"));
1848 fnode = evas_textblock_node_format_next_get(fnode);
1850 fail_if(strcmp(evas_textblock_node_format_text_get(fnode), "- a"));
1852 /* Format list get */
1853 evas_object_textblock_text_markup_set(tb, "<a>a</>a<item>b</>"
1854 "b<item>b</>c<a>c</>");
1855 const Eina_List *flist = evas_textblock_node_format_list_get(tb, "a");
1856 const Eina_List *itr;
1857 EINA_LIST_FOREACH(flist, itr, fnode)
1859 fail_if(strcmp(evas_textblock_node_format_text_get(fnode), "+ a"));
1862 flist = evas_textblock_node_format_list_get(tb, "item");
1863 EINA_LIST_FOREACH(flist, itr, fnode)
1865 fail_if(strcmp(evas_textblock_node_format_text_get(fnode), "+ item"));
1868 /* Make sure we get all the types of visible formats correctly. */
1869 evas_object_textblock_text_markup_set(tb, "<ps/>a<br/>a<tab/>a<item></>");
1870 fail_if(strcmp(evas_textblock_node_format_text_get(
1871 evas_textblock_cursor_format_get(cur)), "ps"));
1872 fail_if(strcmp(evas_textblock_cursor_content_get(cur), "<ps/>"));
1873 fail_if(!evas_textblock_cursor_format_is_visible_get(cur));
1874 fail_if(!evas_textblock_cursor_char_next(cur));
1875 fail_if(!evas_textblock_cursor_char_next(cur));
1876 fail_if(strcmp(evas_textblock_node_format_text_get(
1877 evas_textblock_cursor_format_get(cur)), "br"));
1878 fail_if(strcmp(evas_textblock_cursor_content_get(cur), "<br/>"));
1879 fail_if(!evas_textblock_cursor_format_is_visible_get(cur));
1880 fail_if(!evas_textblock_cursor_char_next(cur));
1881 fail_if(!evas_textblock_cursor_char_next(cur));
1882 fail_if(strcmp(evas_textblock_node_format_text_get(
1883 evas_textblock_cursor_format_get(cur)), "tab"));
1884 fail_if(strcmp(evas_textblock_cursor_content_get(cur), "<tab/>"));
1885 fail_if(!evas_textblock_cursor_format_is_visible_get(cur));
1886 fail_if(!evas_textblock_cursor_char_next(cur));
1887 fail_if(!evas_textblock_cursor_char_next(cur));
1888 fail_if(strcmp(evas_textblock_node_format_text_get(
1889 evas_textblock_cursor_format_get(cur)), "+ item"));
1890 fail_if(strcmp(evas_textblock_cursor_content_get(cur), "<item>"));
1891 fail_if(!evas_textblock_cursor_format_is_visible_get(cur));
1897 /* Different text styles, for example, shadow. */
1898 START_TEST(evas_textblock_style)
1900 Evas_Coord w, h, nw, nh;
1901 Evas_Coord l, r, t, b;
1903 Evas_Textblock_Style *newst;
1904 const char *buf = "Test<ps/>Test2<ps/>נסיון";
1905 evas_object_textblock_text_markup_set(tb, buf);
1906 fail_if(strcmp(evas_object_textblock_text_markup_get(tb), buf));
1908 evas_object_textblock_size_formatted_get(tb, &w, &h);
1909 newst = evas_textblock_style_new();
1911 evas_textblock_style_set(newst,
1912 "DEFAULT='font=Sans font_size=20 color=#000 text_class=entry'"
1916 evas_object_textblock_style_set(tb, newst);
1917 evas_object_textblock_size_formatted_get(tb, &nw, &nh);
1918 fail_if((w >= nw) || (h >= nh));
1920 /* Style padding. */
1921 evas_object_textblock_text_markup_set(tb, "Test");
1922 evas_object_textblock_style_insets_get(tb, &l, &r, &t, &b);
1923 fail_if((l != 0) || (r != 0) || (t != 0) || (b != 0));
1925 evas_object_textblock_text_markup_set(tb, "<style=shadow>Test</>");
1926 evas_object_textblock_style_insets_get(tb, &l, &r, &t, &b);
1927 fail_if((l != 0) || (r != 1) || (t != 0) || (b != 1));
1929 evas_object_textblock_text_markup_set(tb, "<style=outline>Test</>");
1930 evas_object_textblock_style_insets_get(tb, &l, &r, &t, &b);
1931 fail_if((l != 1) || (r != 1) || (t != 1) || (b != 1));
1933 evas_object_textblock_text_markup_set(tb, "<style=soft_outline>Test</>");
1934 evas_object_textblock_style_insets_get(tb, &l, &r, &t, &b);
1935 fail_if((l != 2) || (r != 2) || (t != 2) || (b != 2));
1937 evas_object_textblock_text_markup_set(tb, "<style=glow>Test</>");
1938 evas_object_textblock_style_insets_get(tb, &l, &r, &t, &b);
1939 fail_if((l != 2) || (r != 2) || (t != 2) || (b != 2));
1941 evas_object_textblock_text_markup_set(tb, "<style=outline_shadow>Test</>");
1942 evas_object_textblock_style_insets_get(tb, &l, &r, &t, &b);
1943 fail_if((l != 1) || (r != 2) || (t != 1) || (b != 2));
1945 evas_object_textblock_text_markup_set(tb, "<style=far_shadow>Test</>");
1946 evas_object_textblock_style_insets_get(tb, &l, &r, &t, &b);
1947 fail_if((l != 1) || (r != 2) || (t != 1) || (b != 2));
1949 evas_object_textblock_text_markup_set(tb, "<style=outline_soft_shadow>Test</>");
1950 evas_object_textblock_style_insets_get(tb, &l, &r, &t, &b);
1951 fail_if((l != 1) || (r != 3) || (t != 1) || (b != 3));
1953 evas_object_textblock_text_markup_set(tb, "<style=soft_shadow>Test</>");
1954 evas_object_textblock_style_insets_get(tb, &l, &r, &t, &b);
1955 fail_if((l != 1) || (r != 3) || (t != 1) || (b != 3));
1957 evas_object_textblock_text_markup_set(tb, "<style=far_soft_shadow>Test</>");
1958 evas_object_textblock_style_insets_get(tb, &l, &r, &t, &b);
1959 fail_if((l != 0) || (r != 4) || (t != 0) || (b != 4));
1961 /* Mixed style padding */
1962 evas_object_textblock_text_markup_set(tb,
1963 "<style=far_shadow>Test</><style=far_soft_shadow>Test</>");
1964 evas_object_textblock_style_insets_get(tb, &l, &r, &t, &b);
1965 fail_if((l != 1) || (r != 4) || (t != 1) || (b != 4));
1971 /* Various setters and getters */
1972 START_TEST(evas_textblock_set_get)
1975 const char *buf = "";
1976 evas_object_textblock_text_markup_set(tb, buf);
1977 fail_if(strcmp(evas_textblock_style_get(st), style_buf));
1978 fail_if(evas_object_textblock_style_get(tb) != st);
1979 evas_object_textblock_replace_char_set(tb, "|");
1980 fail_if(strcmp(evas_object_textblock_replace_char_get(tb), "|"));
1981 evas_object_textblock_replace_char_set(tb, "ש");
1982 fail_if(strcmp(evas_object_textblock_replace_char_get(tb), "ש"));
1984 evas_object_textblock_valign_set(tb, -1.0);
1985 fail_if(evas_object_textblock_valign_get(tb) != 0.0);
1986 evas_object_textblock_valign_set(tb, 0.0);
1987 fail_if(evas_object_textblock_valign_get(tb) != 0.0);
1988 evas_object_textblock_valign_set(tb, 0.432);
1989 fail_if(evas_object_textblock_valign_get(tb) != 0.432);
1990 evas_object_textblock_valign_set(tb, 1.0);
1991 fail_if(evas_object_textblock_valign_get(tb) != 1.0);
1992 evas_object_textblock_valign_set(tb, 1.5);
1993 fail_if(evas_object_textblock_valign_get(tb) != 1.0);
1995 evas_object_textblock_bidi_delimiters_set(tb, ",.|");
1996 fail_if(strcmp(evas_object_textblock_bidi_delimiters_get(tb), ",.|"));
1997 evas_object_textblock_bidi_delimiters_set(tb, ",|");
1998 fail_if(strcmp(evas_object_textblock_bidi_delimiters_get(tb), ",|"));
1999 evas_object_textblock_bidi_delimiters_set(tb, NULL);
2000 fail_if(evas_object_textblock_bidi_delimiters_get(tb));
2001 evas_object_textblock_bidi_delimiters_set(tb, ",|");
2002 fail_if(strcmp(evas_object_textblock_bidi_delimiters_get(tb), ",|"));
2005 evas_object_textblock_text_markup_set(tb, "This is<ps/>a test<br/>bla");
2006 /* Force relayout */
2007 evas_object_textblock_size_formatted_get(tb, NULL, NULL);
2008 evas_font_hinting_set(evas, EVAS_FONT_HINTING_NONE);
2009 evas_font_hinting_set(evas, EVAS_FONT_HINTING_AUTO);
2010 evas_font_hinting_set(evas, EVAS_FONT_HINTING_BYTECODE);
2015 /* Aux evas stuff, such as scale. */
2016 START_TEST(evas_textblock_evas)
2018 Evas_Coord w, h, sw, sh;
2020 const char *buf = "Test";
2021 evas_object_textblock_text_markup_set(tb, buf);
2022 evas_object_textblock_size_formatted_get(tb, &w, &h);
2023 evas_object_scale_set(tb, 3.0);
2024 evas_object_textblock_size_formatted_get(tb, &sw, &sh);
2025 fail_if((sw <= w) || (sh <= h));
2027 evas_object_scale_set(tb, 0.5);
2028 evas_object_textblock_size_formatted_get(tb, &sw, &sh);
2029 fail_if((sw >= w) || (sh >= h));
2035 /* All the string escaping stuff */
2036 START_TEST(evas_textblock_escaping)
2040 fail_if(strcmp(evas_textblock_escape_string_get("&"), "&"));
2041 fail_if(strcmp(evas_textblock_string_escape_get("&", &len), "&"));
2044 fail_if(strcmp(evas_textblock_escape_string_get("·"), "\xc2\xb7"));
2045 fail_if(strcmp(evas_textblock_string_escape_get("\xc2\xb7", &len),
2049 fail_if(strcmp(evas_textblock_escape_string_get("👙"),
2050 "\xF0\x9F\x91\x99"));
2051 fail_if(strcmp(evas_textblock_escape_string_get("👙"),
2052 "\xF0\x9F\x91\x99"));
2054 fail_if(evas_textblock_escape_string_get("·aa"));
2055 const char *tmp = "·aa";
2056 fail_if(strcmp(evas_textblock_escape_string_range_get(tmp, tmp + 8),
2058 fail_if(evas_textblock_escape_string_range_get(tmp, tmp + 9));
2059 fail_if(evas_textblock_escape_string_range_get(tmp, tmp + 7));
2060 fail_if(evas_textblock_escape_string_range_get(tmp, tmp + 5));
2062 const char *buf = "This · is";
2063 evas_object_textblock_text_markup_set(tb, buf);
2064 fail_if(strcmp(evas_object_textblock_text_markup_get(tb), buf));
2066 buf = "This is";
2067 evas_object_textblock_text_markup_set(tb, buf);
2068 fail_if(strcmp(evas_object_textblock_text_markup_get(tb), buf));
2074 START_TEST(evas_textblock_size)
2077 Evas_Coord w, h, h2, nw, nh;
2078 const char *buf = "This is a <br/> test.<br/>גם בעברית";
2079 /* When wrapping is off, native size should be the same as formatted
2082 evas_object_textblock_size_formatted_get(tb, &w, &h);
2083 evas_object_textblock_size_native_get(tb, &nw, &nh);
2084 fail_if((w != nw) || (h != nh));
2087 evas_object_textblock_text_markup_set(tb, "a<br/>a");
2088 evas_object_textblock_size_formatted_get(tb, &w, &h2);
2089 evas_object_textblock_size_native_get(tb, &nw, &nh);
2090 fail_if((w != nw) || (h2 != nh));
2092 /* Two lines == double the height */
2093 fail_if(h * 2 != h2);
2095 evas_object_textblock_text_markup_set(tb, buf);
2097 evas_object_textblock_size_formatted_get(tb, &w, &h);
2098 evas_object_textblock_size_native_get(tb, &nw, &nh);
2099 fail_if((w != nw) || (h != nh));
2102 /* This time with margins. */
2104 Evas_Textblock_Style *newst;
2105 Evas_Coord oldw, oldh, oldnw, oldnh;
2107 evas_object_textblock_text_markup_set(tb, buf);
2108 evas_object_textblock_size_formatted_get(tb, &oldw, &oldh);
2109 evas_object_textblock_size_native_get(tb, &oldnw, &oldnh);
2112 newst = evas_textblock_style_new();
2114 evas_textblock_style_set(newst,
2115 "DEFAULT='left_margin=4 right_margin=4'");
2116 evas_object_textblock_style_user_push(tb, newst);
2118 evas_object_textblock_size_formatted_get(tb, &w, &h);
2119 evas_object_textblock_size_native_get(tb, &nw, &nh);
2121 fail_if((w != oldw + 8) || (h != oldh) ||
2122 (nw != oldnw + 8) || (nh != oldnh));
2125 /* FIXME: There is a lot more to be done. */
2130 void evas_test_textblock(TCase *tc)
2132 tcase_add_test(tc, evas_textblock_simple);
2133 tcase_add_test(tc, evas_textblock_cursor);
2134 tcase_add_test(tc, evas_textblock_size);
2135 tcase_add_test(tc, evas_textblock_editing);
2136 tcase_add_test(tc, evas_textblock_style);
2137 tcase_add_test(tc, evas_textblock_evas);
2138 tcase_add_test(tc, evas_textblock_text_getters);
2139 tcase_add_test(tc, evas_textblock_formats);
2140 tcase_add_test(tc, evas_textblock_format_removal);
2141 tcase_add_test(tc, evas_textblock_escaping);
2142 tcase_add_test(tc, evas_textblock_set_get);
2143 tcase_add_test(tc, evas_textblock_geometries);
2144 tcase_add_test(tc, evas_textblock_various);
2145 tcase_add_test(tc, evas_textblock_wrapping);
2146 tcase_add_test(tc, evas_textblock_items);