From 86303ad26445ce7f7490f7e7a6690c611d83ea5e Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Fri, 12 Nov 2021 13:55:22 -0500 Subject: Handle break-after-space correctly When we are breaking after a space, we must not count the width of the space towards the line, since we are zeroing it later. It is a bit annoying that there are multiple places where this has to be taken into account. Another missing bit in this code is that we are only looking at a single whitespace character before the break, when we should really look for a sequence of spaces. --- pango/pango-layout.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/pango/pango-layout.c b/pango/pango-layout.c index 821f767c..b605ded5 100644 --- a/pango/pango-layout.c +++ b/pango/pango-layout.c @@ -3752,7 +3752,11 @@ find_break_extra_width (PangoLayout *layout, ParaBreakState *state, int pos) { - /* Check whether to insert a hyphen */ + /* Check whether to insert a hyphen, + * or whether we are breaking after one of those + * characters that turn into a hyphen, + * or after a space. + */ if (layout->log_attrs[state->start_offset + pos].break_inserts_hyphen) { ensure_hyphen_width (state); @@ -3762,6 +3766,11 @@ find_break_extra_width (PangoLayout *layout, else return state->hyphen_width; } + else if (state->start_offset + pos > 0 && + layout->log_attrs[state->start_offset + pos - 1].is_white) + { + return - state->log_widths[state->log_widths_offset + pos - 1]; + } return 0; } @@ -3977,6 +3986,11 @@ process_item (PangoLayout *layout, insert_run (line, state, new_item, FALSE); break_width = pango_glyph_string_get_width (((PangoGlyphItem *)(line->runs->data))->glyphs); + + if (state->start_offset + break_num_chars > 0 && + layout->log_attrs[state->start_offset + break_num_chars - 1].is_white) + break_width -= state->log_widths[state->log_widths_offset + break_num_chars - 1]; + if (break_width > state->remaining_width && !break_disabled[break_num_chars] && break_num_chars > 1) -- cgit v1.2.1