Evas textblock: Use a common thickness and position at a underline. 18/59118/1
authorYoungbok Shin <youngb.shin@samsung.com>
Wed, 27 Jan 2016 13:14:52 +0000 (13:14 +0000)
committerYoungbok Shin <youngb.shin@samsung.com>
Thu, 11 Feb 2016 01:56:52 +0000 (10:56 +0900)
Summary:
If a underline is drawn with seperated thickness and position, it doesn't look good.
It will take the thickest and the lowest underline.

@feature

Test Plan:
Set the following markup text in Evas Textblock.
<underline=on underline_color=#fff><font_size=20>Markup text <font_size=50>with</font_size> underline tag</font_size></underline>

It shows the underline is split to 3 underlines with different thickness and positions.
Commonly, underline has to be drawn with same thickness ans position per each line.

Reviewers: woohyun, herdsman, tasn

Reviewed By: tasn

Subscribers: jpeg, raster, subodh6129, cedric

Differential Revision: https://phab.enlightenment.org/D2971

Change-Id: I2c3a0cbfc03a29501f7e3878fa84934173430233

src/lib/evas/canvas/evas_object_textblock.c

index 8df33411b0643ea705c5895e1a0a1d67b69c3670..aa4ce47439362baedad1e64a6890abd1a4bf6bc0 100644 (file)
@@ -3532,6 +3532,7 @@ _layout_line_finalize(Ctxt *c, Evas_Object_Textblock_Format *fmt)
           {
              Evas_Coord asc = 0, desc = 0;
              Evas_Coord maxasc = 0, maxdesc = 0;
+
              _layout_item_ascent_descent_adjust(c->obj, &asc, &desc,
                    it, it->format);
              _layout_item_max_ascent_descent_calc(c->obj, &maxasc, &maxdesc,
@@ -12580,11 +12581,12 @@ evas_object_textblock_render(Evas_Object *eo_obj EINA_UNUSED,
 {
    Evas_Object_Textblock_Paragraph *par, *start = NULL;
    Evas_Object_Textblock_Item *itr;
-   Evas_Object_Textblock_Line *ln;
+   Evas_Object_Textblock_Line *ln, *cur_ln = NULL;
    Evas_Textblock_Data *o = type_private_data;
    Eina_List *shadows = NULL;
    Eina_List *glows = NULL;
    Eina_List *outlines = NULL;
+   int strikethrough_thickness, underline_thickness, underline_position;
    int i, j;
    int cx, cy, cw, ch, clip;
    int ca, cr, cg, cb;
@@ -13024,11 +13026,9 @@ evas_object_textblock_render(Evas_Object *eo_obj EINA_UNUSED,
      }
 
    /* normal text and lines */
-   /* Get the thickness and position, and save them for non-text items. */
-   int line_thickness =
-           evas_common_font_instance_underline_thickness_get(NULL);
-   int line_position =
-           evas_common_font_instance_underline_position_get(NULL);
+   /* Get the thickness, and save it for strikethrough of non-text items. */
+   strikethrough_thickness = underline_thickness = evas_common_font_instance_underline_thickness_get(NULL);
+   underline_position = evas_common_font_instance_underline_position_get(NULL);
    ENFN->context_multiplier_unset(output, context);
 
    if (obj->cur->clipper)
@@ -13041,6 +13041,37 @@ evas_object_textblock_render(Evas_Object *eo_obj EINA_UNUSED,
    ITEM_WALK()
      {
         Evas_Object_Textblock_Text_Item *ti;
+
+        if (cur_ln != ln)
+          {
+             Evas_Object_Textblock_Item *itrr;
+
+             cur_ln = ln;
+             underline_thickness =
+                evas_common_font_instance_underline_thickness_get(NULL);
+             underline_position =
+                evas_common_font_instance_underline_position_get(NULL);
+
+             EINA_INLIST_FOREACH(ln->items, itrr)
+               {
+                  if (itrr->type == EVAS_TEXTBLOCK_ITEM_TEXT)
+                    {
+                       int fi_underline_thickness, fi_underline_position;
+                       void *fi = _ITEM_TEXT(itrr)->text_props.font_instance;
+
+                       fi_underline_thickness =
+                          evas_common_font_instance_underline_thickness_get(fi);
+                       fi_underline_position =
+                          evas_common_font_instance_underline_position_get(fi);
+
+                       if (fi_underline_thickness > underline_thickness)
+                         underline_thickness = fi_underline_thickness;
+                       if (fi_underline_position > underline_position)
+                         underline_position = fi_underline_position;
+                    }
+               }
+          }
+
         ti = (itr->type == EVAS_TEXTBLOCK_ITEM_TEXT) ? _ITEM_TEXT(itr) : NULL;
         /* NORMAL TEXT */
         if (ti)
@@ -13048,28 +13079,26 @@ evas_object_textblock_render(Evas_Object *eo_obj EINA_UNUSED,
              void *fi = _ITEM_TEXT(itr)->text_props.font_instance;
              COLOR_SET(normal);
              DRAW_TEXT(0, 0);
-             line_thickness =
+             strikethrough_thickness =
                 evas_common_font_instance_underline_thickness_get(fi);
-             line_position =
-                evas_common_font_instance_underline_position_get(fi);
           }
 
         /* STRIKETHROUGH */
-        DRAW_FORMAT(strikethrough, (ln->h / 2), line_thickness);
+        DRAW_FORMAT(strikethrough, (ln->h / 2), strikethrough_thickness);
 
         /* UNDERLINE */
-        DRAW_FORMAT(underline, ln->baseline + line_position,
-                               line_thickness * itr->format->underline_height);
+        DRAW_FORMAT(underline, ln->baseline + underline_position,
+                               underline_thickness * itr->format->underline_height);
 
         /* UNDERLINE DASHED */
-        DRAW_FORMAT_DASHED(underline_dash, ln->baseline + line_position,
-                         line_thickness,
+        DRAW_FORMAT_DASHED(underline_dash, ln->baseline + underline_position,
+                         underline_thickness,
                          itr->format->underline_dash_width,
                          itr->format->underline_dash_gap);
 
         /* UNDERLINE2 */
-        DRAW_FORMAT(underline2, ln->baseline + line_position + line_thickness +
-              line_position, line_thickness);
+        DRAW_FORMAT(underline2, ln->baseline + underline_position + underline_thickness +
+              underline_position, underline_thickness);
      }
    ITEM_WALK_END();
    ENFN->context_multiplier_unset(output, context);