summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYoungbok Shin <youngb.shin@samsung.com>2020-09-01 19:39:13 +0900
committerWooHyun Jung <wh0705.jung@samsung.com>2020-09-01 19:39:13 +0900
commit6e025575350276a0f43ffc33ade696e6bffca395 (patch)
treeaf9573fe682a3c03f16f779342b384b1c7b69e54
parent1ab71284db89dcc37da12dd56796e892bc50ae0a (diff)
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, "<style=far_soft_shadow>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
-rw-r--r--src/lib/evas/canvas/efl_canvas_textblock.eo8
-rw-r--r--src/lib/evas/canvas/evas_object_textblock.c48
-rw-r--r--src/tests/evas/evas_test_textblock.c7
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,
355 size after wrapping text according to the size restrictions of the 355 size after wrapping text according to the size restrictions of the
356 object. 356 object.
357 357
358 The formatted width and height do not include padding size.
359 To get the total size of text with style, you need to query padding size
360 from @.style_insets.
361
358 For example a text block containing the text: 362 For example a text block containing the text:
359 "You shall not pass!" with no margins or padding and assuming 363 "You shall not pass!" with no margins or padding and assuming
360 a monospace font and a size of 7x10 char widths (for simplicity) 364 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,
378 size after wrapping text according to the size restrictions of the 382 size after wrapping text according to the size restrictions of the
379 object. 383 object.
380 384
385 The native width and height do not include padding size.
386 To get the total size of text with style, you need to query padding size
387 from @.style_insets.
388
381 For example a text block containing the text: 389 For example a text block containing the text:
382 "You shall not pass!" with no margins or padding and assuming 390 "You shall not pass!" with no margins or padding and assuming
383 a monospace font and a size of 7x10 char widths (for simplicity) 391 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
311{ 311{
312 Evas_Object_Textblock_Item parent; /**< Textblock item. */ 312 Evas_Object_Textblock_Item parent; /**< Textblock item. */
313 Evas_Text_Props text_props; /**< Props for this item. */ 313 Evas_Text_Props text_props; /**< Props for this item. */
314 Evas_Coord x_adjustment; /**< Used to indicate by how much we adjusted sizes */
315 Text_Item_Filter *gfx_filter; 314 Text_Item_Filter *gfx_filter;
316}; 315};
317 316
@@ -4963,7 +4962,7 @@ loop_advance:
4963 /* c->o->style_pad.r is already included in the line width, so it's 4962 /* c->o->style_pad.r is already included in the line width, so it's
4964 * not used in this calculation. . */ 4963 * not used in this calculation. . */
4965 c->ln->x = c->marginl + c->o->style_pad.l + 4964 c->ln->x = c->marginl + c->o->style_pad.l +
4966 ((c->w - c->ln->w - c->o->style_pad.l - 4965 ((c->w - c->ln->w - c->o->style_pad.l - c->o->style_pad.r -
4967 c->marginl - c->marginr) * _layout_line_align_get(c)); 4966 c->marginl - c->marginr) * _layout_line_align_get(c));
4968 } 4967 }
4969 else 4968 else
@@ -4979,8 +4978,7 @@ loop_advance:
4979 4978
4980 /* Calculate new max width */ 4979 /* Calculate new max width */
4981 { 4980 {
4982 Evas_Coord new_wmax = c->ln->w + 4981 Evas_Coord new_wmax = c->ln->w + c->marginl + c->marginr;
4983 c->marginl + c->marginr - (c->o->style_pad.l + c->o->style_pad.r);
4984 if (new_wmax > c->par->last_fw) 4982 if (new_wmax > c->par->last_fw)
4985 c->par->last_fw = new_wmax; 4983 c->par->last_fw = new_wmax;
4986 if (new_wmax > c->wmax) 4984 if (new_wmax > c->wmax)
@@ -5199,9 +5197,8 @@ _text_item_update_sizes(Ctxt *c, Evas_Object_Textblock_Text_Item *ti)
5199 { 5197 {
5200 evas_filter_program_padding_get(pgm, &pad, NULL); 5198 evas_filter_program_padding_get(pgm, &pad, NULL);
5201 5199
5202 ti->x_adjustment = pad.r + pad.l; 5200 ti->parent.w = tw; // Don't add style pad here
5203 ti->parent.w = tw + ti->x_adjustment; // FIXME: why add l+r here, 5201 ti->parent.h = th; // Don't add style pad here
5204 ti->parent.h = th; // but not t+b here?
5205 ti->parent.adv = advw; 5202 ti->parent.adv = advw;
5206 ti->parent.x = 0; 5203 ti->parent.x = 0;
5207 return; 5204 return;
@@ -5270,9 +5267,8 @@ _text_item_update_sizes(Ctxt *c, Evas_Object_Textblock_Text_Item *ti)
5270 shx2 += shad_sz; 5267 shx2 += shad_sz;
5271 if (shx1 < minx) minx = shx1; 5268 if (shx1 < minx) minx = shx1;
5272 if (shx2 > maxx) maxx = shx2; 5269 if (shx2 > maxx) maxx = shx2;
5273 ti->x_adjustment = maxx - minx;
5274 5270
5275 ti->parent.w = tw + ti->x_adjustment; 5271 ti->parent.w = tw;
5276 ti->parent.h = th; 5272 ti->parent.h = th;
5277 ti->parent.adv = advw; 5273 ti->parent.adv = advw;
5278 ti->parent.x = 0; 5274 ti->parent.x = 0;
@@ -6275,7 +6271,7 @@ _layout_handle_ellipsis(Ctxt *c, Evas_Object_Textblock_Item *it, Eina_List *i)
6275 6271
6276 save_cx = c->x; 6272 save_cx = c->x;
6277 temp_w = c->w; 6273 temp_w = c->w;
6278 ellip_w = ellip_ti->parent.w - ellip_ti->x_adjustment; 6274 ellip_w = ellip_ti->parent.w;
6279#ifdef BIDI_SUPPORT 6275#ifdef BIDI_SUPPORT
6280 // XXX: with RTL considerations in mind, we need to take max(adv, w) as the 6276 // XXX: with RTL considerations in mind, we need to take max(adv, w) as the
6281 // line may be reordered in a way that the item placement will cause the 6277 // line may be reordered in a way that the item placement will cause the
@@ -6725,10 +6721,6 @@ _layout_par(Ctxt *c)
6725 /* Check if we need to wrap, i.e the text is bigger than the width, 6721 /* Check if we need to wrap, i.e the text is bigger than the width,
6726 or we already found a wrap point. */ 6722 or we already found a wrap point. */
6727 itw = it->w; 6723 itw = it->w;
6728 if (it->type == EVAS_TEXTBLOCK_ITEM_TEXT)
6729 {
6730 itw -= _ITEM_TEXT(it)->x_adjustment;
6731 }
6732 6724
6733 if ((c->w >= 0) && 6725 if ((c->w >= 0) &&
6734 (obs || 6726 (obs ||
@@ -7571,7 +7563,8 @@ _layout_visual(Ctxt *c)
7571 if (last_vis_par) 7563 if (last_vis_par)
7572 { 7564 {
7573 c->hmax = last_vis_par->y + last_vis_par->h + 7565 c->hmax = last_vis_par->y + last_vis_par->h +
7574 _layout_last_line_max_descent_adjust_calc(c, last_vis_par); 7566 _layout_last_line_max_descent_adjust_calc(c, last_vis_par) -
7567 c->style_pad.t - c->style_pad.b;
7575 } 7568 }
7576 } 7569 }
7577 7570
@@ -7596,7 +7589,7 @@ _layout_done(Ctxt *c, Evas_Coord *w_ret, Evas_Coord *h_ret)
7596 /* Vertically align the textblock */ 7589 /* Vertically align the textblock */
7597 if ((c->o->valign > 0.0) && (c->h > c->hmax)) 7590 if ((c->o->valign > 0.0) && (c->h > c->hmax))
7598 { 7591 {
7599 Evas_Coord adjustment = (c->h - c->hmax) * c->o->valign; 7592 Evas_Coord adjustment = (c->h - c->hmax - c->style_pad.t - c->style_pad.b) * c->o->valign;
7600 Evas_Object_Textblock_Paragraph *par; 7593 Evas_Object_Textblock_Paragraph *par;
7601 EINA_INLIST_FOREACH(c->paragraphs, par) 7594 EINA_INLIST_FOREACH(c->paragraphs, par)
7602 { 7595 {
@@ -7768,10 +7761,11 @@ _relayout(const Evas_Object *eo_obj)
7768 if ((o->paragraphs) && (!EINA_INLIST_GET(o->paragraphs)->next) && 7761 if ((o->paragraphs) && (!EINA_INLIST_GET(o->paragraphs)->next) &&
7769 (o->paragraphs->lines) && (!EINA_INLIST_GET(o->paragraphs->lines)->next)) 7762 (o->paragraphs->lines) && (!EINA_INLIST_GET(o->paragraphs->lines)->next))
7770 { 7763 {
7771 if (obj->cur->geometry.h < o->formatted.h) 7764 if (obj->cur->geometry.h < o->formatted.h + o->style_pad.t + o->style_pad.b)
7772 { 7765 {
7773 LYDBG("ZZ: 1 line only... lasth == formatted h (%i)\n", o->formatted.h); 7766 LYDBG("ZZ: 1 line only... lasth == formatted h + style_pad.t + style_pad.b(%i)\n",
7774 o->formatted.oneline_h = o->formatted.h; 7767 o->formatted.h + o->style_pad.t + o->style_pad.b);
7768 o->formatted.oneline_h = o->formatted.h + o->style_pad.t + o->style_pad.b;
7775 } 7769 }
7776 } 7770 }
7777 o->changed = 0; 7771 o->changed = 0;
@@ -13467,7 +13461,7 @@ _evas_textblock_cursor_coord_set(Evas_Textblock_Cursor *cur, Evas_Coord x, Evas_
13467 if (o->paragraphs) 13461 if (o->paragraphs)
13468 { 13462 {
13469 Evas_Object_Textblock_Line *first_line = o->paragraphs->lines; 13463 Evas_Object_Textblock_Line *first_line = o->paragraphs->lines;
13470 if (y >= o->paragraphs->y + o->formatted.h) 13464 if (y >= o->paragraphs->y + o->formatted.h + o->style_pad.t + o->style_pad.b)
13471 { 13465 {
13472 /* If we are after the last paragraph, use the last position in the 13466 /* If we are after the last paragraph, use the last position in the
13473 * text. */ 13467 * text. */
@@ -13541,7 +13535,7 @@ evas_textblock_cursor_line_coord_set(Evas_Textblock_Cursor *cur, Evas_Coord y)
13541 } 13535 }
13542 } 13536 }
13543 } 13537 }
13544 else if (o->paragraphs && (y >= o->paragraphs->y + o->formatted.h)) 13538 else if (o->paragraphs && (y >= o->paragraphs->y + o->formatted.h + o->style_pad.t + o->style_pad.b))
13545 { 13539 {
13546 int line_no = 0; 13540 int line_no = 0;
13547 /* If we are after the last paragraph, use the last position in the 13541 /* 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)
17633 if ((c->o->paragraphs) && (!EINA_INLIST_GET(c->o->paragraphs)->next) && 17627 if ((c->o->paragraphs) && (!EINA_INLIST_GET(c->o->paragraphs)->next) &&
17634 (c->o->paragraphs->lines) && (!EINA_INLIST_GET(c->o->paragraphs->lines)->next)) 17628 (c->o->paragraphs->lines) && (!EINA_INLIST_GET(c->o->paragraphs->lines)->next))
17635 { 17629 {
17636 if (c->evas_o->cur->geometry.h < c->o->formatted.h) 17630 if (c->evas_o->cur->geometry.h < c->o->formatted.h + c->o->style_pad.t + c->o->style_pad.b)
17637 { 17631 {
17638 c->o->formatted.oneline_h = c->o->formatted.h; 17632 c->o->formatted.oneline_h = c->o->formatted.h + c->o->style_pad.t + c->o->style_pad.b;
17639 } 17633 }
17640 } 17634 }
17641 c->o->changed = 0; 17635 c->o->changed = 0;
@@ -17652,7 +17646,9 @@ _text_layout_async_done(void *todo, Ecore_Thread *thread EINA_UNUSED)
17652 evas_object_change(c->obj, c->evas_o); 17646 evas_object_change(c->obj, c->evas_o);
17653 free(c); 17647 free(c);
17654 17648
17655 _resolve_async(td, o->formatted.w, o->formatted.h); 17649 _resolve_async(td,
17650 o->formatted.w + o->style_pad.l + o->style_pad.r,
17651 o->formatted.h + o->style_pad.t + o->style_pad.b);
17656 17652
17657 o->layout_th = NULL; 17653 o->layout_th = NULL;
17658 o->layout_jobs--; 17654 o->layout_jobs--;
@@ -17699,7 +17695,9 @@ _efl_canvas_textblock_async_layout(Eo *eo_obj EINA_UNUSED, Efl_Canvas_Textblock_
17699 evas_object_textblock_coords_recalc(eo_obj, obj, obj->private_data); 17695 evas_object_textblock_coords_recalc(eo_obj, obj, obj->private_data);
17700 if (o->formatted.valid) 17696 if (o->formatted.valid)
17701 { 17697 {
17702 _resolve_async(ctx, o->formatted.w, o->formatted.w); 17698 _resolve_async(ctx,
17699 o->formatted.w + o->style_pad.l + o->style_pad.r,
17700 o->formatted.h + o->style_pad.t + o->style_pad.b);
17703 return f; 17701 return f;
17704 } 17702 }
17705 17703
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)
3736 evas_object_textblock_style_insets_get(tb, &l, &r, &t, &b); 3736 evas_object_textblock_style_insets_get(tb, &l, &r, &t, &b);
3737 fail_if((l != 0) || (r != 4) || (t != 0) || (b != 4)); 3737 fail_if((l != 0) || (r != 4) || (t != 0) || (b != 4));
3738 3738
3739 /* Size with style padding */
3740 evas_object_textblock_size_formatted_get(tb, &w, &h);
3741 evas_object_textblock_size_native_get(tb, &nw, &nh);
3742
3743 /* It is non-sense if the following condition is true. */
3744 fail_if((w + l + r == nw) && (h == nh + t + b));
3745
3739 /* Mixed style padding */ 3746 /* Mixed style padding */
3740 evas_object_textblock_text_markup_set(tb, 3747 evas_object_textblock_text_markup_set(tb,
3741 "<style=far_shadow>Test</><style=far_soft_shadow>Test</>"); 3748 "<style=far_shadow>Test</><style=far_soft_shadow>Test</>");