title: PangoCairo text cut-off when using PANGO_ALIGN_MIDDLE
body: <p>On a C++ game, we're using Pango to render text with cairo and from there to an OpenGL texture.
  I noticed this problem recently while working on implementing text-wrapping via Pango.</p>
  <p>What I'm doing is calculating the width by translating our own coordinate system to pixels and then using that as a fraction of the window width in PANGO UNITS, or in code:</p>
  <pre><code>        float screenEdge = _w * m * static_cast&lt;float&gt;(PANGO_SCALE);
          float tempMaxWidth = _owner-&gt;m_wrapping.m_maxWidth;
          tempMaxWidth = std::min(_owner-&gt;m_wrapping.m_maxWidth, (0.48f - _owner-&gt;dimensions().x1()));
          float wrapWidth = screenEdge * tempMaxWidth;
          maxWidth = static_cast&lt;int&gt;(std::round(wrapWidth));
          pango_layout_set_width(_owner-&gt;m_pangoLayout.get(), maxWidth);
  </code></pre>
  <p>Then we get a rectangle from the layout an pass that to cairo with:</p>
  <pre><code>        float border = 2.0f;
          PangoRectangle lRec;
          pango_layout_get_pixel_extents(_owner-&gt;m_pangoLayout.get(), nullptr, &amp;lRec);
          m_width = (lRec.width + border);  // Add twice half a border for margins
          m_height = (lRec.height + border);
      std::unique_ptr&lt;cairo_surface_t, decltype(&amp;cairo_surface_destroy)&gt; m_cairoSurface(
        cairo_image_surface_create(CAIRO_FORMAT_ARGB32, m_width, m_height),
        &amp;cairo_surface_destroy);
      std::unique_ptr&lt;cairo_t, decltype(&amp;cairo_destroy)&gt; m_cairoDc(
        cairo_create(m_cairoSurface.get()),
        &amp;cairo_destroy);
      cairo_set_antialias(m_cairoDc.get(), CAIRO_ANTIALIAS_FAST);
      cairo_push_group_with_content (m_cairoDc.get(), CAIRO_CONTENT_COLOR_ALPHA);
      cairo_set_operator(m_cairoDc.get(), CAIRO_OPERATOR_SOURCE);
      // Add Pango line and path to proper position on the DC
      cairo_move_to(m_cairoDc.get(), (0.5f * border), (0.5f * border));  // Margins needed for border stroke to fit in
  </code></pre>
  <p>But the output, as you can see below, is cut-off; this does not happen if I use <code>PANGO_ALIGN_LEFT</code>
  Searching around here, I found <a href="https://stackoverflow.com/questions/42226415/cairo-pango-layout-non-left-alignment">Cairo + Pango layout non-left alignment</a></p>
  <p>Which appears related to my issue but does not quite provide a solution (or I didn't get it properly); what I tried was to calculate the different between the x and y coordinates of the logical and ink rectangles and adding that to <code>cairo_move_to</code> but that made no real difference in the output, so I just pasted the original code here.</p>
  <p><a href="https://i.stack.imgur.com/nsiJS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nsiJS.png" alt="Texture output (should be &quot;Done Loading! Loaded 24 Songs.&quot;)" /></a></p>