In my application, I am using Pango and Cairo to create text textures. These textures have their width fixed, but should scale their height to fit text contents. The parent objects involved in this situation will then scale their heights to match the text.
The problem is, the way I have been initializing Pango and Cairo does not allow for this. Currently, the system is set up by:
cairo_surface_t* cairoSurface = cairo_image_surface_create( CAIRO_FORMAT_ARGB32, sizeX, sizeY );
cairo_t* cairoContext = cairo_create( cairoSurface );
PangoLayout* pangoLayout = pango_cairo_create_layout( cairoContext );
Which fixes the height, at least of the surface - something I do not want to do, at least not all the time.
My understanding is that if the layout height is not specified, it will automatically scale the height, which can then be found via pango_layout_get_size()
. I would like to create the layout first and then use the output of this function to create the surface.
However, pango_cairo_create_layout()
requires the surface to already be created, and I have been unable to find a way to render a layout from pango_layout_new()
via Cairo. The API docs one of the render functions, pango_cairo_update_layout()
, specify that pango_cairo_create_layout()
had to be used to create the layout; however, the more important function, pango_cairo_show_layout()
, notes no such requirement, and I am not sure if that means that any Pango layout is allowed or not. While I could test if it works, I'm afraid that trial and error could lead me to undefined behavior.
I feel like I'm stuck in a chicken and egg situation, and the documentation for Pango is mostly an API reference with little explanation of how the library is intended to be used. Is there a way to do this properly?