[cairo] cairo porting help

Zoltan Kovacs giszo.k at gmail.com
Wed Dec 8 05:05:01 PST 2010


One more problem. I am trying to display some text but it is not drawn
to my buffer. The source code I am using can be found below.

Both FT_Init_FreeType and FT_New_Face functions return 0 so there is
no error there, the font is loaded properly.
The extents of the text is also counted properly as I displayed those
values and they seem to be right.
I also tried to debug the part of the cairo-ft module where the
FT_Render_Glyph function is called and it seems that the freetype
library did a good job and the glyph was rendered properly.

What did I miss?

    int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, 640);
    cairo_surface_t* s = cairo_image_surface_create_for_data(
        reinterpret_cast<unsigned char*>(m_graphicsDriver->getFrameBuffer()),
        CAIRO_FORMAT_ARGB32, 640, 480, stride
    );
    cairo_t* cr = cairo_create(s);

    cairo_text_extents_t extents;

    const char *utf8 = "cairo";
    double x,y;

    int ret;
    FT_Library ftLibrary;
    FT_Face ftFace;
    ret = FT_Init_FreeType(&ftLibrary); dbprintf("ret=%d\n", ret);
    ret = FT_New_Face(ftLibrary, "/system/fonts/DejaVuSans.ttf", 0,
&ftFace); dbprintf("ret=%d\n", ret);
    cairo_font_face_t* font = cairo_ft_font_face_create_for_ft_face(ftFace, 0);
    cairo_font_options_t* font_ops = cairo_font_options_create();
    cairo_font_options_set_antialias(font_ops, CAIRO_ANTIALIAS_SUBPIXEL);
    cairo_font_options_set_hint_style(font_ops, CAIRO_HINT_STYLE_FULL);
    cairo_font_options_set_hint_metrics(font_ops, CAIRO_HINT_METRICS_ON);

    cairo_set_font_face(cr, font);
    cairo_set_font_options(cr, font_ops);
    cairo_set_font_size (cr, 100.0);
    cairo_text_extents (cr, utf8, &extents);

    x=25.0;
    y=150.0;

    cairo_set_source_rgb(cr, 1, 1, 1);
    cairo_move_to(cr, x,y);
    cairo_show_text(cr, utf8);



On Wed, Dec 8, 2010 at 8:57 AM, Zoltan Kovacs <giszo.k at gmail.com> wrote:
> Grrr, looks like a really silly mistake I made. :)
>
> Thanks for pointing it out, now everything looks fine!
>
> On Wed, Dec 8, 2010 at 8:50 AM, Alexander Shulgin
> <alex.shulgin at gmail.com> wrote:
>> On Wed, Dec 8, 2010 at 09:39, Zoltan Kovacs <giszo.k at gmail.com> wrote:
>>> Hi.
>>>
>>> I am trying to port the cairo library to an OS that the library does
>>> not support by default. Both libraries (pixman & cairo) has been
>>> compiled successfully and I am trying to test it with the following
>>> code piece:
>>>
>>>    int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, 640);
>>>    dbprintf("stride=%d\n", stride);
>>>    cairo_surface_t* s = cairo_image_surface_create_for_data(
>>>        reinterpret_cast<unsigned char*>(m_graphicsDriver->getFrameBuffer()),
>>>        CAIRO_FORMAT_ARGB32, 640, 480, stride
>>>    );
>>>    cairo_t* cr = cairo_create(s);
>>>    cairo_set_source_rgb(cr, 1, 1, 1);
>>>    cairo_move_to(cr, 0, 0);
>>>    cairo_line_to(cr, 100, 100);
>>
>>>    cairo_paint(cr);
>>
>> This should be cairo_stroke(cr)
>>
>


More information about the cairo mailing list