From e9c2833d6448f5f7f437cce16a74d8ce3a8ba16c Mon Sep 17 00:00:00 2001
From: Carl Worth <cworth@cworth.org>
Date: Thu, 14 Feb 2008 17:11:43 -0800
Subject: [PATCH] Account for x_bearing/y_bearing to align each glyph properly

And draw a grid just to show it's working as expected.
---
 spritext.c | 40 ++++++++++++++++++++++------------------
 1 file changed, 22 insertions(+), 18 deletions(-)

diff --git a/spritext.c b/spritext.c
index 5ae64ba..21d77f5 100644
--- a/spritext.c
+++ b/spritext.c
@@ -68,9 +68,9 @@ parse_args (args_t *args)
 {
     /* First some defaults */
     args->family = "Vera";
-    args->size = 20;
+    args->size = 40;
     args->color.red = 0.0;
-    args->color.green = 0.0;
+    args->color.green = 0.3;
     args->color.blue = 0.0;
 
     /* XXX: Next, we should override the defaults based on
@@ -179,29 +179,33 @@ draw_character_table (cairo_t *cr,
     double x = 0.0;
     double y = 0.0;
 
-    cairo_translate (cr, 0, -(character_height / 2.50));
-
     char string[2];
     string[1] = '\0';
+
+    cairo_set_line_width (cr, 2.0);
     for (i = 0; i < num_characters; i++)
     {
-	if (i % 10 == 0)
-	{
-	    x = 0.;
-	    y += character_height + 8;
-	}
+	cairo_rectangle (cr, x, y, character_width, character_height);
+	cairo_stroke_preserve (cr);
+	cairo_save (cr);
+	cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); /* white */
+	cairo_fill (cr);
+	cairo_restore (cr);
+
 	string[0] = characters[i];
 
 	cairo_text_extents (cr, string, &extents);
 
-	x -= extents.x_bearing;
-  
-	cairo_move_to (cr, x, y);
-	cairo_text_path (cr, string);
-	cairo_fill (cr);
+	cairo_move_to (cr, x - extents.x_bearing, y - extents.y_bearing);
+	cairo_show_text (cr, string);
 
-	x += extents.x_bearing;
-	x += character_width + 8;
+	if ((i+1) % 10 == 0)
+	{
+	    x = 0.;
+	    y += character_height;
+	} else {
+	    x += character_width;
+	}
     }
 
     cairo_scale (cr, 1, -1);
@@ -242,8 +246,8 @@ main (void)
 
     /* Draw */
     surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
-					  (max_width + 8) * 10,
-					  (max_height + 8) * 10);
+					  max_width * 10,
+					  max_height * 10);
 
     cr = cairo_create (surface);
 
-- 
2.45.2