[cairo] Toy text api, PNG, and magic numbers

Kozhevnikov Mikhail mikhailkozhevnikov at yandex.ru
Wed Mar 25 16:19:53 PDT 2009


Hello,

Smth goes wrong with the text rendered in the following example (output attached)

   cairo_surface_t *surface;
   cairo_t *cr;
   surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 600, 600);
   cr = cairo_create(surface);
   cairo_set_source_rgb(cr, 0, 0, 0);
   cairo_select_font_face (cr, "Arial", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);

   const char* txt = "N";
   cairo_set_font_size(cr, 10);
   cairo_text_extents_t ext;
   cairo_text_extents(cr, txt, &ext);
   for (int j = 0; j < 50; ++j)
      for (int i = 0; i < 50; ++i)
      {                           
         cairo_move_to(cr, (ext.width * (1.999 + j * 0.0005)) * i + 20, j * 12 + 11);
         cairo_show_text(cr, txt); 
      }

   cairo_destroy(cr);
   cairo_surface_write_to_png(surface, "test.png");
   cairo_surface_destroy(surface);

Looks interesting, ain't it? :) 

Best regards,
Mikhail.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.png
Type: image/png
Size: 6320 bytes
Desc: not available
Url : http://lists.cairographics.org/archives/cairo/attachments/20090326/16bf040b/attachment.png 


More information about the cairo mailing list