[cairo] cairo + pango + vertical text

Behdad Esfahbod behdad at behdad.org
Tue Oct 30 10:37:23 PDT 2007

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:


It's basically a cairo_rotate() and a pango_context_set_gravity().

I just improved the docs, adding these:

Applications should only need to set base gravity on #PangoContext in use, and
let Pango decide the gravity assigned to each run of text.  This automatically
handles text with mixed scripts.  A very common use is to set the context base
gravity to auto using pango_context_set_base_gravity()
and rotate the layout normally.  Pango will make sure that
Asian languages take the right form, while other scripts are rotated normally.
The correct way to set gravity on a layout is to set it on the context
associated with it using pango_context_set_base_gravity().  The context
of a layout can be accessed using pango_layout_get_context().  The currently
set base gravity of the context can be accessed using
pango_context_get_base_gravity() and the <firstterm>resolved</firstterm>
gravity of it using pango_context_get_gravity().  The resolved gravity is
the same as the base gravity for the most part, except that if the base
gravity is set to %PANGO_GRAVITY_AUTO, the resolved gravity will depend
on the current matrix set on context, and is derived using
The next thing an application may want to set on the context is the
<firstterm>gravity hint</firstterm>.  A #PangoGravityHint instructs how
different scripts should react to the set base gravity.
Font descriptions have a gravity property too, that can be set using
pango_font_description_set_gravity() and accessed using
pango_font_description_get_gravity().  However, those are rarely useful
from application code and are mainly used by #PangoLayout internally.
Last but not least, one can create #PangoAttribute<!---->s for gravity
and gravity hint using pango_attr_gravity_new() and

<!-- ##### SECTION See_Also ##### -->

Hope that helps,


"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