]> git.cworth.org Git - spritext/commitdiff
Account for x_bearing/y_bearing to align each glyph properly master
authorCarl Worth <cworth@cworth.org>
Fri, 15 Feb 2008 01:11:43 +0000 (17:11 -0800)
committerCarl Worth <cworth@cworth.org>
Fri, 15 Feb 2008 01:11:43 +0000 (17:11 -0800)
And draw a grid just to show it's working as expected.

spritext.c

index 5ae64ba2309bb9a17d04ca3929c5175409423cd8..21d77f54df6e9036cd690566c716a97751a62313 100644 (file)
@@ -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);