[cairo] PDF text doesn't render

Lichtl, Adam alichtl at bnl.gov
Thu Sep 20 13:16:56 PDT 2007


Hi Behdad,

Thank you for your help.  Here is what I've been able to determine:

I'm using a Mac, and you are right- the pdf file works in gv, xpdf, and acroread, but not in Preview.  I wonder what is different about these different programs.. I thought pdf was supposed to be a universal format!!  I've also noticed that using set_source_rgba has different effects in different viewers - it works fine in Preview and acroread, but not in xpdf or gv.  This is certainly strange (and frustrating).

So far I just use gv to look at the PostScript, and everything works fine (text and set_source_rgba).  Here is another twist to the story:  ps2pdf is able to correctly generate pdf files from the PostScript versions.  By this I mean that if I use cairo to write out a .ps file, and then run ps2pdf on it, the resulting .pdf file displays correctly in *all viewers*!  Except, unfortunately, that there doesn't seem to be the bounding box information that ps2pdf needs to set the boundary correctly in the PDF - it just sets it to page size.

Is this going to be fixed in future versions of cairo?  It seems to me that the PostScript surface is perfect except for bounding box information, and the PDF surface just needs to implement whatever ps2pdf does.

-Adam

-----Original Message-----
From: Behdad Esfahbod on behalf of Behdad Esfahbod
Sent: Thu 9/20/2007 3:23 PM
To: Lichtl, Adam
Cc: cairo at cairographics.org
Subject: Re: [cairo] PDF text doesn't render
 
On Thu, 2007-09-20 at 15:14 -0400, Lichtl, Adam wrote:
> Hello,
> 
> 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!

Your attached PDF renders fine here, both in acroread and Evince.


> #include <stdio.h>
> #include <string.h>
> #include <cairo/cairo.h>
> #include <cairo/cairo-pdf.h>
> 
> int main() {
>    FILE *file = fopen("out.pdf", "w");

You don't need this line.  In fact it may corrupt your output.
cairo_pdf_surface_create() opens the file itself.

>    cairo_surface_t *surface = cairo_pdf_surface_create("out.pdf", 2600,
> 100);
>    cairo_t *cr = cairo_create(surface);
>    cairo_surface_destroy(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_FONT_WEIGHT_BOLD);
>    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);
>    }
> 
>    cairo_show_page(cr);
>    cairo_destroy(cr);
>    fclose(file);

Ditto for the fclose().

>    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,
> -Adam
> 
> _______________________________________________
> cairo mailing list
> cairo at cairographics.org
> http://lists.cairographics.org/mailman/listinfo/cairo
-- 
behdad
http://behdad.org/

"Those who would give up Essential Liberty to purchase a little
 Temporary Safety, deserve neither Liberty nor Safety."
        -- Benjamin Franklin, 1759








More information about the cairo mailing list