[cairo] unable to render text

Mehmet Kovacioglu mkovacioglu at gmail.com
Thu Mar 20 01:45:20 PDT 2008


thanks for the replies, moving the cursor is very handy :)

anyway my problem was caused by fontconfig not being configured for the
target platform
(i'm cross compiling for a set top box and fontconfig was pointing to the
font-cache on my development pc)
fixing this and adding the adjustments with size and position solved
everything

On Wed, Mar 19, 2008 at 11:51 PM, Carl Worth <cworth at cworth.org> wrote:

> On Wed, 19 Mar 2008 14:09:02 +0100, "Mehmet Kovacioglu" wrote:
> > thanks for the quick reply,
> > here's the code:
>
> Hi Mehmet,
>
> Thanks for the code sample. This makes it much easier to spot the
> problem.
>
> >     cairo_stroke(cr);
> >
> > ------------------
> >     up till here everything works fine
> >  ------------------
> >
> >     cairo_set_source_rgb (cr, 1.0, 0.0, 0.0);
> >     cairo_select_font_face (cr, "sansserif",
> >                 CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
> >     cairo_set_font_size (cr, 22);
> >     cairo_text_extents (cr, "ABC", &te);
> >     cairo_show_text (cr, "ABC");
> >
> > --------------------
> > the part above isnt shown in the resulting png file
> > --------------------
>
> So the problem here is that you're never providing a position for
> where you'd like the cairo_show_text text to be placed.
>
> It's arguably an API error on our part that we didn't make you pass an
> (x,y) coordinate to that function---in which case it would have been
> obvious to you how to position the text.
>
> Instead, we took a cue from the PostScript specification and used the
> current path point as the position for cairo_show_text[*]. Since the
> last path-based operation you did was cairo_stroke and since it
> destroys the current path, then cairo assumes a current point of (0,0)
> for your text origin. And since the origin is to the lower-left of the
> glyphs for your font, none of your text is appearing on your image.
>
> If you had examined the contents of the te structure then you perhaps
> would have noticed that they describe a rectangle with negative Y
> coordinates.
>
> To fix this, insert something like the following just before the
> cairo_show_text call:
>
>        cairo_move_to (cr, 25, 25);
>
> and you should be all set. I do hope you have fun with cairo!
>
> -Carl
>
> [*] The advantage that it does have is that subsequent calls to
> cairo_show_text do continue the natural left-to-right layout that
> cairo_show_text uses:
>
>        cairo_move_to (cr, x, y);
>        cairo_show_text (cr, "One ");
>        cairo_show_text (cr, "word ");
>        cairo_show_text (cr, "at ");
>        cairo_show_text (cr, "a ");
>        cairo_show_text (cr, "time.");
>
> But that's still obviously extremely limited text layout. For anything
> more sophisticated in terms of layout, we highly recommend using pango
> and it's cairo integration instead, (it will do line-breaking,
> right-to-left layout, properly support Arabic, etc. etc.).
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.cairographics.org/archives/cairo/attachments/20080320/ffde894a/attachment.htm 


More information about the cairo mailing list