[cairo] automatic multi-line text?

Chris Wilson chris at chris-wilson.co.uk
Sun Sep 14 04:09:31 PDT 2008


On Sun, 2008-09-14 at 03:38 -0700, Daniel Goldman wrote:
> Can cairo automatically output multi-line text? Something 
> like (did not work, did not print on multiple lines):
> 
> cairo_show_text (cr, "First Line\nSecond Line");

cairo_show_text() (along with cairo_select_font(), cairo_text_path() and
cairo_text_extents()) are part of what is referred to as the "toy" text
interface. The primarily purpose of those functions is to provide simple
convenience routines for tests and demos and are not intended for
serious use by applications. As such, they do not provide multiple
language support (i.e. switching fonts on the fly to map in the
appropriate glyph), do not implement advance shaping, do not handle
anything but the most trivial layout (i.e. only single lines with no
kerning) and many more complications of handling text. Instead the
application is meant to handle all the complexity of laying out text in
order to meet the myriad of different specifications that each
individual application conforms to and then to provide cairo with a
simple glyph-string using cairo_show_glyphs() (which just tells cairo
what glyph to draw and where, using the current font).

So the short answer is: no, cairo purposely does not handle multi-line
text. The library you are looking for is Pango [http://www.pango.org/].
It's a very versatile library, but at the simplest level it's just an
extremely advanced cairo_show_text() [see pango_cairo_show_layout()].

Have fun with Pango!
-- 
Chris Wilson



More information about the cairo mailing list