diff options
author | Christian Persch <chpe@src.gnome.org> | 2023-03-10 21:52:41 +0100 |
---|---|---|
committer | Christian Persch <chpe@src.gnome.org> | 2023-03-10 21:52:41 +0100 |
commit | 3c8f66be867aca6656e4109ce880b6ea7431b895 (patch) | |
tree | e14227ff50214fa23885df7e456ab36ac21792d8 | |
parent | 22b3a562d5c95f5911560131c9f6f2df70881e34 (diff) | |
download | vte-3c8f66be867aca6656e4109ce880b6ea7431b895.tar.gz |
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
-rw-r--r-- | src/fonts-pangocairo.cc | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/src/fonts-pangocairo.cc b/src/fonts-pangocairo.cc index 15b77599..669cf721 100644 --- a/src/fonts-pangocairo.cc +++ b/src/fonts-pangocairo.cc @@ -494,7 +494,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; @@ -524,11 +538,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. + #if VTE_DEBUG m_coverage_count[0]++; m_coverage_count[uinfo->m_coverage]++; |