summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAli Alzyod <ali198724@gmail.com>2019-11-05 20:40:59 +0900
committerWooHyun Jung <wh0705.jung@samsung.com>2019-11-05 20:40:59 +0900
commit2f676a6591c117e15d65f263ebd267866963b627 (patch)
treecaeb56c6be2c81ea0c517ef00c8419828feb3c08
parent6a647880c60c376aa8c6acb9e54a16d9221d6658 (diff)
evas_textblock: content fit feature
Summary: **Content Fit Feature for Evas_Object_Textblock** This Feature is available at **Evas **object level. And **Edje **level (where it is internally use evas functionality) This feature will allow text block to fit its content font size to proper size to fit its area. **Main Properties:** Fit Modes : None=Default, Width, Height, All [Width+Height] Fit Size Range : Contains maximum and minimum font size to be used (and in between). Fit Step Size : Step(Jump) value when trying fonts sizes between Size_Range max and min. Fit Size Array : Other way to resize font, where you explicitly select font sizes to be uses (for example [20, 50, 100] it will try 3 sizes only) Text Fit feature was available in Edje but: 1- It doesn't effected by ellipsis or warping in font style (or do not handle the in right way) 2- Accuracy is not good (specially if you have fix pixel size elements (spaces,tabs,items)) 3- No (Step size, Size Array) available. Test Plan: To check the Feature > elementary_test > fit > textbock fit You can modify all the modes and properties These are two examples, One using Evas other uses Edje **Evas** ``` #include <Elementary.h> enum BUTTON{ BUTTON_MODE = 0, BUTTON_MAX = 1, BUTTON_MIN = 2, BUTTON_STEP = 3, BUTTON_ARRAY = 4, BUTTON_CONTENT = 5, BUTTON_STYLE = 6, BUTTON_ALL = BUTTON_STYLE+1, }; char* BUTTON_STR[BUTTON_ALL] ={ "MODE", "MAX", "MIN", "STEP", "ARRAY", "CONTENT", "STYLE", }; char *contents[] = { "Hello World", "This is Line<br>THis is other Line", "This text contains <font_size=20 color=#F00>SPECIFIC SIZE</font_size> that does not effected by fit mode" }; char *styles[] = { "DEFAULT='font=sans font_size=30 color=#000 wrap=mixed ellipsis=1.0'", "DEFAULT='font=sans font_size=30 color=#000 wrap=mixed'", "DEFAULT='font=sans font_size=30 color=#000 ellipsis=1.0'", "DEFAULT='font=sans font_size=30 color=#000'", }; char *styles_names[] = { "wrap=<color=#F00>mixed</color> ellipsis=<color=#F00>1.0</color>", "wrap=<color=#F00>mixed</color> ellipsis=<color=#F00>NONE</color>", "wrap=<color=#F00>NONE</color> ellipsis=<color=#F00>1.0</color>", "wrap=<color=#F00>NONE</color> ellipsis=<color=#F00>NONE</color>", }; typedef struct _APP { Evas_Object *win, *box, *txtblock,*bg, *boxHor, *boxHor2; Eo *btn[BUTTON_ALL]; Eo *lbl_status; char * str; unsigned int i_contnet, i_style; } APP; APP *app; char * get_fit_status(Eo * textblock); static void _btn_clicked(void *data EINA_UNUSED, Eo *obj, void *eventInfo EINA_UNUSED){ if (obj == app->btn[BUTTON_MODE]) { unsigned int options; evas_textblock_fit_options_get(app->txtblock, &options); if (options == TEXTBLOCK_FIT_MODE_NONE) evas_textblock_fit_options_set(app->txtblock, TEXTBLOCK_FIT_MODE_HEIGHT); else if (options == TEXTBLOCK_FIT_MODE_HEIGHT) evas_textblock_fit_options_set(app->txtblock, TEXTBLOCK_FIT_MODE_WIDTH); else if (options == TEXTBLOCK_FIT_MODE_WIDTH) evas_textblock_fit_options_set(app->txtblock, TEXTBLOCK_FIT_MODE_ALL); else if (options == TEXTBLOCK_FIT_MODE_ALL) evas_textblock_fit_options_set(app->txtblock, TEXTBLOCK_FIT_MODE_NONE); } else if (obj == app->btn[BUTTON_MAX]) { unsigned int min, max; evas_textblock_fit_size_range_get(app->txtblock, &min, &max); max -= 5; evas_textblock_fit_size_range_set(app->txtblock, min, max); } else if (obj == app->btn[BUTTON_MIN]) { unsigned int min, max; evas_textblock_fit_size_range_get(app->txtblock, &min, &max); min += 5; evas_textblock_fit_size_range_set(app->txtblock, min, max); } else if (obj == app->btn[BUTTON_STEP]) { unsigned int step; evas_textblock_fit_step_size_get(app->txtblock, &step); step++; evas_textblock_fit_step_size_set(app->txtblock, step); } else if (obj == app->btn[BUTTON_ARRAY]) { unsigned int font_size[] = {10, 50, 100 ,150}; evas_textblock_fit_size_array_set(app->txtblock,font_size,4); } else if (obj == app->btn[BUTTON_CONTENT]) { app->i_contnet++; if(app->i_contnet>=sizeof(contents)/sizeof(char*)) app->i_contnet=0; evas_object_textblock_text_markup_set(app->txtblock,contents[app->i_contnet]); } else if (obj == app->btn[BUTTON_STYLE]) { app->i_style++; if(app->i_style>=sizeof(styles)/sizeof(char*)) app->i_style=0; Evas_Textblock_Style *style = evas_object_textblock_style_get(app->txtblock); evas_textblock_style_set(style,styles[app->i_style]); } elm_object_text_set(app->lbl_status, get_fit_status(app->txtblock)); } char * get_fit_status(Eo * textblock) { static char status[0xFFF]; unsigned int options,min,max,step,size_array[256]; size_t size_array_len; evas_textblock_fit_options_get(textblock,&options); evas_textblock_fit_size_range_get(textblock,&min,&max); evas_textblock_fit_step_size_get(textblock,&step); evas_textblock_fit_size_array_get(textblock,NULL,&size_array_len,0); if (size_array_len>255) size_array_len = 255; evas_textblock_fit_size_array_get(textblock,size_array,NULL,size_array_len); strcpy(status,"Mode : "); if (options == TEXTBLOCK_FIT_MODE_NONE) strcat(status,"MODE_NONE"); else if (options == TEXTBLOCK_FIT_MODE_HEIGHT) strcat(status,"MODE_HEIGHT"); else if (options == TEXTBLOCK_FIT_MODE_WIDTH) strcat(status,"MODE_WIDTH"); else if (options == TEXTBLOCK_FIT_MODE_ALL) strcat(status,"MODE_ALL"); strcat(status,"<br>"); sprintf(status + strlen(status),"Max : %d<br>",max); sprintf(status + strlen(status),"Min : %d<br>",min); sprintf(status + strlen(status),"Step : %d<br>",step); sprintf(status + strlen(status),"Array : [ "); for (size_t i = 0 ; i < 10 ; i++) { if(i<size_array_len) sprintf(status + strlen(status)," %d,",size_array[i]); } if(10<size_array_len) sprintf(status + strlen(status)," ... "); sprintf(status + strlen(status)," ]"); sprintf(status + strlen(status),"<br>"); sprintf(status + strlen(status),"%s",styles_names[app->i_style]); return status; } int elm_main(int argc, char **argv) { app = calloc(sizeof(APP), 1); elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED); app->win = elm_win_util_standard_add("Main", "App"); elm_win_autodel_set(app->win, EINA_TRUE); app->box = elm_box_add(app->win); app->boxHor = elm_box_add(app->box); app->boxHor2 = elm_box_add(app->box); app->txtblock = evas_object_textblock_add(app->box); app->bg = elm_bg_add(app->box); elm_bg_color_set(app->bg,255,255,255); Evas_Textblock_Style *style = evas_textblock_style_new(); evas_textblock_style_set(style,styles[0]); evas_object_textblock_style_set(app->txtblock,style); evas_object_textblock_text_markup_set(app->txtblock,contents[0]); elm_box_horizontal_set(app->boxHor, EINA_TRUE); elm_box_horizontal_set(app->boxHor2, EINA_TRUE); evas_object_size_hint_weight_set(app->box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(app->box, EVAS_HINT_FILL, EVAS_HINT_FILL); evas_object_size_hint_weight_set(app->box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(app->box, EVAS_HINT_FILL, EVAS_HINT_FILL); evas_object_show(app->txtblock); evas_object_show(app->bg); evas_object_show(app->box); evas_object_show(app->boxHor); evas_object_show(app->boxHor2); elm_box_pack_end(app->box, app->bg); elm_box_pack_end(app->box, app->boxHor); elm_box_pack_end(app->box, app->boxHor2); elm_object_content_set(app->bg,app->txtblock); elm_win_resize_object_add(app->win, app->box); evas_object_resize(app->win, 320, 480); for(int i = 0 ; i < BUTTON_ALL ; i++) { app->btn[i] = elm_button_add(app->boxHor); evas_object_smart_callback_add(app->btn[i], "clicked", _btn_clicked, NULL); elm_object_text_set(app->btn[i], BUTTON_STR[i]); elm_box_pack_end(app->boxHor, app->btn[i]); evas_object_show(app->btn[i]); } app->lbl_status = elm_label_add(app->boxHor2); elm_object_text_set(app->lbl_status, get_fit_status(app->txtblock)); elm_box_pack_end(app->boxHor2, app->lbl_status); evas_object_show(app->lbl_status); evas_object_size_hint_weight_set(app->txtblock, EVAS_HINT_EXPAND,EVAS_HINT_EXPAND); evas_object_size_hint_align_set(app->txtblock, EVAS_HINT_FILL, EVAS_HINT_FILL); evas_object_size_hint_weight_set(app->bg, EVAS_HINT_EXPAND,EVAS_HINT_EXPAND); evas_object_size_hint_align_set(app->bg, EVAS_HINT_FILL, EVAS_HINT_FILL); evas_object_show(app->win); elm_run(); return 0; } ELM_MAIN() ``` **Edje** ``` // compile: edje_cc source.edc // run: edje_player source.edje collections { styles { style { name: "text_style"; base: "font=sans font_size=30 color=#FFF wrap=mixed ellipsis=1.0"; tag: "br" "\n"; tag: "ps" "ps"; tag: "tab" "\t"; tag: "b" "+ font_weight=Bold"; } } group { name: "my_group"; // must be the same as in source.c parts { part { name: "background"; type: RECT; scale: 1; description { color: 0 0 0 0; rel1.relative: 0.0 0.0; rel2.relative: 1.0 1.0; } } part { name: "text"; type: TEXTBLOCK; scale: 1; entry_mode: NONE; effect: OUTLINE_SHADOW; description { state: "default" 0.0; rel1.to : "background"; rel1.relative: 0.0 0.0; rel2.to : "background"; rel2.relative: 1.0 1.0; text { style: "text_style"; align: 0.0 0.0; text: "Hello World This is Me"; fit: 1 1; fit_step: 1; size_range: 30 200; //fit_size_array: 20 40 60 80 100 200; } } } } } } ``` Found Task T5724 relative to this Feature Reviewers: woohyun, bowonryu, cedric, raster Subscribers: #committers, #reviewers, cedric Tags: #efl Differential Revision: https://phab.enlightenment.org/D9280
-rw-r--r--src/bin/edje/edje_cc_handlers.c81
-rw-r--r--src/bin/elementary/test.c2
-rw-r--r--src/bin/elementary/test_label.c232
-rw-r--r--src/lib/edje/edje_data.c2
-rw-r--r--src/lib/edje/edje_private.h3
-rw-r--r--src/lib/edje/edje_textblock.c102
-rw-r--r--src/lib/eet/Eet.h23
-rw-r--r--src/lib/evas/canvas/evas_object_textblock.c500
-rw-r--r--src/lib/evas/canvas/evas_textblock_legacy.h100
-rw-r--r--src/tests/evas/evas_test_textblock.c27
10 files changed, 983 insertions, 89 deletions
diff --git a/src/bin/edje/edje_cc_handlers.c b/src/bin/edje/edje_cc_handlers.c
index c9bbc1744a..8353d260a3 100644
--- a/src/bin/edje/edje_cc_handlers.c
+++ b/src/bin/edje/edje_cc_handlers.c
@@ -419,6 +419,8 @@ static void st_collections_group_parts_part_description_text_repch(void);
419static void st_collections_group_parts_part_description_text_size(void); 419static void st_collections_group_parts_part_description_text_size(void);
420static void st_collections_group_parts_part_description_text_size_range(void); 420static void st_collections_group_parts_part_description_text_size_range(void);
421static void st_collections_group_parts_part_description_text_fit(void); 421static void st_collections_group_parts_part_description_text_fit(void);
422static void st_collections_group_parts_part_description_text_fit_step(void);
423static void st_collections_group_parts_part_description_text_fit_size_array(void);
422static void st_collections_group_parts_part_description_text_min(void); 424static void st_collections_group_parts_part_description_text_min(void);
423static void st_collections_group_parts_part_description_text_max(void); 425static void st_collections_group_parts_part_description_text_max(void);
424static void st_collections_group_parts_part_description_text_align(void); 426static void st_collections_group_parts_part_description_text_align(void);
@@ -952,6 +954,8 @@ New_Statement_Handler statement_handlers[] =
952 {"collections.group.parts.part.description.text.size", st_collections_group_parts_part_description_text_size}, 954 {"collections.group.parts.part.description.text.size", st_collections_group_parts_part_description_text_size},
953 {"collections.group.parts.part.description.text.size_range", st_collections_group_parts_part_description_text_size_range}, 955 {"collections.group.parts.part.description.text.size_range", st_collections_group_parts_part_description_text_size_range},
954 {"collections.group.parts.part.description.text.fit", st_collections_group_parts_part_description_text_fit}, 956 {"collections.group.parts.part.description.text.fit", st_collections_group_parts_part_description_text_fit},
957 {"collections.group.parts.part.description.text.fit_step", st_collections_group_parts_part_description_text_fit_step},
958 {"collections.group.parts.part.description.text.fit_size_array", st_collections_group_parts_part_description_text_fit_size_array},
955 {"collections.group.parts.part.description.text.min", st_collections_group_parts_part_description_text_min}, 959 {"collections.group.parts.part.description.text.min", st_collections_group_parts_part_description_text_min},
956 {"collections.group.parts.part.description.text.max", st_collections_group_parts_part_description_text_max}, 960 {"collections.group.parts.part.description.text.max", st_collections_group_parts_part_description_text_max},
957 {"collections.group.parts.part.description.text.align", st_collections_group_parts_part_description_text_align}, 961 {"collections.group.parts.part.description.text.align", st_collections_group_parts_part_description_text_align},
@@ -11654,6 +11658,83 @@ st_collections_group_parts_part_description_text_fit(void)
11654 ed->text.fit_y = parse_bool(1); 11658 ed->text.fit_y = parse_bool(1);
11655} 11659}
11656 11660
11661
11662/**
11663 @page edcref
11664
11665 @property
11666 fit_step
11667 @parameters
11668 [font step size in points (pt)]
11669 @effect
11670 Sets the font step size for the text part. when fitting text
11671
11672 Defaults: 1
11673 @since 1.24.0
11674 @endproperty
11675 */
11676static void
11677st_collections_group_parts_part_description_text_fit_step(void)
11678{
11679 Edje_Part_Description_Text *ed;
11680
11681 check_arg_count(1);
11682
11683 if (current_part->type != EDJE_PART_TYPE_TEXTBLOCK)
11684 {
11685 ERR("parse error %s:%i. text attributes in non-TEXTBLOCK part.",
11686 file_in, line - 1);
11687 exit(-1);
11688 }
11689
11690 ed = (Edje_Part_Description_Text *)current_desc;
11691
11692 ed->text.fit_step = parse_int(0);
11693
11694 if (ed->text.fit_step < 1)
11695 {
11696 ERR("parse error %s:%i. fit step less than 1.",
11697 file_in, line - 1);
11698 exit(-1);
11699 }
11700}
11701
11702/**
11703 @page edcref
11704
11705 @property
11706 fit
11707 @parameters
11708 [Array of font sizes in points]
11709 @effect
11710 Sets the allowed font sizes array for the text part.
11711 @since 1.24.0
11712 @endproperty
11713 */
11714static void
11715st_collections_group_parts_part_description_text_fit_size_array(void)
11716{
11717 int n, argc;
11718 Edje_Part_Description_Text *ed;
11719
11720 if (current_part->type != EDJE_PART_TYPE_TEXTBLOCK)
11721 {
11722 ERR("parse error %s:%i. text attributes in non-TEXTBLOCK part.",
11723 file_in, line - 1);
11724 exit(-1);
11725 }
11726
11727 ed = (Edje_Part_Description_Text *)current_desc;
11728 check_min_arg_count(1);
11729
11730 for (n = 0, argc = get_arg_count(); n < argc; n++)
11731 {
11732 unsigned int *value = malloc(sizeof(unsigned int));
11733 *value = (unsigned int) parse_int(n);
11734 ed->text.fit_size_array = eina_list_append(ed->text.fit_size_array, value);
11735 }
11736}
11737
11657/** 11738/**
11658 @page edcref 11739 @page edcref
11659 11740
diff --git a/src/bin/elementary/test.c b/src/bin/elementary/test.c
index 8259ed8b0c..257cdc1a30 100644
--- a/src/bin/elementary/test.c
+++ b/src/bin/elementary/test.c
@@ -240,6 +240,7 @@ void test_flip_page_eo(void *data, Evas_Object *obj, void *event_info);
240void test_label(void *data, Evas_Object *obj, void *event_info); 240void test_label(void *data, Evas_Object *obj, void *event_info);
241void test_label_slide(void *data, Evas_Object *obj, void *event_info); 241void test_label_slide(void *data, Evas_Object *obj, void *event_info);
242void test_label_wrap(void *data, Evas_Object *obj, void *event_info); 242void test_label_wrap(void *data, Evas_Object *obj, void *event_info);
243void test_textblock_fit(void *data, Evas_Object *obj, void *event_info);
243void test_label_ellipsis(void *data, Evas_Object *obj, void *event_info); 244void test_label_ellipsis(void *data, Evas_Object *obj, void *event_info);
244void test_label_colors(void *data, Evas_Object *obj, void *event_info); 245void test_label_colors(void *data, Evas_Object *obj, void *event_info);
245void test_label_emoji(void *data, Evas_Object *obj, void *event_info); 246void test_label_emoji(void *data, Evas_Object *obj, void *event_info);
@@ -1207,6 +1208,7 @@ add_tests:
1207 ADD_TEST(NULL, "Text", "Label", test_label); 1208 ADD_TEST(NULL, "Text", "Label", test_label);
1208 ADD_TEST(NULL, "Text", "Label Slide", test_label_slide); 1209 ADD_TEST(NULL, "Text", "Label Slide", test_label_slide);
1209 ADD_TEST(NULL, "Text", "Label Wrap", test_label_wrap); 1210 ADD_TEST(NULL, "Text", "Label Wrap", test_label_wrap);
1211 ADD_TEST(NULL, "Text", "Textblock Fit", test_textblock_fit);
1210 ADD_TEST(NULL, "Text", "Label Ellipsis", test_label_ellipsis); 1212 ADD_TEST(NULL, "Text", "Label Ellipsis", test_label_ellipsis);
1211 ADD_TEST(NULL, "Text", "Label Colors", test_label_colors); 1213 ADD_TEST(NULL, "Text", "Label Colors", test_label_colors);
1212 ADD_TEST(NULL, "Text", "Label Emoji", test_label_emoji); 1214 ADD_TEST(NULL, "Text", "Label Emoji", test_label_emoji);
diff --git a/src/bin/elementary/test_label.c b/src/bin/elementary/test_label.c
index 233ce015b4..929d06b1d5 100644
--- a/src/bin/elementary/test_label.c
+++ b/src/bin/elementary/test_label.c
@@ -309,6 +309,238 @@ test_label_slide(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *eve
309 evas_object_show(win); 309 evas_object_show(win);
310} 310}
311 311
312
313
314/*** FIT TEXT **************************************************************/
315enum BUTTON{
316 BUTTON_MODE = 0,
317 BUTTON_MAX = 1,
318 BUTTON_MIN = 2,
319 BUTTON_STEP = 3,
320 BUTTON_ARRAY = 4,
321 BUTTON_CONTENT = 5,
322 BUTTON_STYLE = 6,
323 BUTTON_ALL = BUTTON_STYLE+1,
324};
325
326char* BUTTON_STR[BUTTON_ALL] ={
327 "MODE",
328 "MAX",
329 "MIN",
330 "STEP",
331 "ARRAY",
332 "CONTENT",
333 "STYLE",
334};
335
336char *contents[] = {
337 "Hello World",
338 "This is Line<br>THis is other Line",
339 "This text contains <font_size=20 color=#F00>SPECIFIC SIZE</font_size>that does not effected by fit mode"
340 };
341
342char *styles[] = {
343 "DEFAULT='font=sans font_size=30 color=#000 wrap=mixed ellipsis=1.0'",
344 "DEFAULT='font=sans font_size=30 color=#000 wrap=mixed'",
345 "DEFAULT='font=sans font_size=30 color=#000 ellipsis=1.0'",
346 "DEFAULT='font=sans font_size=30 color=#000'",
347 };
348
349char *styles_names[] = {
350 "wrap=<color=#F00>mixed</color> ellipsis=<color=#F00>1.0</color>",
351 "wrap=<color=#F00>mixed</color> ellipsis=<color=#F00>NONE</color>",
352 "wrap=<color=#F00>NONE</color> ellipsis=<color=#F00>1.0</color>",
353 "wrap=<color=#F00>NONE</color> ellipsis=<color=#F00>NONE</color>",
354 };
355
356typedef struct _APP
357{
358 Evas_Object *win, *box, *txtblock,*bg, *boxHor, *boxHor2;
359 Eo *btn[BUTTON_ALL];
360 Eo *lbl_status;
361 char * str;
362 unsigned int i_contnet, i_style;
363} APP;
364APP *app;
365
366char * get_fit_status(Eo * textblock);
367
368static void _btn_clicked(void *data EINA_UNUSED, Eo *obj, void *eventInfo EINA_UNUSED){
369 if (obj == app->btn[BUTTON_MODE])
370 {
371 unsigned int options;
372 evas_textblock_fit_options_get(app->txtblock, &options);
373 if (options == TEXTBLOCK_FIT_MODE_NONE)
374 evas_textblock_fit_options_set(app->txtblock, TEXTBLOCK_FIT_MODE_HEIGHT);
375 else if (options == TEXTBLOCK_FIT_MODE_HEIGHT)
376 evas_textblock_fit_options_set(app->txtblock, TEXTBLOCK_FIT_MODE_WIDTH);
377 else if (options == TEXTBLOCK_FIT_MODE_WIDTH)
378 evas_textblock_fit_options_set(app->txtblock, TEXTBLOCK_FIT_MODE_ALL);
379 else if (options == TEXTBLOCK_FIT_MODE_ALL)
380 evas_textblock_fit_options_set(app->txtblock, TEXTBLOCK_FIT_MODE_NONE);
381 }
382 else if (obj == app->btn[BUTTON_MAX])
383 {
384 unsigned int min, max;
385 evas_textblock_fit_size_range_get(app->txtblock, &min, &max);
386 max -= 5;
387 evas_textblock_fit_size_range_set(app->txtblock, min, max);
388 }
389 else if (obj == app->btn[BUTTON_MIN])
390 {
391 unsigned int min, max;
392 evas_textblock_fit_size_range_get(app->txtblock, &min, &max);
393 min += 5;
394 evas_textblock_fit_size_range_set(app->txtblock, min, max);
395 }
396 else if (obj == app->btn[BUTTON_STEP])
397 {
398 unsigned int step;
399 evas_textblock_fit_step_size_get(app->txtblock, &step);
400 step++;
401 evas_textblock_fit_step_size_set(app->txtblock, step);
402 }
403 else if (obj == app->btn[BUTTON_ARRAY])
404 {
405 unsigned int font_size[] = {10, 50, 100 ,150};
406 evas_textblock_fit_size_array_set(app->txtblock,font_size,4);
407 }
408 else if (obj == app->btn[BUTTON_CONTENT])
409 {
410 app->i_contnet++;
411 if(app->i_contnet>=sizeof(contents)/sizeof(char*))
412 app->i_contnet=0;
413 evas_object_textblock_text_markup_set(app->txtblock,contents[app->i_contnet]);
414 }
415 else if (obj == app->btn[BUTTON_STYLE])
416 {
417 app->i_style++;
418 if(app->i_style>=sizeof(styles)/sizeof(char*))
419 app->i_style=0;
420
421 Evas_Textblock_Style *style = evas_object_textblock_style_get(app->txtblock);
422 evas_textblock_style_set(style,styles[app->i_style]);
423 }
424
425 elm_object_text_set(app->lbl_status, get_fit_status(app->txtblock));
426}
427
428char * get_fit_status(Eo * textblock)
429{
430 static char status[0xFFF];
431 unsigned int options,min,max,step,size_array[256];
432 size_t size_array_len;
433 evas_textblock_fit_options_get(textblock,&options);
434 evas_textblock_fit_size_range_get(textblock,&min,&max);
435 evas_textblock_fit_step_size_get(textblock,&step);
436 evas_textblock_fit_size_array_get(textblock,NULL,&size_array_len,0);
437 if (size_array_len>255)
438 size_array_len = 255;
439 evas_textblock_fit_size_array_get(textblock,size_array,NULL,size_array_len);
440
441 strcpy(status,"Mode : ");
442 if (options == TEXTBLOCK_FIT_MODE_NONE)
443 strcat(status,"MODE_NONE");
444 else if (options == TEXTBLOCK_FIT_MODE_HEIGHT)
445 strcat(status,"MODE_HEIGHT");
446 else if (options == TEXTBLOCK_FIT_MODE_WIDTH)
447 strcat(status,"MODE_WIDTH");
448 else if (options == TEXTBLOCK_FIT_MODE_ALL)
449 strcat(status,"MODE_ALL");
450
451 strcat(status,"<br>");
452 sprintf(status + strlen(status),"Max : %d<br>",max);
453 sprintf(status + strlen(status),"Min : %d<br>",min);
454 sprintf(status + strlen(status),"Step : %d<br>",step);
455 sprintf(status + strlen(status),"Array : [ ");
456 for (size_t i = 0 ; i < 10 ; i++)
457 {
458 if(i<size_array_len)
459 sprintf(status + strlen(status)," %d,",size_array[i]);
460 }
461
462 if(10<size_array_len)
463 sprintf(status + strlen(status)," ... ");
464 sprintf(status + strlen(status)," ]");
465
466 sprintf(status + strlen(status),"<br>");
467 sprintf(status + strlen(status),"%s",styles_names[app->i_style]);
468
469
470
471 return status;
472}
473
474void
475test_textblock_fit(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
476{
477 app = calloc(sizeof(APP), 1);
478
479 elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
480
481 app->win = elm_win_util_standard_add("Main", "App");
482 elm_win_autodel_set(app->win, EINA_TRUE);
483
484 app->box = elm_box_add(app->win);
485 app->boxHor = elm_box_add(app->box);
486 app->boxHor2 = elm_box_add(app->box);
487 app->txtblock = evas_object_textblock_add(app->box);
488 app->bg = elm_bg_add(app->box);
489 elm_bg_color_set(app->bg,255,255,255);
490
491 Evas_Textblock_Style *style = evas_textblock_style_new();
492 evas_textblock_style_set(style,styles[0]);
493 evas_object_textblock_style_set(app->txtblock,style);
494 evas_object_textblock_text_markup_set(app->txtblock,contents[0]);
495
496 elm_box_horizontal_set(app->boxHor, EINA_TRUE);
497 elm_box_horizontal_set(app->boxHor2, EINA_TRUE);
498
499 evas_object_size_hint_weight_set(app->box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
500 evas_object_size_hint_align_set(app->box, EVAS_HINT_FILL, EVAS_HINT_FILL);
501
502
503 evas_object_size_hint_weight_set(app->box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
504 evas_object_size_hint_align_set(app->box, EVAS_HINT_FILL, EVAS_HINT_FILL);
505
506 evas_object_show(app->txtblock);
507 evas_object_show(app->bg);
508 evas_object_show(app->box);
509 evas_object_show(app->boxHor);
510 evas_object_show(app->boxHor2);
511
512 elm_box_pack_end(app->box, app->bg);
513 elm_box_pack_end(app->box, app->boxHor);
514 elm_box_pack_end(app->box, app->boxHor2);
515
516 elm_object_content_set(app->bg,app->txtblock);
517
518 elm_win_resize_object_add(app->win, app->box);
519 evas_object_resize(app->win, 320, 480);
520
521 for(int i = 0 ; i < BUTTON_ALL ; i++)
522 {
523 app->btn[i] = elm_button_add(app->boxHor);
524 evas_object_smart_callback_add(app->btn[i], "clicked", _btn_clicked, NULL);
525 elm_object_text_set(app->btn[i], BUTTON_STR[i]);
526 elm_box_pack_end(app->boxHor, app->btn[i]);
527 evas_object_show(app->btn[i]);
528 }
529
530 app->lbl_status = elm_label_add(app->boxHor2);
531 elm_object_text_set(app->lbl_status, get_fit_status(app->txtblock));
532 elm_box_pack_end(app->boxHor2, app->lbl_status);
533 evas_object_show(app->lbl_status);
534
535 evas_object_size_hint_weight_set(app->txtblock, EVAS_HINT_EXPAND,EVAS_HINT_EXPAND);
536 evas_object_size_hint_align_set(app->txtblock, EVAS_HINT_FILL, EVAS_HINT_FILL);
537
538 evas_object_size_hint_weight_set(app->bg, EVAS_HINT_EXPAND,EVAS_HINT_EXPAND);
539 evas_object_size_hint_align_set(app->bg, EVAS_HINT_FILL, EVAS_HINT_FILL);
540
541 evas_object_show(app->win);
542}
543
312/*** Label Wrap **************************************************************/ 544/*** Label Wrap **************************************************************/
313void 545void
314test_label_wrap(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) 546test_label_wrap(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
diff --git a/src/lib/edje/edje_data.c b/src/lib/edje/edje_data.c
index 08fdae4256..ca9cbf11ad 100644
--- a/src/lib/edje/edje_data.c
+++ b/src/lib/edje/edje_data.c
@@ -1188,6 +1188,8 @@ _edje_edd_init(void)
1188 EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_description_textblock, Edje_Part_Description_Text, "text.size_range_max", text.size_range_max, EET_T_INT); 1188 EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_description_textblock, Edje_Part_Description_Text, "text.size_range_max", text.size_range_max, EET_T_INT);
1189 EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_description_textblock, Edje_Part_Description_Text, "text.fit_x", text.fit_x, EET_T_UCHAR); 1189 EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_description_textblock, Edje_Part_Description_Text, "text.fit_x", text.fit_x, EET_T_UCHAR);
1190 EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_description_textblock, Edje_Part_Description_Text, "text.fit_y", text.fit_y, EET_T_UCHAR); 1190 EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_description_textblock, Edje_Part_Description_Text, "text.fit_y", text.fit_y, EET_T_UCHAR);
1191 EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_description_textblock, Edje_Part_Description_Text, "text.fit_step", text.fit_step, EET_T_UINT);
1192 EET_DATA_DESCRIPTOR_ADD_LIST_UINT(_edje_edd_edje_part_description_textblock, Edje_Part_Description_Text, "text.fit_size_array", text.fit_size_array);
1191 EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_description_textblock, Edje_Part_Description_Text, "text.min_x", text.min_x, EET_T_UCHAR); 1193 EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_description_textblock, Edje_Part_Description_Text, "text.min_x", text.min_x, EET_T_UCHAR);
1192 EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_description_textblock, Edje_Part_Description_Text, "text.min_y", text.min_y, EET_T_UCHAR); 1194 EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_description_textblock, Edje_Part_Description_Text, "text.min_y", text.min_y, EET_T_UCHAR);
1193 EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_description_textblock, Edje_Part_Description_Text, "text.max_x", text.max_x, EET_T_UCHAR); 1195 EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_description_textblock, Edje_Part_Description_Text, "text.max_x", text.max_x, EET_T_UCHAR);
diff --git a/src/lib/edje/edje_private.h b/src/lib/edje/edje_private.h
index c3e4e1659a..14b7630be5 100644
--- a/src/lib/edje/edje_private.h
+++ b/src/lib/edje/edje_private.h
@@ -1460,6 +1460,9 @@ struct _Edje_Part_Description_Spec_Text
1460 int id_text_source; /* -1 if none */ 1460 int id_text_source; /* -1 if none */
1461 int size_range_min; 1461 int size_range_min;
1462 int size_range_max; /* -1 means, no bound. */ 1462 int size_range_max; /* -1 means, no bound. */
1463 unsigned int fit_step;
1464 /*FIXME THIS SHOULD BE EINA_LIST*/
1465 Eina_List *fit_size_array;
1463 1466
1464 unsigned char fit_x; /* resize font size down to fit in x dir */ 1467 unsigned char fit_x; /* resize font size down to fit in x dir */
1465 unsigned char fit_y; /* resize font size down to fit in y dir */ 1468 unsigned char fit_y; /* resize font size down to fit in y dir */
diff --git a/src/lib/edje/edje_textblock.c b/src/lib/edje/edje_textblock.c
index c7e58c3148..732b583e78 100644
--- a/src/lib/edje/edje_textblock.c
+++ b/src/lib/edje/edje_textblock.c
@@ -1,25 +1,5 @@
1#include "edje_private.h" 1#include "edje_private.h"
2 2
3static double
4_edje_part_recalc_single_textblock_scale_range_adjust(Edje_Part_Description_Text *chosen_desc, double base_scale, double scale)
5{
6 double size, min, max;
7
8 if (chosen_desc->text.size == 0)
9 return scale;
10
11 min = base_scale * chosen_desc->text.size_range_min;
12 max = chosen_desc->text.size_range_max * base_scale;
13 size = chosen_desc->text.size * scale;
14
15 if ((size > max) && (max > 0))
16 scale = max / (double)chosen_desc->text.size;
17 else if (size < min)
18 scale = min / (double)chosen_desc->text.size;
19
20 return scale;
21}
22
23/* 3/*
24 * Legacy function for min/max calculation of textblock part. 4 * Legacy function for min/max calculation of textblock part.
25 * It can't calculate min/max properly in many cases. 5 * It can't calculate min/max properly in many cases.
@@ -431,7 +411,6 @@ _edje_part_recalc_single_textblock(FLOAT_T sc,
431 411
432 if (chosen_desc) 412 if (chosen_desc)
433 { 413 {
434 Evas_Coord tw, th;
435 const char *text = ""; 414 const char *text = "";
436 const char *style = ""; 415 const char *style = "";
437 Evas_Textblock_Style *stl = NULL; 416 Evas_Textblock_Style *stl = NULL;
@@ -503,76 +482,29 @@ _edje_part_recalc_single_textblock(FLOAT_T sc,
503 482
504 if ((chosen_desc->text.fit_x) || (chosen_desc->text.fit_y)) 483 if ((chosen_desc->text.fit_x) || (chosen_desc->text.fit_y))
505 { 484 {
506 double base_s = 1.0; 485 unsigned int size_array[255];
507 double orig_s; 486 size_t size_array_len = 0;
508 double s = base_s; 487 Eina_List *l;
488 unsigned int *value;
489 EINA_LIST_FOREACH(chosen_desc->text.fit_size_array, l, value)
490 {
491 size_array[size_array_len++] = *value;
492 }
509 493
510 if (ep->part->scale) base_s = TO_DOUBLE(sc); 494 unsigned int mode = TEXTBLOCK_FIT_MODE_NONE;
511 efl_gfx_entity_scale_set(ep->object, base_s);
512 efl_canvas_text_size_native_get(ep->object, &tw, &th);
513 495
514 orig_s = base_s;
515 /* Now make it bigger so calculations will be more accurate
516 * and less influenced by hinting... */
517 {
518 orig_s = _edje_part_recalc_single_textblock_scale_range_adjust(chosen_desc, base_s,
519 orig_s * TO_INT(params->eval.w) / tw);
520 efl_gfx_entity_scale_set(ep->object, orig_s);
521 efl_canvas_text_size_native_get(ep->object, &tw, &th);
522 }
523 if (chosen_desc->text.fit_x) 496 if (chosen_desc->text.fit_x)
524 { 497 mode |= TEXTBLOCK_FIT_MODE_WIDTH;
525 if (tw > 0)
526 {
527 s = _edje_part_recalc_single_textblock_scale_range_adjust(chosen_desc, base_s,
528 orig_s * TO_INT(params->eval.w) / tw);
529 efl_gfx_entity_scale_set(ep->object, s);
530 efl_canvas_text_size_native_get(ep->object, NULL, NULL);
531 }
532 }
533 if (chosen_desc->text.fit_y) 498 if (chosen_desc->text.fit_y)
499 mode |= TEXTBLOCK_FIT_MODE_HEIGHT;
500 evas_textblock_fit_options_set(ep->object, mode);
501 evas_textblock_fit_step_size_set(ep->object, chosen_desc->text.fit_step);
502 if ( chosen_desc->text.size_range_min || chosen_desc->text.size_range_max)
503 evas_textblock_fit_size_range_set(ep->object, chosen_desc->text.size_range_min, chosen_desc->text.size_range_max);
504 if (size_array_len>0)
534 { 505 {
535 if (th > 0) 506 evas_textblock_fit_size_array_set(ep->object,size_array,size_array_len);
536 {
537 double tmp_s = _edje_part_recalc_single_textblock_scale_range_adjust(chosen_desc, base_s,
538 orig_s * TO_INT(params->eval.h) / th);
539 /* If we already have X fit, restrict Y to be no bigger
540 * than what we got with X. */
541 if (!((chosen_desc->text.fit_x) && (tmp_s > s)))
542 {
543 s = tmp_s;
544 }
545
546 efl_gfx_entity_scale_set(ep->object, s);
547 efl_canvas_text_size_native_get(ep->object, NULL, NULL);
548 }
549 } 507 }
550
551 /* Final tuning, try going down 90% at a time, hoping it'll
552 * actually end up being correct. */
553 {
554 int i = 5; /* Tries before we give up. */
555 Evas_Coord fw, fh;
556 efl_canvas_text_size_native_get(ep->object, &fw, &fh);
557
558 /* If we are still too big, try reducing the size to
559 * 95% each try. */
560 while ((i > 0) &&
561 ((chosen_desc->text.fit_x && (fw > TO_INT(params->eval.w))) ||
562 (chosen_desc->text.fit_y && (fh > TO_INT(params->eval.h)))))
563 {
564 double tmp_s = _edje_part_recalc_single_textblock_scale_range_adjust(chosen_desc, base_s, s * 0.95);
565
566 /* Break if we are not making any progress. */
567 if (EQ(tmp_s, s))
568 break;
569 s = tmp_s;
570
571 efl_gfx_entity_scale_set(ep->object, s);
572 efl_canvas_text_size_native_get(ep->object, &fw, &fh);
573 i--;
574 }
575 }
576 } 508 }
577 509
578 if ((ed->file->efl_version.major >= 1) && (ed->file->efl_version.minor >= 19)) 510 if ((ed->file->efl_version.major >= 1) && (ed->file->efl_version.minor >= 19))
diff --git a/src/lib/eet/Eet.h b/src/lib/eet/Eet.h
index 25babe1578..eb7cb5324f 100644
--- a/src/lib/eet/Eet.h
+++ b/src/lib/eet/Eet.h
@@ -3538,6 +3538,29 @@ eet_data_descriptor_encode(Eet_Data_Descriptor *edd,
3538 3538
3539/** 3539/**
3540 * @ingroup Eet_Data_Group 3540 * @ingroup Eet_Data_Group
3541 * @brief Adds a linked list of unsigned integers to a data descriptor.
3542 * @param edd The data descriptor to add the type to.
3543 * @param struct_type The type of the struct.
3544 * @param name The string name to use to encode/decode this member
3545 * (must be a constant global and never change).
3546 * @param member The struct member itself to be encoded.
3547 *
3548 * This macro lets you easily add a linked list of unsigned int. All the
3549 * parameters are the same as for EET_DATA_DESCRIPTOR_ADD_BASIC().
3550 *
3551 * @since 1.24.0
3552 */
3553#define EET_DATA_DESCRIPTOR_ADD_LIST_UINT(edd, struct_type, name, member) \
3554 do { \
3555 struct_type ___ett; \
3556 eet_data_descriptor_element_add(edd, name, EET_T_UINT, EET_G_LIST, \
3557 (char *)(& (___ett.member)) - \
3558 (char *)(& (___ett)), \
3559 0, /* 0, */ NULL, NULL); \
3560 } while (0)
3561
3562/**
3563 * @ingroup Eet_Data_Group
3541 * @brief Adds a hash type to a data descriptor. 3564 * @brief Adds a hash type to a data descriptor.
3542 * @param edd The data descriptor to add the type to. 3565 * @param edd The data descriptor to add the type to.
3543 * @param struct_type The type of the struct. 3566 * @param struct_type The type of the struct.
diff --git a/src/lib/evas/canvas/evas_object_textblock.c b/src/lib/evas/canvas/evas_object_textblock.c
index 1ec71f2f53..e0dd39fd3c 100644
--- a/src/lib/evas/canvas/evas_object_textblock.c
+++ b/src/lib/evas/canvas/evas_object_textblock.c
@@ -245,6 +245,12 @@ typedef struct _Efl_Canvas_Text_Filter_Program Efl_Canvas_Text_Filter_Program;
245typedef struct _Text_Item_Filter Text_Item_Filter; 245typedef struct _Text_Item_Filter Text_Item_Filter;
246/** 246/**
247 * @internal 247 * @internal
248 * @typedef TEXT_FIT_CONTENT_CONFIG
249 * Configurations used to fit content inside Textblock
250 */
251typedef struct _TEXT_FIT_CONTENT_CONFIG TEXT_FIT_CONTENT_CONFIG;
252/**
253 * @internal
248 * @def IS_AT_END(ti, ind) 254 * @def IS_AT_END(ti, ind)
249 * Return true if ind is at the end of the text item, false otherwise. 255 * Return true if ind is at the end of the text item, false otherwise.
250 */ 256 */
@@ -581,6 +587,20 @@ struct _Efl_Text_Annotate_Annotation
581 Eina_Bool is_item : 1; /**< indicates it is an item/object placeholder */ 587 Eina_Bool is_item : 1; /**< indicates it is an item/object placeholder */
582}; 588};
583 589
590struct _TEXT_FIT_CONTENT_CONFIG
591{
592 unsigned int options;
593 unsigned int min_font_size,max_font_size;
594 unsigned int step_size;
595 unsigned int *p_size_array;
596 size_t size_list_length;
597 Eina_Size2D size_cache[256+1]; /** used hash font sizes 1-255 */
598 Eina_Size2D last_size;
599 int last_size_index;
600 Eina_Bool force_refit;
601 char fit_style[256];
602};
603
584#define _FMT(x) (o->default_format.format.x) 604#define _FMT(x) (o->default_format.format.x)
585#define _FMT_INFO(x) (o->default_format.info.x) 605#define _FMT_INFO(x) (o->default_format.info.x)
586 606
@@ -655,6 +675,7 @@ struct _Evas_Object_Textblock
655 Eina_Hash *sources; 675 Eina_Hash *sources;
656 Text_Item_Filter *text_items; // inlist 676 Text_Item_Filter *text_items; // inlist
657 } gfx_filter; 677 } gfx_filter;
678 TEXT_FIT_CONTENT_CONFIG fit_content_config;
658 Eina_Bool redraw : 1; 679 Eina_Bool redraw : 1;
659 Eina_Bool changed : 1; 680 Eina_Bool changed : 1;
660 Eina_Bool pause_change : 1; 681 Eina_Bool pause_change : 1;
@@ -669,6 +690,7 @@ struct _Evas_Object_Textblock
669 Eina_Bool multiline : 1; 690 Eina_Bool multiline : 1;
670 Eina_Bool wrap_changed : 1; 691 Eina_Bool wrap_changed : 1;
671 Eina_Bool auto_styles : 1; 692 Eina_Bool auto_styles : 1;
693 Eina_Bool fit_in_progress : 1;
672}; 694};
673 695
674struct _Evas_Textblock_Selection_Iterator 696struct _Evas_Textblock_Selection_Iterator
@@ -783,6 +805,21 @@ static void _evas_textblock_cursor_copy(Efl_Text_Cursor_Cursor *dst, const Efl_T
783static void 805static void
784_textblock_style_generic_set(Evas_Object *eo_obj, Evas_Textblock_Style *ts, const char *key); 806_textblock_style_generic_set(Evas_Object *eo_obj, Evas_Textblock_Style *ts, const char *key);
785 807
808
809/*********Internal fitting Functions and Defines*********/
810int fit_cache_clear(TEXT_FIT_CONTENT_CONFIG *fc,const unsigned int fit_cache_flags);
811int fit_text_block(Evas_Object *eo_obj);
812int fit_fill_internal_list(TEXT_FIT_CONTENT_CONFIG *fc);
813int fit_start_fitting(Evas_Object *eo_obj);
814int fit_finish_fitting(Evas_Object *eo_obj);
815Eina_Bool fit_is_fitting(const Evas_Object *eo_obj);
816const unsigned int FIT_CACHE_CANVAS_SIZE = 0x0001;
817const unsigned int FIT_CACHE_INTERNAL_SIZE_ARRAY = 0x0002;
818const unsigned int FIT_CACHE_FORCE_REFIT = 0x0004;
819const unsigned int FIT_CACHE_ALL = 0x000F;
820
821
822static void _canvas_text_format_changed(Eo *eo_obj, Efl_Canvas_Text_Data *o);
786/** selection iterator */ 823/** selection iterator */
787/** 824/**
788 * @internal 825 * @internal
@@ -7017,6 +7054,11 @@ _layout_setup(Ctxt *c, const Eo *eo_obj, Evas_Coord w, Evas_Coord h)
7017 finalize = EINA_TRUE; 7054 finalize = EINA_TRUE;
7018 } 7055 }
7019 } 7056 }
7057 /* Extra Style used by fitting configure*/
7058 if (*o->fit_content_config.fit_style)
7059 {
7060 _format_fill(c->obj, c->fmt, o->fit_content_config.fit_style);
7061 }
7020 7062
7021 if (finalize) 7063 if (finalize)
7022 _format_finalize(c->obj, c->fmt); 7064 _format_finalize(c->obj, c->fmt);
@@ -7111,7 +7153,9 @@ _relayout_if_needed(const Evas_Object *eo_obj, Efl_Canvas_Text_Data *o)
7111 if (obj->delete_me) return EINA_TRUE; 7153 if (obj->delete_me) return EINA_TRUE;
7112 7154
7113 /* XXX const */ 7155 /* XXX const */
7114 evas_object_textblock_coords_recalc((Evas_Object *)eo_obj, obj, obj->private_data); 7156 if(!fit_is_fitting(eo_obj))
7157 evas_object_textblock_coords_recalc((Evas_Object *)eo_obj, obj, obj->private_data);
7158
7115 if (o->formatted.valid) 7159 if (o->formatted.valid)
7116 { 7160 {
7117 return EINA_TRUE; 7161 return EINA_TRUE;
@@ -7261,6 +7305,10 @@ _efl_canvas_text_efl_object_constructor(Eo *eo_obj, Efl_Canvas_Text_Data *class_
7261 _FMT(ellipsis) = -1; 7305 _FMT(ellipsis) = -1;
7262 _FMT_INFO(bitmap_scalable) = EFL_TEXT_FONT_BITMAP_SCALABLE_COLOR; 7306 _FMT_INFO(bitmap_scalable) = EFL_TEXT_FONT_BITMAP_SCALABLE_COLOR;
7263 7307
7308 /* Fit default properties*/
7309 evas_textblock_fit_size_range_set(eo_obj,1,255);
7310 evas_textblock_fit_step_size_set(eo_obj,1);
7311
7264 o->auto_styles = EINA_TRUE; 7312 o->auto_styles = EINA_TRUE;
7265 7313
7266 return eo_obj; 7314 return eo_obj;
@@ -11040,10 +11088,13 @@ _evas_textblock_changed(Efl_Canvas_Text_Data *o, Evas_Object *eo_obj)
11040 o->formatted.valid = 0; 11088 o->formatted.valid = 0;
11041 o->native.valid = 0; 11089 o->native.valid = 0;
11042 o->content_changed = 1; 11090 o->content_changed = 1;
11043 if (o->markup_text) 11091 if (!fit_is_fitting(eo_obj))
11044 { 11092 {
11045 eina_stringshare_del(o->markup_text); 11093 if (o->markup_text)
11046 o->markup_text = NULL; 11094 {
11095 eina_stringshare_del(o->markup_text);
11096 o->markup_text = NULL;
11097 }
11047 } 11098 }
11048 11099
11049 // FIXME: emit ONCE after this following checks 11100 // FIXME: emit ONCE after this following checks
@@ -11053,6 +11104,15 @@ _evas_textblock_changed(Efl_Canvas_Text_Data *o, Evas_Object *eo_obj)
11053 _cursor_emit_if_changed(data_obj); 11104 _cursor_emit_if_changed(data_obj);
11054 } 11105 }
11055 11106
11107 /*
11108 If format changed we need to refit content again.
11109 If content already fitting then ignore fitting (fitting cause fall to this callback)
11110 */
11111 if (!fit_is_fitting(eo_obj))
11112 {
11113 fit_cache_clear(&o->fit_content_config, FIT_CACHE_ALL);
11114 fit_text_block(eo_obj);
11115 }
11056 evas_object_change(eo_obj, obj); 11116 evas_object_change(eo_obj, obj);
11057} 11117}
11058 11118
@@ -14075,6 +14135,11 @@ evas_object_textblock_free(Evas_Object *eo_obj)
14075 14135
14076 /* remove obstacles */ 14136 /* remove obstacles */
14077 _obstacles_free(eo_obj, o); 14137 _obstacles_free(eo_obj, o);
14138 if (o->fit_content_config.p_size_array)
14139 {
14140 free(o->fit_content_config.p_size_array);
14141 o->fit_content_config.p_size_array = NULL;
14142 }
14078 14143
14079#ifdef HAVE_HYPHEN 14144#ifdef HAVE_HYPHEN
14080 /* Hyphenation */ 14145 /* Hyphenation */
@@ -15161,6 +15226,7 @@ _efl_canvas_text_efl_gfx_filter_filter_source_get(const Eo *obj EINA_UNUSED, Efl
15161 return eina_hash_find(pd->gfx_filter.sources, name); 15226 return eina_hash_find(pd->gfx_filter.sources, name);
15162} 15227}
15163 15228
15229
15164static void 15230static void
15165evas_object_textblock_coords_recalc(Evas_Object *eo_obj, 15231evas_object_textblock_coords_recalc(Evas_Object *eo_obj,
15166 Evas_Object_Protected_Data *obj, 15232 Evas_Object_Protected_Data *obj,
@@ -15218,6 +15284,17 @@ evas_object_textblock_coords_recalc(Evas_Object *eo_obj,
15218 o->formatted.valid = 0; 15284 o->formatted.valid = 0;
15219 o->changed = 1; 15285 o->changed = 1;
15220 } 15286 }
15287
15288 Evas_Coord x,y,w,h;
15289 evas_object_geometry_get(eo_obj, &x, &y, &w, &h);
15290 if (
15291 (w!=o->fit_content_config.last_size.w || h!=o->fit_content_config.last_size.h) &&
15292 (o->fit_content_config.options & TEXTBLOCK_FIT_MODE_ALL) != TEXTBLOCK_FIT_MODE_NONE
15293 )
15294 {
15295 fit_cache_clear(&o->fit_content_config, FIT_CACHE_INTERNAL_SIZE_ARRAY);
15296 fit_text_block(eo_obj);
15297 }
15221} 15298}
15222 15299
15223static void 15300static void
@@ -15345,6 +15422,54 @@ done:
15345 eo_obj, is_v, was_v); 15422 eo_obj, is_v, was_v);
15346} 15423}
15347 15424
15425void fit_style_update(Evas_Object *object, int i_font_size, Eina_Bool disable_ellipsis, Eina_Bool disable_wrap)
15426{
15427 Efl_Canvas_Text_Data *o = efl_data_scope_get(object, MY_CLASS);
15428 TEXT_FIT_CONTENT_CONFIG * fc = &o->fit_content_config;
15429 memset(fc->fit_style,0,sizeof(fc->fit_style));
15430 char * fit_style = fc->fit_style;
15431 if (i_font_size >= 0)
15432 {
15433 char font_size[0xF] = {0};
15434 char *pfont = font_size;
15435 sprintf(font_size, "font_size=%i ", i_font_size);
15436 while (*pfont)
15437 {
15438 *fit_style = *pfont;
15439 pfont++;
15440 fit_style++;
15441 }
15442 }
15443
15444 if (disable_ellipsis == EINA_TRUE)
15445 {
15446 *fit_style = ' ';
15447 fit_style++;
15448 char *p = "ellipsis=2.0";
15449 while (*p)
15450 {
15451 *fit_style = *p;
15452 p++;
15453 fit_style++;
15454 }
15455 }
15456
15457 if (disable_wrap == EINA_TRUE)
15458 {
15459 *fit_style = ' ';
15460 fit_style++;
15461 char *p = "wrap=none";
15462 while (*p)
15463 {
15464 *fit_style = *p;
15465 p++;
15466 fit_style++;
15467 }
15468 }
15469
15470 _canvas_text_format_changed(object,o);
15471}
15472
15348static void 15473static void
15349evas_object_textblock_render_post(Evas_Object *eo_obj EINA_UNUSED, 15474evas_object_textblock_render_post(Evas_Object *eo_obj EINA_UNUSED,
15350 Evas_Object_Protected_Data *obj, 15475 Evas_Object_Protected_Data *obj,
@@ -17076,6 +17201,373 @@ _efl_canvas_text_async_layout(Eo *eo_obj EINA_UNUSED, Efl_Canvas_Text_Data *o)
17076 return f; 17201 return f;
17077} 17202}
17078 17203
17204
17205
17206
17207/* Fitting Internal Functions*/
17208
17209int fit_cache_clear(TEXT_FIT_CONTENT_CONFIG *fc, unsigned int fit_cache_flags)
17210{
17211 EINA_SAFETY_ON_NULL_RETURN_VAL(fc, EVAS_ERROR_INVALID_PARAM);
17212 if ((fit_cache_flags&FIT_CACHE_CANVAS_SIZE) == FIT_CACHE_CANVAS_SIZE)
17213 fc->last_size = EINA_SIZE2D(0, 0);
17214 if ((fit_cache_flags&FIT_CACHE_INTERNAL_SIZE_ARRAY) == FIT_CACHE_INTERNAL_SIZE_ARRAY)
17215 for(int i = 0 ; i < 255 ; i++) fc->size_cache[i] = EINA_SIZE2D(0,0);
17216 if ((fit_cache_flags&FIT_CACHE_FORCE_REFIT) == FIT_CACHE_FORCE_REFIT)
17217 fc->force_refit = EINA_TRUE;
17218 return EVAS_ERROR_SUCCESS;
17219}
17220
17221int fit_start_fitting(Evas_Object *eo_obj)
17222{
17223 EINA_SAFETY_ON_NULL_RETURN_VAL(eo_obj, EVAS_ERROR_INVALID_PARAM);
17224 Efl_Canvas_Text_Data *o = efl_data_scope_get(eo_obj, MY_CLASS);
17225 if (o->fit_in_progress == EINA_TRUE)
17226 return EVAS_ERROR_INVALID_OPERATION;
17227
17228 o->fit_in_progress = EINA_TRUE;
17229 return EVAS_ERROR_SUCCESS;
17230}
17231
17232int fit_finish_fitting(Evas_Object *eo_obj)
17233{
17234 EINA_SAFETY_ON_NULL_RETURN_VAL(eo_obj, EVAS_ERROR_INVALID_PARAM);
17235 Efl_Canvas_Text_Data *o = efl_data_scope_get(eo_obj, MY_CLASS);
17236 if (o->fit_in_progress == EINA_FALSE)
17237 return EVAS_ERROR_INVALID_OPERATION;
17238
17239 o->fit_in_progress = EINA_FALSE;
17240 return EVAS_ERROR_SUCCESS;
17241}
17242
17243Eina_Bool fit_is_fitting(const Evas_Object *eo_obj)
17244{
17245 EINA_SAFETY_ON_NULL_RETURN_VAL(eo_obj, EVAS_ERROR_INVALID_PARAM);
17246 Efl_Canvas_Text_Data *o = efl_data_scope_get(eo_obj, MY_CLASS);
17247 return o->fit_in_progress;
17248}
17249
17250int fit_text_block(Evas_Object *eo_obj)
17251{
17252 EINA_SAFETY_ON_NULL_RETURN_VAL(eo_obj, EVAS_ERROR_INVALID_PARAM);
17253 Efl_Canvas_Text_Data *o = efl_data_scope_get(eo_obj, MY_CLASS);
17254 Evas_Coord x,y,w,h;
17255 Evas_Coord wf_new,hf_new;
17256
17257 TEXT_FIT_CONTENT_CONFIG * fc = &o->fit_content_config;
17258
17259 if (fc->options == TEXTBLOCK_FIT_MODE_NONE && !fc->force_refit)
17260 return EVAS_ERROR_SUCCESS;
17261
17262
17263 if (fc->options == TEXTBLOCK_FIT_MODE_NONE)
17264 {
17265 fit_start_fitting(eo_obj);
17266 fc->force_refit = 0;
17267 fit_style_update(eo_obj,-1, EINA_FALSE, EINA_FALSE);
17268 fit_finish_fitting(eo_obj);
17269 return EVAS_ERROR_SUCCESS;
17270 }
17271
17272 evas_object_geometry_get(eo_obj, &x, &y, &w, &h);
17273
17274 if (w > 0 && h > 0)
17275 {
17276 Eina_Bool b_fit_width = ((fc->options & TEXTBLOCK_FIT_MODE_WIDTH) == TEXTBLOCK_FIT_MODE_WIDTH);
17277 Eina_Bool b_fit_height = ((fc->options & TEXTBLOCK_FIT_MODE_HEIGHT) == TEXTBLOCK_FIT_MODE_HEIGHT);
17278 //FIXME uncomment condition when style is not warp
17279 if ( fc->force_refit || /*(w != fc->last_size.w && b_fit_width) || (h != fc->last_size.h && b_fit_height)*/ EINA_TRUE)
17280 {
17281 /* Extra Check to reduce recalculate */
17282 Eina_Bool b_max_reached = (fc->last_size_index == ((int)fc->size_list_length) - 1);
17283 Eina_Bool b_min_reached = (fc->last_size_index == 0);
17284 /* 1 - If max font size reached and text block size increased*/
17285 if (!fc->force_refit && b_max_reached && ((b_fit_width ? (w >= fc->last_size.w) : EINA_TRUE) && (b_fit_height ? (h >= fc->last_size.h) : EINA_TRUE)))
17286 return EVAS_ERROR_SUCCESS;
17287 /* 2- If min font size reached and text block size decreased*/
17288 if (!fc->force_refit && b_min_reached && ((b_fit_width ? (w <= fc->last_size.w) : EINA_TRUE) && (b_fit_height ? (h <= fc->last_size.h) : EINA_TRUE)))
17289 {
17290 /*This is needed to recalculate ellipsis, inside fitting to avoid losing markup_text*/
17291 fit_start_fitting(eo_obj);
17292 _canvas_text_format_changed(eo_obj, o);
17293 fit_finish_fitting(eo_obj);
17294 return EVAS_ERROR_SUCCESS;
17295 }
17296
17297 fit_start_fitting(eo_obj);
17298
17299 fc->force_refit = EINA_FALSE;
17300 fc->last_size.w = w;
17301 fc->last_size.h = h;
17302
17303 int r = fc->size_list_length;
17304 int l = 0;
17305
17306 Eina_Bool bwrap = EINA_FALSE;
17307 if (fc->options == TEXTBLOCK_FIT_MODE_WIDTH)
17308 {
17309 bwrap = EINA_TRUE;
17310 }
17311
17312 while(r > l)
17313 {
17314 int mid = (r + l) / 2;
17315 /*cache font sizes vaules from 0-255 in size_cache array*/
17316 size_t font_size = fc->p_size_array[mid];
17317 if (font_size <= 0xFF && (fc->size_cache[font_size].w != 0 && fc->size_cache[font_size].h != 0))
17318 {
17319 wf_new = fc->size_cache[font_size].w;
17320 hf_new = fc->size_cache[font_size].h;
17321 }
17322 else
17323 {
17324 fit_style_update(eo_obj,fc->p_size_array[mid],EINA_TRUE,bwrap);
17325 efl_canvas_text_size_formatted_get(eo_obj, &wf_new, &hf_new);
17326 if (fc->p_size_array[mid]<255)
17327 {
17328 fc->size_cache[font_size].w = wf_new;
17329 fc->size_cache[font_size].h = hf_new;
17330 }
17331 }
17332
17333 if (
17334 ((wf_new > w) & ((fc->options & TEXTBLOCK_FIT_MODE_WIDTH) == TEXTBLOCK_FIT_MODE_WIDTH)) ||
17335 ((hf_new > h) & ((fc->options & TEXTBLOCK_FIT_MODE_HEIGHT) == TEXTBLOCK_FIT_MODE_HEIGHT)))
17336 {
17337 r = mid;
17338 }
17339 else
17340 {
17341 l = mid + 1;
17342 }
17343 }
17344
17345 /*Lower bound founded, subtract one to move for nearest value*/
17346 fc->last_size_index = MAX(l-1, 0);
17347 fit_style_update(eo_obj,fc->p_size_array[fc->last_size_index],(fc->last_size_index != 0) && fc->options != TEXTBLOCK_FIT_MODE_HEIGHT ,EINA_FALSE);
17348 fit_finish_fitting(eo_obj);
17349 }
17350 }
17351 return EVAS_ERROR_SUCCESS;
17352}
17353
17354int fit_fill_internal_list(TEXT_FIT_CONTENT_CONFIG *fc)
17355{
17356 int diff = (fc->max_font_size - fc->min_font_size);
17357 if (fc->p_size_array)
17358 {
17359 free(fc->p_size_array);
17360 fc->p_size_array = NULL;
17361 }
17362 if (diff == 0)
17363 {
17364 fc->size_list_length = 1;
17365 fc->p_size_array = malloc(sizeof(unsigned int) * fc->size_list_length);
17366 if (!fc->p_size_array)
17367 return EVAS_ERROR_NO_MEMORY;
17368 fc->p_size_array[0] = fc->max_font_size;
17369 return EVAS_ERROR_SUCCESS;
17370 }
17371
17372 fc->size_list_length = 2 + diff / MAX(fc->step_size, 1);
17373 fc->p_size_array = malloc(sizeof(unsigned int) * fc->size_list_length);
17374 if (!fc->p_size_array)
17375 return EVAS_ERROR_NO_MEMORY;
17376
17377 size_t i ;
17378 for (i = 0 ; i < fc->size_list_length - 1; i++)
17379 {
17380 fc->p_size_array[i] = fc->min_font_size + i * MAX(fc->step_size, 1);
17381 }
17382 fc->p_size_array[fc->size_list_length - 1] = fc->max_font_size;
17383 fc->last_size_index = -1;
17384 return EVAS_ERROR_SUCCESS;
17385}
17386
17387
17388
17389EAPI int evas_textblock_fit_options_set(Evas_Object *obj, unsigned int options)
17390{
17391 EINA_SAFETY_ON_NULL_RETURN_VAL(obj, EVAS_ERROR_INVALID_PARAM);
17392 Efl_Canvas_Text_Data *o = efl_data_scope_get(obj, MY_CLASS);
17393 TEXT_FIT_CONTENT_CONFIG * fc = &o->fit_content_config;
17394 if (fc->options == options)
17395 return EVAS_ERROR_SUCCESS;
17396
17397 fc->options = options;
17398 fit_cache_clear(fc, FIT_CACHE_ALL);
17399 fit_text_block(obj);
17400 return EVAS_ERROR_SUCCESS;
17401}
17402
17403EAPI int evas_textblock_fit_options_get(const Evas_Object *obj, unsigned int *p_options)
17404{
17405 EINA_SAFETY_ON_NULL_RETURN_VAL(obj, EVAS_ERROR_INVALID_PARAM);
17406 Efl_Canvas_Text_Data *o = efl_data_scope_get(obj, MY_CLASS);
17407 TEXT_FIT_CONTENT_CONFIG * fc = &o->fit_content_config;
17408 if (p_options)
17409 *p_options = fc->options;
17410 return EVAS_ERROR_SUCCESS;
17411}
17412
17413EAPI int evas_textblock_fit_size_range_set(Evas_Object *obj, unsigned int min_font_size, unsigned int max_font_size)
17414{
17415 EINA_SAFETY_ON_NULL_RETURN_VAL(obj, EVAS_ERROR_INVALID_PARAM);
17416 Efl_Canvas_Text_Data *o = efl_data_scope_get(obj, MY_CLASS);
17417 TEXT_FIT_CONTENT_CONFIG * fc = &o->fit_content_config;
17418
17419 Eina_Bool max_changed = fc->max_font_size != max_font_size;
17420 Eina_Bool min_changed = fc->min_font_size != min_font_size;
17421
17422 /* last_selected_size used for optimization calculations
17423 * If last_size_index already recach last element in p_size_array
17424 * Skip optimization by setting last_selected_size to -1
17425 */
17426 int last_selected_size = fc->last_size_index;
17427 if (last_selected_size == ((int)fc->size_list_length-1))
17428 last_selected_size = -1;
17429
17430 if (!max_changed && !min_changed)
17431 return EVAS_ERROR_SUCCESS;
17432
17433 if (min_font_size < 0 || max_font_size <0)
17434 return EVAS_ERROR_INVALID_PARAM;
17435
17436 if (max_font_size < min_font_size)
17437 return EVAS_ERROR_INVALID_PARAM;
17438
17439 fc->max_font_size = max_font_size;
17440 fc->min_font_size = min_font_size;
17441
17442 int n_ret = EVAS_ERROR_SUCCESS;
17443 n_ret = fit_cache_clear(fc,FIT_CACHE_FORCE_REFIT);
17444 if (n_ret) return n_ret;
17445 n_ret = fit_fill_internal_list(fc);
17446 if (n_ret) return n_ret;
17447
17448 /* Optimization to reduce calculations
17449 * If only max size changed and last fit size index is still valid, then no need to recalculation
17450 * Where changing max font size will not change content of p_size_array for sizes < max_size
17451 */
17452 if (min_changed || (last_selected_size == -1 || last_selected_size > ((int)fc->size_list_length-1)))
17453 {
17454 n_ret = fit_text_block(obj);
17455 if (n_ret) return n_ret;
17456 }
17457 else
17458 {
17459 /* Keep fit size index */
17460 fc->last_size_index = last_selected_size;
17461 }
17462 return EVAS_ERROR_SUCCESS;
17463}
17464
17465EAPI int evas_textblock_fit_size_range_get(const Evas_Object *obj, unsigned int *p_min_font_size, unsigned int *p_max_font_size)
17466{
17467 EINA_SAFETY_ON_NULL_RETURN_VAL(obj, EVAS_ERROR_INVALID_PARAM);
17468 Efl_Canvas_Text_Data *o = efl_data_scope_get(obj, MY_CLASS);
17469 TEXT_FIT_CONTENT_CONFIG * fc = &o->fit_content_config;
17470
17471 if (p_min_font_size)
17472 *p_min_font_size = fc->min_font_size;
17473
17474 if (p_max_font_size)
17475 *p_max_font_size = fc->max_font_size;
17476
17477 return EVAS_ERROR_SUCCESS;
17478}
17479
17480EAPI int evas_textblock_fit_step_size_set(Evas_Object *obj, unsigned int step_size)
17481{
17482 EINA_SAFETY_ON_NULL_RETURN_VAL(obj, EVAS_ERROR_INVALID_PARAM);
17483 Efl_Canvas_Text_Data *o = efl_data_scope_get(obj, MY_CLASS);
17484 TEXT_FIT_CONTENT_CONFIG * fc = &o->fit_content_config;
17485 if (fc->step_size == step_size)
17486 return EVAS_ERROR_SUCCESS;
17487
17488 if (step_size == 0)
17489 return EVAS_ERROR_INVALID_PARAM;
17490
17491 fc->step_size = step_size;
17492 int n_ret = EVAS_ERROR_SUCCESS;
17493 n_ret = fit_cache_clear(fc, FIT_CACHE_FORCE_REFIT);
17494 if (n_ret) return n_ret;
17495 n_ret = fit_fill_internal_list(fc);
17496 if (n_ret) return n_ret;
17497 n_ret = fit_text_block(obj);
17498 if (n_ret) return n_ret;
17499 return EVAS_ERROR_SUCCESS;
17500}
17501
17502EAPI int evas_textblock_fit_step_size_get(const Evas_Object *obj, unsigned int * p_step_size)
17503{
17504 EINA_SAFETY_ON_NULL_RETURN_VAL(obj, EVAS_ERROR_INVALID_PARAM);
17505 Efl_Canvas_Text_Data *o = efl_data_scope_get(obj, MY_CLASS);
17506 TEXT_FIT_CONTENT_CONFIG * fc = &o->fit_content_config;
17507 if (p_step_size)
17508 *p_step_size = fc->step_size;
17509 return EVAS_ERROR_SUCCESS;
17510}
17511
17512int compareUINT(const void * a, const void * b)
17513{
17514 unsigned int a_value = *(const unsigned int*)a;
17515 unsigned int b_value = *(const unsigned int*)b;
17516
17517 if(a_value > b_value) return 1;
17518 else if(a_value < b_value) return -1;
17519 else return 0;
17520}
17521
17522EAPI int evas_textblock_fit_size_array_set(Evas_Object *obj, const unsigned int *p_size_array, size_t size_array_len)
17523{
17524 int n_ret = EVAS_ERROR_SUCCESS;
17525 EINA_SAFETY_ON_NULL_RETURN_VAL(obj, EVAS_ERROR_INVALID_PARAM);
17526 Efl_Canvas_Text_Data *o = efl_data_scope_get(obj, MY_CLASS);
17527 TEXT_FIT_CONTENT_CONFIG * fc = &o->fit_content_config;
17528 if (size_array_len == 0)
17529 return EVAS_ERROR_INVALID_PARAM;
17530
17531 if (fc->p_size_array)
17532 {
17533 free(fc->p_size_array);
17534 fc->p_size_array = NULL;
17535 fc->size_list_length = 0;
17536 }
17537
17538 fc->p_size_array = malloc(sizeof(unsigned int) * size_array_len);
17539 if (!fc->p_size_array) return EVAS_ERROR_NO_MEMORY;
17540 memcpy(fc->p_size_array,p_size_array,sizeof(unsigned int) * size_array_len);
17541 fc->size_list_length = size_array_len;
17542
17543 fc->last_size_index = -1;
17544
17545 qsort(fc->p_size_array,fc->size_list_length,sizeof(unsigned int),compareUINT);
17546
17547 n_ret = fit_cache_clear(fc, FIT_CACHE_FORCE_REFIT);
17548 if (n_ret) return n_ret;
17549 n_ret = fit_text_block(obj);
17550 if (n_ret) return n_ret;
17551 return EVAS_ERROR_SUCCESS;
17552}
17553
17554EAPI int evas_textblock_fit_size_array_get(const Evas_Object *obj, unsigned int *p_size_array, size_t *p_size_array_len, size_t passed_array_size)
17555{
17556 EINA_SAFETY_ON_NULL_RETURN_VAL(obj, EVAS_ERROR_INVALID_PARAM);
17557 Efl_Canvas_Text_Data *o = efl_data_scope_get(obj, MY_CLASS);
17558 TEXT_FIT_CONTENT_CONFIG * fc = &o->fit_content_config;
17559 if (p_size_array)
17560 {
17561 size_t num = MIN(passed_array_size,fc->size_list_length);
17562 memcpy(p_size_array,fc->p_size_array,sizeof(unsigned int)* num);
17563 }
17564 if (p_size_array_len)
17565 {
17566 *p_size_array_len = fc->size_list_length;
17567 }
17568 return EVAS_ERROR_SUCCESS;
17569}
17570
17079#include "canvas/efl_canvas_text.eo.c" 17571#include "canvas/efl_canvas_text.eo.c"
17080#include "canvas/efl_canvas_text_eo.legacy.c" 17572#include "canvas/efl_canvas_text_eo.legacy.c"
17081#include "canvas/efl_canvas_text_factory.eo.c" // interface 17573#include "canvas/efl_canvas_text_factory.eo.c" // interface
diff --git a/src/lib/evas/canvas/evas_textblock_legacy.h b/src/lib/evas/canvas/evas_textblock_legacy.h
index ae537680c0..27ea6caaae 100644
--- a/src/lib/evas/canvas/evas_textblock_legacy.h
+++ b/src/lib/evas/canvas/evas_textblock_legacy.h
@@ -1056,6 +1056,106 @@ EAPI void evas_textblock_cursor_char_delete(Evas_Textblock_Cursor *cur);
1056 * @ingroup Evas_Textblock 1056 * @ingroup Evas_Textblock
1057 */ 1057 */
1058EAPI Evas_Textblock_Cursor *evas_object_textblock_cursor_get(const Evas_Object *obj); 1058EAPI Evas_Textblock_Cursor *evas_object_textblock_cursor_get(const Evas_Object *obj);
1059
1060
1061
1062/* TEXT BLOCK FIT OPTIONS FLAGS*/
1063#define TEXTBLOCK_FIT_MODE_NONE 0x0000
1064#define TEXTBLOCK_FIT_MODE_WIDTH 0x0001
1065#define TEXTBLOCK_FIT_MODE_HEIGHT 0x0002
1066#define TEXTBLOCK_FIT_MODE_ALL 0x0003
1067
1068/* TEXT BLOCK ERROR CODES*/
1069/* FIXME this hould go to other public place*/
1070#define EVAS_ERROR_SUCCESS 0x0000
1071#define EVAS_ERROR_INVALID_PARAM 0x0001
1072#define EVAS_ERROR_NO_MEMORY 0x0002
1073#define EVAS_ERROR_INVALID_OPERATION 0x0003
1074
1075
1076/** Get the object's content it options.
1077 *
1078 * @param obj The textblock object.
1079 * @param[out] options content fitting options.
1080 * @return Returns error code.
1081 */
1082EAPI int evas_textblock_fit_options_get(const Evas_Object *obj, unsigned int * p_options);
1083
1084/** Set the object's content it options.
1085 *
1086 * @param obj The textblock object.
1087 * @param[in] options content fitting options.
1088 * @return Returns error code.
1089 */
1090EAPI int evas_textblock_fit_options_set(Evas_Object *obj, unsigned int options);
1091
1092/** Get the object's max and min font sizes used for fitting content.
1093 *
1094 * @param obj The textblock object.
1095 * @param[out] p_min_font_size min font size used when fitting content.
1096 * @param[out] p_max_font_size max font size used when fitting content.
1097 * @return Returns error code.
1098 */
1099EAPI int evas_textblock_fit_size_range_get(const Evas_Object *obj, unsigned int *p_min_font_size, unsigned int *p_max_font_size);
1100
1101/** Set the object's max and min font sizes used for fitting content.
1102 *
1103 * @param obj The textblock object.
1104 * @param[in] min_font_size min font size used when fitting content.
1105 * @param[in] max_font_size max font size used when fitting content.
1106 * @return Returns error code.
1107 */
1108EAPI int evas_textblock_fit_size_range_set(Evas_Object *obj, unsigned int min_font_size, unsigned int max_font_size);
1109
1110
1111/** Get the object's fitting step size when trying fonts between min font size and
1112 * max font size.
1113 *
1114 * @param obj The textblock object.
1115 * @param[out] p_step_size step jumps between min and max font size.
1116 * @return Returns error code.
1117 */
1118EAPI int evas_textblock_fit_step_size_get(const Evas_Object *obj, unsigned int *p_step_size);
1119
1120
1121/** Set the object's fitting step size when trying fonts between min font size and
1122 * max font size.
1123 *
1124 * @param obj The textblock object.
1125 * @param[out] step_size step jumps between min and max font size.
1126 * @return Returns error code.
1127 */
1128EAPI int evas_textblock_fit_step_size_set(Evas_Object *obj, unsigned int step_size);
1129
1130/** Get copy of the object's fitting font size array used internally
1131 *
1132 * @param obj The textblock object.
1133 * @param[out] p_size_array pointer to size array (passing NULL will ignore filling array).
1134 * @param[out] p_size_array_len the length of internall font sizes array.
1135 * @param[out] request_size_array request to fill specific amount in p_size_array.
1136 * @return Returns error code.
1137 */
1138EAPI int evas_textblock_fit_size_array_get(const Evas_Object *obj, unsigned int *p_size_array, size_t *p_size_array_len,size_t request_size_array);
1139
1140/** Set the object's fitting font size array that will be used internally
1141 * Changing fitting step_size,min_font_size,max_font size will generate new array
1142 * Internall array will be sorted
1143 *
1144 * @param obj The textblock object.
1145 * @param[in] p_size_array pointer to font sizes array.
1146 * @param[in] size_array_len the length passed font sizes array.
1147 * @return Returns error code.
1148 */
1149EAPI int evas_textblock_fit_size_array_set(Evas_Object *obj, const unsigned int *p_size_array, size_t size_array_len);
1150
1151
1152
1153
1154
1155
1156
1157
1158
1059#include "canvas/efl_canvas_text_eo.legacy.h" 1159#include "canvas/efl_canvas_text_eo.legacy.h"
1060/** 1160/**
1061 * @} 1161 * @}
diff --git a/src/tests/evas/evas_test_textblock.c b/src/tests/evas/evas_test_textblock.c
index f61574c065..03ae5992a4 100644
--- a/src/tests/evas/evas_test_textblock.c
+++ b/src/tests/evas/evas_test_textblock.c
@@ -4129,6 +4129,32 @@ EFL_START_TEST(evas_textblock_obstacle)
4129} 4129}
4130EFL_END_TEST; 4130EFL_END_TEST;
4131 4131
4132EFL_START_TEST(evas_textblock_fit)
4133{
4134 START_TB_TEST();
4135 Evas_Coord fw, fh,fw_new, fh_new;
4136 int n_ret;
4137 const char *buf =
4138 "This is an example text to demonstrate the textblock object"
4139 " with content fit feature.";
4140 evas_object_textblock_text_markup_set(tb, buf);
4141 evas_object_resize(tb, 300, 300);
4142 evas_object_textblock_size_formatted_get(tb, &fw, &fh);
4143 n_ret = evas_textblock_fit_options_set(tb,TEXTBLOCK_FIT_MODE_ALL);
4144 fail_if(n_ret != EVAS_ERROR_SUCCESS);
4145 n_ret = evas_textblock_fit_size_range_set(tb,1,50);
4146 fail_if(n_ret != EVAS_ERROR_SUCCESS);
4147 evas_object_textblock_size_formatted_get(tb, &fw_new, &fh_new);
4148 fail_if(fw_new == fw && fh_new == fh);
4149 unsigned int size_array[3] = {150,200,250};
4150 n_ret = evas_textblock_fit_size_array_set(tb,size_array,3);
4151 fail_if(n_ret != EVAS_ERROR_SUCCESS);
4152 evas_object_textblock_size_formatted_get(tb, &fw, &fh);
4153 fail_if(fw_new == fw && fh_new == fh);
4154 END_TB_TEST();
4155}
4156EFL_END_TEST;
4157
4132#ifdef HAVE_HYPHEN 4158#ifdef HAVE_HYPHEN
4133static void 4159static void
4134_hyphenation_width_stress(Evas_Object *tb, Evas_Textblock_Cursor *cur) 4160_hyphenation_width_stress(Evas_Object *tb, Evas_Textblock_Cursor *cur)
@@ -4729,6 +4755,7 @@ void evas_test_textblock(TCase *tc)
4729 tcase_add_test(tc, evas_textblock_items); 4755 tcase_add_test(tc, evas_textblock_items);
4730 tcase_add_test(tc, evas_textblock_delete); 4756 tcase_add_test(tc, evas_textblock_delete);
4731 tcase_add_test(tc, evas_textblock_obstacle); 4757 tcase_add_test(tc, evas_textblock_obstacle);
4758 tcase_add_test(tc, evas_textblock_fit);
4732#ifdef HAVE_HYPHEN 4759#ifdef HAVE_HYPHEN
4733 tcase_add_test(tc, evas_textblock_hyphenation); 4760 tcase_add_test(tc, evas_textblock_hyphenation);
4734#endif 4761#endif