[gtk/better-font-rendering-demo: 2/4] gtk-demo: Improve the font rendering demo




commit ad51216e876ecfdce3ae39422ade9fe624ee23d2
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Sep 4 20:45:37 2021 -0400

    gtk-demo: Improve the font rendering demo
    
    Prevent ligatures between the glyphs in
    the grid (mainly happens for 'f').

 demos/gtk-demo/fontrendering.c | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)
---
diff --git a/demos/gtk-demo/fontrendering.c b/demos/gtk-demo/fontrendering.c
index b032fa335d..749d067663 100644
--- a/demos/gtk-demo/fontrendering.c
+++ b/demos/gtk-demo/fontrendering.c
@@ -167,20 +167,26 @@ update_image (void)
       PangoLayoutRun *run;
       PangoGlyphInfo *g;
       int i, j;
-      char buf[24] = { 0, };
-      int len;
+      GString *str;
+      gunichar ch;
 
       if (*text == '\0')
         text = " ";
 
-      len = g_utf8_next_char (text) - text;
+      ch = g_utf8_get_char (text);
+
+      str = g_string_new ("");
 
       for (i = 0; i < 4; i++)
-        memcpy (buf + i * len, text, len);
+        {
+          g_string_append_unichar (str, ch);
+          g_string_append_unichar (str, 0x200c);
+        }
 
       layout = pango_layout_new (context);
       pango_layout_set_font_description (layout, desc);
-      pango_layout_set_text (layout, buf, -1);
+      pango_layout_set_text (layout, str->str, -1);
+      g_string_free (str, TRUE);
       pango_layout_get_extents (layout, &ink, &logical);
       pango_extents_to_pixels (&logical, NULL);
 
@@ -195,7 +201,7 @@ update_image (void)
       cairo_set_source_rgb (cr, 0, 0, 0);
       for (i = 0; i < 4; i++)
         {
-          g = &(run->glyphs->glyphs[i]);
+          g = &(run->glyphs->glyphs[2*i]);
           g->geometry.width = PANGO_UNITS_ROUND (g->geometry.width * 3 / 2);
         }
 
@@ -203,7 +209,7 @@ update_image (void)
         {
           for (i = 0; i < 4; i++)
             {
-              g = &(run->glyphs->glyphs[i]);
+              g = &(run->glyphs->glyphs[2*i]);
               g->geometry.x_offset = i * (PANGO_SCALE / 4);
               g->geometry.y_offset = j * (PANGO_SCALE / 4);
             }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]