title: Create Pango Layout Before Cairo Surface
body: <p>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.</p>
  
  <p>The problem is, the way I have been initializing Pango and Cairo does not allow for this. Currently, the system is set up by:</p>
  
  <pre><code>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 );
  </code></pre>
  
  <p>Which fixes the height, at least of the surface - something I do not want to do, at least not all the time.</p>
  
  <p>My understanding is that if the layout height is not specified, it will automatically scale the height, which can then be found via <code>pango_layout_get_size()</code>. I would like to create the layout first and then use the output of this function to create the surface.</p>
  
  <p>However, <code>pango_cairo_create_layout()</code> requires the surface to already be created, and I have been unable to find a way to render a layout from <code>pango_layout_new()</code> via Cairo. The API docs one of the render functions, <code>pango_cairo_update_layout()</code>, specify that <code>pango_cairo_create_layout()</code> had to be used to create the layout; however, the more important function, <code>pango_cairo_show_layout()</code>, 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.</p>
  
  <p>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?</p>