This is an automated email from the git hooks/post-receive script.

git pushed a commit to reference refs/pull/285/head
in repository efl.

View the commit online.

commit 0723e91d624acf6c8ff67d3d1c012d0af7dd9747
Author: Cedric BAIL <[email protected]>
AuthorDate: Sat Nov 28 15:09:03 2026 -0600

    evas/textblock: give filtered spans their own colors
    
    The textblock skips setting a color equal to the one set last, and kept
    that cache for the screen and filter input contexts alike. A filtered
    span following plain text of the same color was left in the white of
    the input context: it vanished on a white background.
    
    The color of the object was also used to draw the input, then applied
    again to the result: a translucent or clipped textblock had its
    filtered spans fade twice.
    
    The input is now drawn with the colors of the text alone, and the cache
    is the screen's.
    
    The tests compare a filtered textblock with the same text without
    filter, on both engines.
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
 src/lib/evas/canvas/evas_object_textblock.c |  41 ++--
 src/tests/evas/evas_test_filter_textblock.c | 312 ++++++++++++++++++++++++++++
 src/tests/evas/evas_test_filters.c          |   2 +
 src/tests/evas/meson.build                  |   1 +
 4 files changed, 337 insertions(+), 19 deletions(-)

diff --git a/src/lib/evas/canvas/evas_object_textblock.c b/src/lib/evas/canvas/evas_object_textblock.c
index 04e2aa1e26..c0f08bb31f 100644
--- a/src/lib/evas/canvas/evas_object_textblock.c
+++ b/src/lib/evas/canvas/evas_object_textblock.c
@@ -14935,28 +14935,31 @@ evas_object_textblock_render(Evas_Object *eo_obj EINA_UNUSED,
      } \
    do {} while(0)
 
-#define COLOR_SET(col)                                                  \
-   nr = obj->cur->cache.clip.r * ti->parent.format->color.col.r;        \
-   ng = obj->cur->cache.clip.g * ti->parent.format->color.col.g;        \
-   nb = obj->cur->cache.clip.b * ti->parent.format->color.col.b;        \
-   na = obj->cur->cache.clip.a * ti->parent.format->color.col.a;        \
-   if (na != ca || nb != cb || ng != cg || nr != cr)                    \
-     {                                                                  \
-        ENFN->context_color_set(engine, context,                        \
-                                nr / 255, ng / 255, nb / 255, na / 255); \
-        cr = nr; cg = ng; cb = nb; ca = na;                             \
-     }
+/* "context" is the one of the screen, or the one drawing the input of a
+ * filter. The input takes the colors of the text alone, those of the object
+ * apply to the result of the filter. The cache of the color last set is only
+ * that of the screen. */
+#define COLOR_SET(col) COLOR_SET_AMUL(col, 255)
 
 #define COLOR_SET_AMUL(col, amul)                                       \
-   nr = obj->cur->cache.clip.r * ti->parent.format->color.col.r * (amul); \
-   ng = obj->cur->cache.clip.g * ti->parent.format->color.col.g * (amul); \
-   nb = obj->cur->cache.clip.b * ti->parent.format->color.col.b * (amul); \
-   na = obj->cur->cache.clip.a * ti->parent.format->color.col.a * (amul); \
-   if (na != ca || nb != cb || ng != cg || nr != cr)                    \
+   if (context != context_save)                                         \
+     ENFN->context_color_set(engine, context,                           \
+                             ti->parent.format->color.col.r * (amul) / 255, \
+                             ti->parent.format->color.col.g * (amul) / 255, \
+                             ti->parent.format->color.col.b * (amul) / 255, \
+                             ti->parent.format->color.col.a * (amul) / 255); \
+   else                                                                 \
      {                                                                  \
-        ENFN->context_color_set(engine, context,                        \
-                                nr / 65025, ng / 65025, nb / 65025, na / 65025); \
-        cr = nr; cg = ng; cb = nb; ca = na;                             \
+        nr = obj->cur->cache.clip.r * ti->parent.format->color.col.r * (amul); \
+        ng = obj->cur->cache.clip.g * ti->parent.format->color.col.g * (amul); \
+        nb = obj->cur->cache.clip.b * ti->parent.format->color.col.b * (amul); \
+        na = obj->cur->cache.clip.a * ti->parent.format->color.col.a * (amul); \
+        if (na != ca || nb != cb || ng != cg || nr != cr)               \
+          {                                                             \
+             ENFN->context_color_set(engine, context,                   \
+                                     nr / 65025, ng / 65025, nb / 65025, na / 65025); \
+             cr = nr; cg = ng; cb = nb; ca = na;                        \
+          }                                                             \
      }
 
 #define DRAW_TEXT_FILTER(gf, ox, oy) do {                               \
