From 0a1218ebb121a829b2a63ac98f36c28e594e124f Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sun, 21 Nov 2021 16:20:25 -0500 Subject: Fix handling of extra width When handling items that fix completely, we were not consistently taking extra width into account, leading to hyphens sticking out in some cases. --- pango/pango-layout.c | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/pango/pango-layout.c b/pango/pango-layout.c index 3cdb677a..a5806774 100644 --- a/pango/pango-layout.c +++ b/pango/pango-layout.c @@ -3930,15 +3930,29 @@ process_item (PangoLayout *layout, width += state->log_widths[state->log_widths_offset + i]; } - if ((width <= state->remaining_width || (item->num_chars == 1 && !line->runs)) && + if (!no_break_at_end && + can_break_at (layout, state->start_offset + item->num_chars, wrap)) + { + if (processing_new_item) + { + compute_log_widths (layout, state); + processing_new_item = FALSE; + } + + extra_width = find_break_extra_width (layout, state, item->num_chars); + } + else + extra_width = 0; + + if ((width + extra_width <= state->remaining_width || (item->num_chars == 1 && !line->runs)) && !no_break_at_end) { - DEBUG1 ("%d <= %d", width, state->remaining_width); + DEBUG1 ("%d + %d <= %d", width, extra_width, state->remaining_width); insert_run (line, state, item, NULL, FALSE); width = pango_glyph_string_get_width (((PangoGlyphItem *)(line->runs->data))->glyphs); - if (width <= state->remaining_width || (item->num_chars == 1 && !line->runs)) + if (width + extra_width <= state->remaining_width || (item->num_chars == 1 && !line->runs)) { state->remaining_width -= width; state->remaining_width = MAX (state->remaining_width, 0); @@ -4007,7 +4021,7 @@ retry_break: if (can_break_at (layout, state->start_offset + num_chars, wrap) && (num_chars > 0 || line->runs)) { - DEBUG1 ("possible breakpoint: %d", num_chars); + DEBUG1 ("possible breakpoint: %d, extra_width %d", num_chars, extra_width); if (num_chars == 0 || width + extra_width < state->remaining_width - safe_distance) { @@ -4044,10 +4058,13 @@ retry_break: if (num_chars > 0 && layout->log_attrs[state->start_offset + num_chars - 1].is_white) extra_width = - state->log_widths[state->log_widths_offset + num_chars - 1]; + else if (item == new_item && + break_needs_hyphen (layout, state, num_chars)) + extra_width = state->hyphen_width; else extra_width = 0; - DEBUG1 ("measured breakpoint %d: %d", num_chars, new_break_width); + DEBUG1 ("measured breakpoint %d: %d, extra %d", num_chars, new_break_width, extra_width); if (new_item != item) { @@ -5947,6 +5964,7 @@ add_missing_hyphen (PangoLayoutLine *line, int width; int start_offset; + DEBUG1("add a missing hyphen"); /* The last run fit onto the line without breaking it, but it still needs a hyphen */ width = pango_glyph_string_get_width (run->glyphs); -- cgit v1.2.1