[cairo] PDF text doesn't render

Lichtl, Adam alichtl at bnl.gov
Thu Sep 20 12:14:45 PDT 2007


I have been able to reproduce most of the examples in the (extremely
helpful) tutorial at http://www.cairographics.org/tutorial using both a
PostScript surface and a PDF surface.  Unfortunately, I am unable to get
the text to show up on the PDF surface.  I have been poking around the
web and also this mailing list's archives, but am unable to get it to
work.  I would appreciate any assistance.  Below is the complete source
code for the program (it is pretty simple) and attached is the output
pdf.  Please help!

#include <stdio.h>
#include <string.h>
#include <cairo/cairo.h>
#include <cairo/cairo-pdf.h>

int main() {
   FILE *file = fopen("out.pdf", "w");
   cairo_surface_t *surface = cairo_pdf_surface_create("out.pdf", 2600,
   cairo_t *cr = cairo_create(surface);
   cairo_scale(cr, 100, 100);

   int i;
   char letter[2];
   cairo_font_extents_t fe;
   cairo_text_extents_t te;
   char alphabet[] = "AbCdEfGhIjKlMnOpQrStUvWxYz";

   cairo_set_source_rgb(cr, 0, 0, 0);
   cairo_select_font_face (cr, "Times-Roman", CAIRO_FONT_SLANT_NORMAL,
   cairo_set_font_size(cr, 1.0);
   cairo_font_extents(cr, &fe);
   for (i = 0; i < strlen(alphabet); i++) {
     *letter = '\0';
     strncat(letter, alphabet + i, 1);

     cairo_text_extents(cr, letter, &te);
     cairo_move_to(cr, i + 0.5 - te.x_bearing - te.width / 2,
                           0.5 - fe.descent + fe.height / 2);
     cairo_show_text (cr, letter);


   return 0;

This program works just fine if "pdf" is replaced with "ps" everywhere.
  Also, all other drawing functions in the tutorial work fine on the pdf
surface - it is just that the text isn't showing up.  I have tried
playing around with the font name in the cairo_select_font_face command,
and have also tried omitting it completely.

Thank you,

-------------- next part --------------
A non-text attachment was scrubbed...
Name: out.pdf
Type: application/pdf
Size: 5519 bytes
Desc: out.pdf
Url : http://lists.cairographics.org/archives/cairo/attachments/20070920/37d190bd/attachment.pdf 

More information about the cairo mailing list