From 164c0f1eb5165786e0addfe5317cf6de3061ddf9 Mon Sep 17 00:00:00 2001 From: Christian Persch Date: Sat, 11 Mar 2023 11:19:11 +0100 Subject: fonts: Keep the PangoLayout unchanged The previous commit still wasn't completely fixing the problem, since the FontInfo and the UnistrInfo are cached too, and m_layout will be re-used when creating the next UnistrInfo, but the code in pango_cairo_show_layout_line() requires the PangoLayout to still have the same text as when it was created for the UnistrInfo. To fix this, adopt the PangoLayout into the PangoLayoutLine cached in the UnistrInfo, and create a new layout for next use. Fixes: https://gitlab.gnome.org/GNOME/vte/-/issues/2606 Fixes: https://gitlab.gnome.org/GNOME/vte/-/issues/2620 (cherry picked from commit 3c8f66be867aca6656e4109ce880b6ea7431b895) Fixes: https://gitlab.gnome.org/Teams/Releng/freeze-breaks/-/issues/131 --- src/fonts-pangocairo.cc | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/fonts-pangocairo.cc b/src/fonts-pangocairo.cc index 476526b9..746f1353 100644 --- a/src/fonts-pangocairo.cc +++ b/src/fonts-pangocairo.cc @@ -474,7 +474,21 @@ FontInfo::get_unistr_info(vteunistr c) { uinfo->set_coverage(UnistrInfo::Coverage::USE_PANGO_LAYOUT_LINE); + // When using a cairo surface which uses show_text_glyphs, + // pango_cairo_show_layout_line() will use the text from + // @line->layout and it must be the text that was used when + // the PangoLayoutLine was created. Also, since @line was + // obtained from m_layout, when setting m_layout to a new + // text later this will change @line->layout to %NULL. + // To make this work, we instead adopt the @m_layout instance + // into @line->layout, and create a new @m_layout object. + + line->layout = m_layout.release(); // adopted ufi->using_pango_layout_line.line = pango_layout_line_ref (line); + + auto const context = pango_layout_get_context(line->layout); + m_layout = vte::glib::take_ref(pango_layout_new(context)); + } else { PangoGlyphItem *glyph_item = (PangoGlyphItem *)line->runs->data; PangoFont *pango_font = glyph_item->item->analysis.font; @@ -504,11 +518,10 @@ FontInfo::get_unistr_info(vteunistr c) ufi->using_pango_glyph_string.font = pango_font ? (PangoFont *)g_object_ref (pango_font) : NULL; ufi->using_pango_glyph_string.glyph_string = pango_glyph_string_copy (glyph_string); } - - /* release internal layout resources */ - pango_layout_set_text(m_layout.get(), "", -1); } + // Don't reset m_layout here; it'll get reset anyway when we next use it. + #ifdef VTE_DEBUG m_coverage_count[0]++; m_coverage_count[uinfo->m_coverage]++; -- cgit v1.2.1