From 6e025575350276a0f43ffc33ade696e6bffca395 Mon Sep 17 00:00:00 2001 From: Youngbok Shin Date: Tue, 1 Sep 2020 19:39:13 +0900 Subject: [PATCH] evas_textblock: remove style padding from native width and formatted height Summary: The style padding was included in native width(not in native height) and formatted height(not in formatted width). This is so weired. In addition, there is no enough document about the relation between formatted size, native size and the style padding. This issue is caused by a confusing code which is about how to handle the style padding on item's width and height.("x_adjustment"!) When Evas calculates "c->wmax" in line finalization stage, it explicitly subtract style padding from line width. So, I assumed the formatted size has not to include style padding. It is same for the native size. The style padding will not be included in formatted size and native size by this commit. @fix Test Plan: A test case is included in this commit. Evas_Object *tb = evas_object_textblock_add(evas); newst = evas_textblock_style_new(); evas_textblock_style_set(newst, "DEFAULT='font=Sans font_size=50 color=#000 text_class=entry'"); evas_object_textblock_style_set(tb, newst); evas_object_textblock_text_markup_set(tb, "Test"); evas_object_textblock_style_insets_get(tb, &l, &r, &t, &b); fail_if((l != 0) || (r != 4) || (t != 0) || (b != 4)); /* Size with style padding */ evas_object_textblock_size_formatted_get(tb, &w, &h); evas_object_textblock_size_native_get(tb, &nw, &nh); /* It is non-sense if the following condition is true. */ fail_if((w + l + r == nw) && (h == nh + t + b)); Reviewers: raster, ali.alzyod, woohyun, bowonryu Reviewed By: ali.alzyod Subscribers: cedric, #reviewers, #committers Tags: #efl Differential Revision: https://phab.enlightenment.org/D12110 --- src/lib/evas/canvas/efl_canvas_textblock.eo | 8 ++++ src/lib/evas/canvas/evas_object_textblock.c | 48 ++++++++++----------- src/tests/evas/evas_test_textblock.c | 7 +++ 3 files changed, 38 insertions(+), 25 deletions(-) diff --git a/src/lib/evas/canvas/efl_canvas_textblock.eo b/src/lib/evas/canvas/efl_canvas_textblock.eo index e819d0df09..b4ef328c14 100644 --- a/src/lib/evas/canvas/efl_canvas_textblock.eo +++ b/src/lib/evas/canvas/efl_canvas_textblock.eo @@ -355,6 +355,10 @@ class Efl.Canvas.Textblock extends Efl.Canvas.Object implements Efl.Text, size after wrapping text according to the size restrictions of the object. + The formatted width and height do not include padding size. + To get the total size of text with style, you need to query padding size + from @.style_insets. + For example a text block containing the text: "You shall not pass!" with no margins or padding and assuming a monospace font and a size of 7x10 char widths (for simplicity) @@ -378,6 +382,10 @@ class Efl.Canvas.Textblock extends Efl.Canvas.Object implements Efl.Text, size after wrapping text according to the size restrictions of the object. + The native width and height do not include padding size. + To get the total size of text with style, you need to query padding size + from @.style_insets. + For example a text block containing the text: "You shall not pass!" with no margins or padding and assuming a monospace font and a size of 7x10 char widths (for simplicity) diff --git a/src/lib/evas/canvas/evas_object_textblock.c b/src/lib/evas/canvas/evas_object_textblock.c index 1a46ea614c..aacc251b1b 100644 --- a/src/lib/evas/canvas/evas_object_textblock.c +++ b/src/lib/evas/canvas/evas_object_textblock.c @@ -311,7 +311,6 @@ struct _Evas_Object_Textblock_Text_Item { Evas_Object_Textblock_Item parent; /**< Textblock item. */ Evas_Text_Props text_props; /**< Props for this item. */ - Evas_Coord x_adjustment; /**< Used to indicate by how much we adjusted sizes */ Text_Item_Filter *gfx_filter; }; @@ -4963,7 +4962,7 @@ loop_advance: /* c->o->style_pad.r is already included in the line width, so it's * not used in this calculation. . */ c->ln->x = c->marginl + c->o->style_pad.l + - ((c->w - c->ln->w - c->o->style_pad.l - + ((c->w - c->ln->w - c->o->style_pad.l - c->o->style_pad.r - c->marginl - c->marginr) * _layout_line_align_get(c)); } else @@ -4979,8 +4978,7 @@ loop_advance: /* Calculate new max width */ { - Evas_Coord new_wmax = c->ln->w + - c->marginl + c->marginr - (c->o->style_pad.l + c->o->style_pad.r); + Evas_Coord new_wmax = c->ln->w + c->marginl + c->marginr; if (new_wmax > c->par->last_fw) c->par->last_fw = new_wmax; if (new_wmax > c->wmax) @@ -5199,9 +5197,8 @@ _text_item_update_sizes(Ctxt *c, Evas_Object_Textblock_Text_Item *ti) { evas_filter_program_padding_get(pgm, &pad, NULL); - ti->x_adjustment = pad.r + pad.l; - ti->parent.w = tw + ti->x_adjustment; // FIXME: why add l+r here, - ti->parent.h = th; // but not t+b here? + ti->parent.w = tw; // Don't add style pad here + ti->parent.h = th; // Don't add style pad here ti->parent.adv = advw; ti->parent.x = 0; return; @@ -5270,9 +5267,8 @@ _text_item_update_sizes(Ctxt *c, Evas_Object_Textblock_Text_Item *ti) shx2 += shad_sz; if (shx1 < minx) minx = shx1; if (shx2 > maxx) maxx = shx2; - ti->x_adjustment = maxx - minx; - ti->parent.w = tw + ti->x_adjustment; + ti->parent.w = tw; ti->parent.h = th; ti->parent.adv = advw; ti->parent.x = 0; @@ -6275,7 +6271,7 @@ _layout_handle_ellipsis(Ctxt *c, Evas_Object_Textblock_Item *it, Eina_List *i) save_cx = c->x; temp_w = c->w; - ellip_w = ellip_ti->parent.w - ellip_ti->x_adjustment; + ellip_w = ellip_ti->parent.w; #ifdef BIDI_SUPPORT // XXX: with RTL considerations in mind, we need to take max(adv, w) as the // line may be reordered in a way that the item placement will cause the @@ -6725,10 +6721,6 @@ _layout_par(Ctxt *c) /* Check if we need to wrap, i.e the text is bigger than the width, or we already found a wrap point. */ itw = it->w; - if (it->type == EVAS_TEXTBLOCK_ITEM_TEXT) - { - itw -= _ITEM_TEXT(it)->x_adjustment; - } if ((c->w >= 0) && (obs || @@ -7571,7 +7563,8 @@ _layout_visual(Ctxt *c) if (last_vis_par) { c->hmax = last_vis_par->y + last_vis_par->h + - _layout_last_line_max_descent_adjust_calc(c, last_vis_par); + _layout_last_line_max_descent_adjust_calc(c, last_vis_par) - + c->style_pad.t - c->style_pad.b; } } @@ -7596,7 +7589,7 @@ _layout_done(Ctxt *c, Evas_Coord *w_ret, Evas_Coord *h_ret) /* Vertically align the textblock */ if ((c->o->valign > 0.0) && (c->h > c->hmax)) { - Evas_Coord adjustment = (c->h - c->hmax) * c->o->valign; + Evas_Coord adjustment = (c->h - c->hmax - c->style_pad.t - c->style_pad.b) * c->o->valign; Evas_Object_Textblock_Paragraph *par; EINA_INLIST_FOREACH(c->paragraphs, par) { @@ -7768,10 +7761,11 @@ _relayout(const Evas_Object *eo_obj) if ((o->paragraphs) && (!EINA_INLIST_GET(o->paragraphs)->next) && (o->paragraphs->lines) && (!EINA_INLIST_GET(o->paragraphs->lines)->next)) { - if (obj->cur->geometry.h < o->formatted.h) + if (obj->cur->geometry.h < o->formatted.h + o->style_pad.t + o->style_pad.b) { - LYDBG("ZZ: 1 line only... lasth == formatted h (%i)\n", o->formatted.h); - o->formatted.oneline_h = o->formatted.h; + LYDBG("ZZ: 1 line only... lasth == formatted h + style_pad.t + style_pad.b(%i)\n", + o->formatted.h + o->style_pad.t + o->style_pad.b); + o->formatted.oneline_h = o->formatted.h + o->style_pad.t + o->style_pad.b; } } o->changed = 0; @@ -13467,7 +13461,7 @@ _evas_textblock_cursor_coord_set(Evas_Textblock_Cursor *cur, Evas_Coord x, Evas_ if (o->paragraphs) { Evas_Object_Textblock_Line *first_line = o->paragraphs->lines; - if (y >= o->paragraphs->y + o->formatted.h) + if (y >= o->paragraphs->y + o->formatted.h + o->style_pad.t + o->style_pad.b) { /* If we are after the last paragraph, use the last position in the * text. */ @@ -13541,7 +13535,7 @@ evas_textblock_cursor_line_coord_set(Evas_Textblock_Cursor *cur, Evas_Coord y) } } } - else if (o->paragraphs && (y >= o->paragraphs->y + o->formatted.h)) + else if (o->paragraphs && (y >= o->paragraphs->y + o->formatted.h + o->style_pad.t + o->style_pad.b)) { int line_no = 0; /* If we are after the last paragraph, use the last position in the @@ -17633,9 +17627,9 @@ _text_layout_async_done(void *todo, Ecore_Thread *thread EINA_UNUSED) if ((c->o->paragraphs) && (!EINA_INLIST_GET(c->o->paragraphs)->next) && (c->o->paragraphs->lines) && (!EINA_INLIST_GET(c->o->paragraphs->lines)->next)) { - if (c->evas_o->cur->geometry.h < c->o->formatted.h) + if (c->evas_o->cur->geometry.h < c->o->formatted.h + c->o->style_pad.t + c->o->style_pad.b) { - c->o->formatted.oneline_h = c->o->formatted.h; + c->o->formatted.oneline_h = c->o->formatted.h + c->o->style_pad.t + c->o->style_pad.b; } } c->o->changed = 0; @@ -17652,7 +17646,9 @@ _text_layout_async_done(void *todo, Ecore_Thread *thread EINA_UNUSED) evas_object_change(c->obj, c->evas_o); free(c); - _resolve_async(td, o->formatted.w, o->formatted.h); + _resolve_async(td, + o->formatted.w + o->style_pad.l + o->style_pad.r, + o->formatted.h + o->style_pad.t + o->style_pad.b); o->layout_th = NULL; o->layout_jobs--; @@ -17699,7 +17695,9 @@ _efl_canvas_textblock_async_layout(Eo *eo_obj EINA_UNUSED, Efl_Canvas_Textblock_ evas_object_textblock_coords_recalc(eo_obj, obj, obj->private_data); if (o->formatted.valid) { - _resolve_async(ctx, o->formatted.w, o->formatted.w); + _resolve_async(ctx, + o->formatted.w + o->style_pad.l + o->style_pad.r, + o->formatted.h + o->style_pad.t + o->style_pad.b); return f; } diff --git a/src/tests/evas/evas_test_textblock.c b/src/tests/evas/evas_test_textblock.c index b3177ff599..3f1cbec8d8 100644 --- a/src/tests/evas/evas_test_textblock.c +++ b/src/tests/evas/evas_test_textblock.c @@ -3736,6 +3736,13 @@ EFL_START_TEST(evas_textblock_style) evas_object_textblock_style_insets_get(tb, &l, &r, &t, &b); fail_if((l != 0) || (r != 4) || (t != 0) || (b != 4)); + /* Size with style padding */ + evas_object_textblock_size_formatted_get(tb, &w, &h); + evas_object_textblock_size_native_get(tb, &nw, &nh); + + /* It is non-sense if the following condition is true. */ + fail_if((w + l + r == nw) && (h == nh + t + b)); + /* Mixed style padding */ evas_object_textblock_text_markup_set(tb, "TestTest");