[cairo] cairo + pango + vertical text

Nguyen Vu Hung vuhung16plus at gmail.com
Tue Oct 30 20:38:40 PDT 2007

2007/10/31, Behdad Esfahbod <behdad at behdad.org>:
> On Tue, 2007-10-30 at 06:29 -0400, Nguyen Vu Hung wrote:
> > Can anyone show a a primitive sample of how to show vertical text with
> > cairo + pango, like this:
> >
> > http://www.pango.org/ScriptGallery?action=AttachFile&do=get&target=VerticalSimple.png
> >
> > I know that pangocairo-viewer.c contains the answer but it seems overload to me.
> Read here:
>   http://library.gnome.org/devel/pango/unstable/pango-Vertical-Text.html
> It's basically a cairo_rotate() and a pango_context_set_gravity().
> I just improved the docs, adding these:

The length of the doc is increased.
However I still don't know how to start. I think a simple working code
worths twice more than long doc.

I've tried the following code, but the text "hihi" didn't get rotated.

    cairo_t *cr;
    cairo_surface_t *surface;
    PangoLayout *layout;

    double width;
    double height;
    int status;

    PangoContext *context;
    PangoCairoFontMap *fontmap;

    fontmap = (PangoCairoFontMap *) pango_cairo_font_map_get_default ();
    context = pango_cairo_font_map_create_context (fontmap);
    pango_context_set_base_gravity ( context, PANGO_GRAVITY_SOUTH);

    surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, WIDTH, HEIGHT);
    cr = cairo_create (surface);

    layout = get_pango_layout (cr,"hihi", &width, &height);

    cairo_move_to (cr, WIDTH/2. - width/2., HEIGHT/2. - height/2.);

    pango_cairo_show_layout (cr, layout);

    g_object_unref (layout);

    status = cairo_status (cr);
    cairo_destroy (cr);

Best Regards,
Nguyen Hung Vu
An inquisitive look at Harajuku

More information about the cairo mailing list