[cairo] cairo + pango + vertical text

Behdad Esfahbod behdad at behdad.org
Wed Oct 31 12:46:19 PDT 2007


On Wed, 2007-10-31 at 05:21 -0400, Kalle Vahlman wrote:
> 2007/10/31, Nguyen Vu Hung <vuhung16plus at gmail.com>:
> [snip]
> > I've tried the following code, but the text "hihi" didn't get rotated.
> [...]
> >     pango_context_set_base_gravity ( context, PANGO_GRAVITY_SOUTH);
> 
> The documentation pointed to above states:
> "Gravity of normal Latin text is south."
> 
> So you are getting what you asked for, normally orientated latin text.
> You are not rotating the output of the layout either as far as I can
> tell, there's no cairo_rotate visible in the code excerpt.
> 
> Now, if you want this (a layout rotated 90 degrees clockwise):
>  h
>  i
>  h
>  i
> 
> you'll probably want to use GRAVITY_EAST (to rotate the glyphs
> counter-clockwise).  This alone won't suffice though, since this is
> latin script and thus will be handled with the SOUTH rotation
> automatically unless you set the gravity hint to
> PANGO_GRAVITY_HINT_STRONG to force the gravity setting for latin text
> too.
> 
> So the code looks something like:
> 
>    context = pango_layout_get_context (layout);
>    pango_context_set_base_gravity (context, PANGO_GRAVITY_EAST);
>    pango_context_set_gravity_hint(context, PANGO_GRAVITY_HINT_STRONG);
>    pango_layout_context_changed(layout);
> 
>    cairo_move_to (cr, x, y);
>    cairo_rotate(cr, 90 / (180.0 / G_PI));
> 
>    pango_cairo_show_layout (cr, layout);
> 
> Hope this helps.

Wow, I couldn't say it this good.  Just a minor note.  Instead of the
context_changed(), you can just call pango_cairo_update_layout() before
show_layout().  Because the rotation can affect layout too.  (though 90
degree doesn't, unless you have scale too).

If you want to improve docs, please file a bug against pango.
A working sample in the docs would be rad too.

-- 
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