[gtk] font rendering: Show ink rect too



commit df1892c0527b042f2e980bfd76ddd45083dd103d
Author: Matthias Clasen <mclasen redhat com>
Date:   Thu Jul 25 22:06:34 2019 -0400

    font rendering: Show ink rect too

 demos/gtk-demo/fontrendering.c | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)
---
diff --git a/demos/gtk-demo/fontrendering.c b/demos/gtk-demo/fontrendering.c
index 17df1a4667..13031b4743 100644
--- a/demos/gtk-demo/fontrendering.c
+++ b/demos/gtk-demo/fontrendering.c
@@ -31,7 +31,7 @@ update_image (void)
   const char *text;
   PangoFontDescription *desc;
   PangoLayout *layout;
-  PangoRectangle ink, logical;
+  PangoRectangle ink, pink, logical;
   int baseline;
   cairo_surface_t *surface;
   cairo_t *cr;
@@ -79,6 +79,7 @@ update_image (void)
       pango_layout_set_font_description (layout, desc);
       pango_layout_set_text (layout, text, -1);
       pango_layout_get_extents (layout, &ink, &logical);
+      pink = ink;
       baseline = pango_layout_get_baseline (layout);
 
       pango_extents_to_pixels (&ink, NULL);
@@ -126,16 +127,23 @@ update_image (void)
 
       cairo_set_source_rgba (cr, 0, 0, 1, 1);
       cairo_rectangle (cr,
-                       scale * (10 + (double)logical.x / PANGO_SCALE) - 0.5,
-                       scale * (10 + (double)logical.y / PANGO_SCALE) - 0.5,
-                       scale * ((double)logical.width / PANGO_SCALE) + 1,
-                       scale * ((double)logical.height / PANGO_SCALE) + 1);
+                       scale * (10 + logical.x / PANGO_SCALE) - 0.5,
+                       scale * (10 + logical.y / PANGO_SCALE) - 0.5,
+                       scale * (logical.width / PANGO_SCALE) + 1,
+                       scale * (logical.height / PANGO_SCALE) + 1);
       cairo_stroke (cr);
-      cairo_move_to (cr, scale * (10 + (double)logical.x / PANGO_SCALE) - 0.5,
+      cairo_move_to (cr, scale * (10 + logical.x / PANGO_SCALE) - 0.5,
                          scale * (10 + baseline / PANGO_SCALE) - 0.5);
-      cairo_line_to (cr, scale * (10 + (double)(logical.x + logical.width) / PANGO_SCALE) + 1,
+      cairo_line_to (cr, scale * (10 + (logical.x + logical.width) / PANGO_SCALE) + 1,
                          scale * (10 + baseline / PANGO_SCALE) - 0.5);
       cairo_stroke (cr);
+      cairo_set_source_rgba (cr, 1, 0, 0, 1);
+      cairo_rectangle (cr,
+                       scale * (10 + pink.x / PANGO_SCALE) + 0.5,
+                       scale * (10 + pink.y / PANGO_SCALE) + 0.5,
+                       scale * (pink.width / PANGO_SCALE) - 0.5,
+                       scale * (pink.height / PANGO_SCALE) - 0.5);
+      cairo_stroke (cr);
       cairo_surface_destroy (surface);
     }
   else


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