[cairo] Creating an image with text

Oscar Lazzarino oscar.lazzarino at gmail.com
Wed Apr 28 14:18:31 PDT 2010

On Wed, Apr 28, 2010 at 9:10 PM, Dov Grobgeld <dov.grobgeld at gmail.com> wrote:
> The following example show you how to measure the bounding box and how to
> create text with pango and cairo:
> http://live.gnome.org/PangoLayoutLineBbox

Thank you for your answer, but the program starts with

#define WIDTH 800
#define HEIGHT 300

and main() starts with

cairo_surface_t *surface;
surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24, WIDTH, HEIGHT);

to create a surface of 800x300 pixels.

My problem is a bit different.

I don't know in advance how big the image will be, and I can't set a
fixed size (actually, width is fixed, but height is variable according
to the text size).

I'd like to build a pango layout without having to allocate an image,
because I'd like to have the image sized exactly to fit the text.

Any advice? Do I need to create a dummy surface ( 1x1 pixels ) just to
build a layout and measure it?



More information about the cairo mailing list