From dc5b1fdea7d63277f2b31489896d1947f0511a24 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Mon, 6 Dec 2021 22:57:27 -0500 Subject: Fix line width computation We an only use the line_width - remaining_width shortcut if we are actually maintaining remaining_width, i.e. not if we don't wrap lines. Testcase included. Fixes: #635 --- pango/pango-layout.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'pango/pango-layout.c') diff --git a/pango/pango-layout.c b/pango/pango-layout.c index ed46d57a..a495596c 100644 --- a/pango/pango-layout.c +++ b/pango/pango-layout.c @@ -3662,6 +3662,31 @@ get_decimal_prefix_width (PangoItem *item, g_free (log_widths); } +static int +line_width (ParaBreakState *state, + PangoLayoutLine *line) +{ + GSList *l; + int i; + int width = 0; + + if (state->remaining_width > -1) + return state->line_width - state->remaining_width; + + /* Compute the width of the line currently - inefficient, but easier + * than keeping the current width of the line up to date everywhere + */ + for (l = line->runs; l; l = l->next) + { + PangoLayoutRun *run = l->data; + + for (i = 0; i < run->glyphs->num_glyphs; i++) + width += run->glyphs->glyphs[i].geometry.width; + } + + return width; +} + static PangoGlyphString * shape_run (PangoLayoutLine *line, ParaBreakState *state, @@ -3671,7 +3696,7 @@ shape_run (PangoLayoutLine *line, PangoGlyphString *glyphs = pango_glyph_string_new (); if (layout->text[item->offset] == '\t') - shape_tab (line, &state->last_tab, &state->properties, state->line_width - state->remaining_width, item, glyphs); + shape_tab (line, &state->last_tab, &state->properties, line_width (state, line), item, glyphs); else { PangoShapeFlags shape_flags = PANGO_SHAPE_NONE; -- cgit v1.2.1