[cairo] Cairo and freetype

Justin Thomas justin at sweaky.com
Wed Nov 7 15:13:00 PST 2012


If your platform is PS3 and your using GCM already your best option is to
use the freetype library and glyph/font rendering already available in the
SDK. However, if your set on using cairo then most likely you will need to
render to an image surface first then copy it to the gcm surface, a pseudo
example:

FT_Error err = 0;
FT_Face fontFace = 0;

if((err = FT_New_Face(<YOUR_FT_LIBRARY_INS>, "font.ttf", 0, &fontFace)) !=
0)
{
    printf("failed to create font (0x%x)\n", err);
    exit(1)
}

cairo_font_face_t* cairoFontFace =
cairo_ft_font_face_create_for_ft_face(fontFace, 0);
cairo_matrix_t mxSize;
cairo_matrix_t mxIdent;

cairo_matrix_init_scale(&mxSize, 16, 16); // sizing..
cairo_matrix_init_identity(&mxIdent);

cairo_scaled_font_t* cairoFont = cairo_scaled_font_create(cairoFontFace,
&mxSize, &mxIdent, 0);

// context = cairo_create(<IMAGE_SURFACE>)
cairo_set_scaled_font(context, cairoFont);
cairo_set_font_size(context, 16);
cairo_new_path(context);
cairo_move_to(context, 25, 25);
cairo_text_path(context, "CAIRO TEXT!");

cairo_set_source_rgb(context, 1, 0, 0);
cairo_fill(context);


.. then take your image surface and paint to the gcm context (I actually
don't know if this is the best way, I imagine there are others using fill
and source operator, maybe someone else with more experience can chime
in)...
cairo_set_source_surface(gcmContext, imageSurface, 0, 0);
cairo_paint(gcmContext);

-JT

On Wed, Nov 7, 2012 at 1:28 PM, Techie Help <techieinfo at yahoo.co.uk> wrote:

> Hi,
>
> I am new to Graphics, so new to cairo as well.
> I am trying to render some text using Cairo and freetype.
> The backend that I am using is gcm, and it does not support any glyphs etc.
> Can anyone please provide me with an example how to do this.
>
> Thanks
>
> --
> cairo mailing list
> cairo at cairographics.org
> http://lists.cairographics.org/mailman/listinfo/cairo
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cairographics.org/archives/cairo/attachments/20121107/f88d33b8/attachment.html>


More information about the cairo mailing list