diff --git a/src/tests/evas/evas_test_filter_textblock.c b/src/tests/evas/evas_test_filter_textblock.c
new file mode 100644
index 0000000000..3c37d22981
--- /dev/null
+++ b/src/tests/evas/evas_test_filter_textblock.c
@@ -0,0 +1,312 @@
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <stdio.h>
+#include <stdint.h>
+#include <unistd.h>
+
+#include <Ecore_Evas.h>
+
+#include "evas_suite.h"
+
+/* Filters on a Textblock are applied to spans of its text, in their own path.
+ * Its input keeps the colors of the text, so that a filter which only blends
+ * it must look like the text without any filter. */
+
+#define W 256
+#define H 80
+#define COLOR_FONT "DejaVuSans," TESTS_SRC_DIR "/fonts/evas_test_color.ttf"
+#define SQUARE "\xf3\xb0\x80\x80"
+
+typedef struct _Scene Scene;
+struct _Scene
+{
+   const char *markup;
+   const char *code;        /* of the filter "f", NULL for none */
+   const char *next_code;   /* set after a first frame */
+   int object_alpha, clip_alpha;
+   Eina_Bool redraw;        /* checked on a second frame */
+};
+
+typedef struct _Shot Shot;
+struct _Shot
+{
+   Evas_Object *snap;
+   const char *file;
+};
+
+static int _errors;
+
+static void
+_error_count(const Eina_Log_Domain *d, Eina_Log_Level level, const char *file,
+             const char *fnc, int line, const char *fmt, void *data,
+             va_list args)
+{
+   if (level <= EINA_LOG_LEVEL_ERR) _errors++;
+   eina_log_print_cb_stderr(d, level, file, fnc, line, fmt, data, args);
+}
+
+static void
+_shot_save(void *data, Evas *e, void *event_info EINA_UNUSED)
+{
+   Shot *s = data;
+
+   evas_event_callback_del(e, EVAS_CALLBACK_RENDER_POST, _shot_save);
+   evas_object_image_save(s->snap, s->file, NULL, NULL);
+}
+
+static Eina_Bool
+_render(const char *engine, const Scene *s, uint32_t *out)
+{
+   Evas_Object *bg, *clip, *tb, *im;
+   Evas_Textblock_Style *style;
+   Ecore_Evas *ee, *loader;
+   Eina_Tmpstr *file = NULL;
+   uint32_t *pixels;
+   Shot shot;
+   Evas *evas;
+   int fd;
+
+   ee = ecore_evas_new(engine, 0, 0, W, H, NULL);
+   if (!ee) return EINA_FALSE;
+   ecore_evas_show(ee);
+   ecore_evas_manual_render_set(ee, EINA_TRUE);
+   evas = ecore_evas_get(ee);
+   _errors = 0;
+   eina_log_print_cb_set(_error_count, NULL);
+
+   bg = evas_object_rectangle_add(evas);
+   evas_object_resize(bg, W, H);
+   evas_object_show(bg);
+   clip = evas_object_rectangle_add(evas);
+   evas_object_color_set(clip, s->clip_alpha, s->clip_alpha, s->clip_alpha,
+                         s->clip_alpha);
+   evas_object_resize(clip, W, H);
+   evas_object_show(clip);
+
+   tb = evas_object_textblock_add(evas);
+   style = evas_textblock_style_new();
+   evas_textblock_style_set(style, "DEFAULT='font=DejaVuSans:style=Bold "
+                            "font_size=40 color=#000'");
+   evas_object_textblock_style_set(tb, style);
+   if (s->code) efl_gfx_filter_program_set(tb, s->code, "f");
+   evas_object_textblock_text_markup_set(tb, s->markup);
+   evas_object_move(tb, 8, 8);
+   evas_object_resize(tb, W - 16, H - 16);
+   evas_object_color_set(tb, s->object_alpha, s->object_alpha,
+                         s->object_alpha, s->object_alpha);
+   evas_object_clip_set(tb, clip);
+   evas_object_show(tb);
+
+   if (s->next_code)
+     {
+        ecore_evas_manual_render(ee);
+        efl_gfx_filter_program_set(tb, s->next_code, "f");
+     }
+
+   im = evas_object_image_filled_add(evas);
+   evas_object_image_snapshot_set(im, EINA_TRUE);
+   evas_object_resize(im, W, H);
+   evas_object_show(im);
+   fd = eina_file_mkstemp("evas_test_filter_XXXXXX.png", &file);
+   fail_if(fd < 0);
+   close(fd);
+   shot.snap = im;
+   shot.file = file;
+   if (s->redraw)
+     {
+        ecore_evas_manual_render(ee);
+        evas_damage_rectangle_add(evas, 0, 0, W, H);
+     }
+   evas_event_callback_add(evas, EVAS_CALLBACK_RENDER_POST, _shot_save, &shot);
+   ecore_evas_manual_render(ee);
+
+   loader = ecore_evas_buffer_new(1, 1);
+   im = evas_object_image_add(ecore_evas_get(loader));
+   evas_object_image_file_set(im, file, NULL);
+   pixels = evas_object_image_data_get(im, EINA_FALSE);
+   fail_if(!pixels);
+   memcpy(out, pixels, W * H * sizeof(uint32_t));
+   evas_object_image_data_set(im, pixels);
+   ecore_evas_free(loader);
+   unlink(file);
+   eina_tmpstr_del(file);
+   evas_textblock_style_free(style);
+   ecore_evas_free(ee);
+   eina_log_print_cb_set(eina_log_print_cb_stderr, NULL);
+
+   return EINA_TRUE;
+}
+
+/* pixels further apart than antialiasing explains */
+static int
+_differ(const uint32_t *a, const uint32_t *b)
+{
+   int count = 0;
+
+   for (int k = 0; k < W * H; k++)
+     for (int shift = 0; shift < 24; shift += 8)
+       if (abs((int) ((a[k] >> shift) & 0xff) -
+               (int) ((b[k] >> shift) & 0xff)) > 24)
+         {
+            count++;
+            break;
+         }
+
+   return count;
+}
+
+static int
+_count(const uint32_t *p, int r, int g, int b)
+{
+   int count = 0;
+
+   for (int k = 0; k < W * H; k++)
+     if ((abs((int) ((p[k] >> 16) & 0xff) - r) < 24) &&
+         (abs((int) ((p[k] >> 8) & 0xff) - g) < 24) &&
+         (abs((int) (p[k] & 0xff) - b) < 24))
+       count++;
+
+   return count;
+}
+
+/* the box of what is not white */
+static Eina_Rectangle
+_box(const uint32_t *p)
+{
+   int x0 = W, y0 = H, x1 = -1, y1 = -1;
+
+   for (int y = 0; y < H; y++)
+     for (int x = 0; x < W; x++)
+       if ((p[(y * W) + x] & 0xff) < 128)
+         {
+            if (x < x0) x0 = x;
+            if (x > x1) x1 = x;
+            if (y < y0) y0 = y;
+            if (y > y1) y1 = y;
+         }
+
+   return (Eina_Rectangle) { x0, y0, x1 - x0, y1 - y0 };
+}
+
+#define TEXT "Filter"
+#define SPAN "<gfx_filter=f>Filter</gfx_filter>"
+
+static int
+_same_as_plain(const char *engine, const char *name, Scene scene,
+               const char *plain_markup)
+{
+   static uint32_t got[W * H], want[W * H];
+   Scene plain = scene;
+   int differ;
+
+   plain.markup = plain_markup;
+   plain.code = NULL;
+   plain.next_code = NULL;
+   if (!_render(engine, &plain, want)) return 0;
+   if (!_render(engine, &scene, got)) return 0;
+   differ = _differ(got, want);
+   if ((differ <= 60) && !_errors) return 0;
+   fprintf(stderr, "VALUE %s: textblock %s: %d pixels differ from the plain "
+           "text, %d errors\n", engine, name, differ, _errors);
+   return 1;
+}
+
+static void
+_textblock_check(const char *engine)
+{
+   static uint32_t got[W * H], want[W * H];
+   Eina_Rectangle a, b;
+   int failed = 0;
+   Scene s;
+
+#define SCENE(Markup, Code) (Scene) { Markup, Code, NULL, 255, 255, 0 }
+   failed += _same_as_plain(engine, "blend", SCENE(SPAN, "blend { }"), TEXT);
+   failed += _same_as_plain(engine, "colored text",
+                            SCENE("<color=#0a0>" SPAN "</color>", "blend { }"),
+                            "<color=#0a0>" TEXT "</color>");
+   failed += _same_as_plain(engine, "filtered and plain spans",
+                            SCENE("Ab " SPAN " cd", "blend { }"),
+                            "Ab " TEXT " cd");
+   failed += _same_as_plain(engine, "translucent",
+                            (Scene) { SPAN, "blend { }", NULL, 64, 255, 0 }, TEXT);
+   failed += _same_as_plain(engine, "clipped",
+                            (Scene) { SPAN, "blend { }", NULL, 255, 64, 0 }, TEXT);
+   failed += _same_as_plain(engine, "translucent, redrawn",
+                            (Scene) { SPAN, "blend { }", NULL, 64, 255, 1 },
+                            TEXT);
+   failed += _same_as_plain(engine, "after a plain span",
+                            SCENE("Ab " SPAN, "blend { }"), "Ab " TEXT);
+   failed += _same_as_plain(engine, "after a plain span, with a shadow",
+                            SCENE("Ab <style=shadow shadow_color=#f00>" SPAN
+                                  "</style>", "blend { }"),
+                            "Ab <style=shadow shadow_color=#f00>" TEXT
+                            "</style>");
+   failed += _same_as_plain(engine, "program changed",
+                            (Scene) { SPAN, "fill { color = 'red' }",
+                                      "blend { }", 255, 255, 0 }, TEXT);
+   failed += _same_as_plain(engine, "program which reads nothing",
+                            SCENE("Ab " SPAN, "fill { color = '#00000000' }"),
+                            "Ab ");
+
+   /* a filter color multiplies the color of the text */
+   s = SCENE("<color=#fff><gfx_filter=f>Filter</gfx_filter></color>",
+             "blend { color = '#0000ff' }");
+   if (!_render(engine, &s, got)) return;
+   if (_count(got, 0, 0, 255) < 200)
+     {
+        fprintf(stderr, "VALUE %s: textblock filter color: %d blue pixels\n",
+                engine, _count(got, 0, 0, 255));
+        failed++;
+     }
+
+   /* a blur stays where the text is */
+   s = SCENE(TEXT, NULL);
+   if (!_render(engine, &s, want)) return;
+   s = SCENE(SPAN, "blur { 3 }");
+   if (!_render(engine, &s, got)) return;
+   a = _box(want);
+   b = _box(got);
+   if ((abs(a.x - b.x) > 3) || (abs(a.y - b.y) > 3) ||
+       (abs(a.w - b.w) > 6) || (abs(a.h - b.h) > 6) || _errors)
+     {
+        fprintf(stderr, "VALUE %s: textblock blur covers %d,%d %dx%d, the "
+                "text %d,%d %dx%d, %d errors\n", engine, b.x, b.y, b.w, b.h,
+                a.x, a.y, a.w, a.h, _errors);
+        failed++;
+     }
+
+   /* color glyphs keep their colors */
+   s = SCENE("<font=" COLOR_FONT "><gfx_filter=f>Ab" SQUARE
+             "</gfx_filter></font>", "blend { }");
+   if (!_render(engine, &s, got)) return;
+   if ((_count(got, 255, 0, 0) < 200) || (_count(got, 0, 255, 0) < 200) ||
+       _errors)
+     {
+        fprintf(stderr, "VALUE %s: textblock color glyph: %d red, %d green, "
+                "%d errors\n", engine, _count(got, 255, 0, 0),
+                _count(got, 0, 255, 0), _errors);
+        failed++;
+     }
+   ck_assert_int_eq(failed, 0);
+#undef SCENE
+}
+
+EFL_START_TEST(evas_filter_textblock)
+{
+   _textblock_check("buffer");
+}
+EFL_END_TEST
+
+EFL_START_TEST(evas_filter_gl_textblock)
+{
+   _textblock_check("opengl_x11");
+}
+EFL_END_TEST
+
+void evas_test_filter_textblock(TCase *tc)
+{
+   tcase_add_test(tc, evas_filter_textblock);
+   if (getenv("DISPLAY")) tcase_add_test(tc, evas_filter_gl_textblock);
+}
diff --git a/src/tests/evas/evas_test_filters.c b/src/tests/evas/evas_test_filters.c
index 6a2c916cc1..b185c306f6 100644
--- a/src/tests/evas/evas_test_filters.c
+++ b/src/tests/evas/evas_test_filters.c
@@ -1090,10 +1090,12 @@ EFL_START_TEST(evas_filter_gl_blur_offset)
 EFL_END_TEST
 
 void evas_test_filter_values(TCase *tc);
+void evas_test_filter_textblock(TCase *tc);
 
 void evas_test_filters(TCase *tc)
 {
    evas_test_filter_values(tc);
+   evas_test_filter_textblock(tc);
 
    tcase_add_test(tc, evas_filter_parser);
    tcase_add_test(tc, evas_filter_text_padding_test);
diff --git a/src/tests/evas/meson.build b/src/tests/evas/meson.build
index 05e6d157f5..600e89864e 100644
--- a/src/tests/evas/meson.build
+++ b/src/tests/evas/meson.build
@@ -13,6 +13,7 @@ evas_suite_src = [
   'evas_test_vg.c',
   'evas_test_filters.c',
   'evas_test_filter_values.c',
+  'evas_test_filter_textblock.c',
   'evas_test_image.c',
   'evas_test_mask.c',
   'evas_test_evasgl.c',

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

Reply via email to