diff options
author | Matthias Clasen <mclasen@redhat.com> | 2021-11-12 21:00:37 -0500 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2021-11-15 08:38:45 -0500 |
commit | cadc688fa4ef2abea1fc6b8dc3ffb053a401ad38 (patch) | |
tree | f79a8920db62c497cee02995dcf210f91dae8bf7 /pango | |
parent | f7e1c6338eba0d775c55d9f4ea7f1ef86b95adc8 (diff) | |
download | pango-cadc688fa4ef2abea1fc6b8dc3ffb053a401ad38.tar.gz |
Improve the BREAK_ALL_FIT case
We always need to check if we still fit, after shaping.
The width we use before is just an estimate.
Diffstat (limited to 'pango')
-rw-r--r-- | pango/pango-layout.c | 39 |
1 files changed, 30 insertions, 9 deletions
diff --git a/pango/pango-layout.c b/pango/pango-layout.c index 594bd6ea..50e6ddeb 100644 --- a/pango/pango-layout.c +++ b/pango/pango-layout.c @@ -3872,13 +3872,24 @@ process_item (PangoLayout *layout, if ((width <= state->remaining_width || (item->num_chars == 1 && !line->runs)) && !no_break_at_end) { - state->remaining_width -= width; - state->remaining_width = MAX (state->remaining_width, 0); - insert_run (line, state, item, TRUE); + insert_run (line, state, item, FALSE); + width = pango_glyph_string_get_width (((PangoGlyphItem *)(line->runs->data))->glyphs); - return BREAK_ALL_FIT; + if (width <= state->remaining_width || (item->num_chars == 1 && !line->runs)) + { + state->remaining_width -= width; + state->remaining_width = MAX (state->remaining_width, 0); + + pango_glyph_string_free (state->glyphs); + state->glyphs = NULL; + + return BREAK_ALL_FIT; + } + + /* if it doesn't fit after shaping, revert and proceed to break the item */ + uninsert_run (line); } - else + { int num_chars; int break_num_chars = item->num_chars; @@ -3915,11 +3926,21 @@ process_item (PangoLayout *layout, /* check one more time if the whole item fits after removing the space */ if (width + break_extra_width <= state->remaining_width && !no_break_at_end) { - state->remaining_width -= width + break_extra_width; - state->remaining_width = MAX (state->remaining_width, 0); - insert_run (line, state, item, TRUE); + insert_run (line, state, item, FALSE); + width = pango_glyph_string_get_width (((PangoGlyphItem *)(line->runs->data))->glyphs); - return BREAK_ALL_FIT; + if (width + break_extra_width <= state->remaining_width) + { + state->remaining_width -= width + break_extra_width; + state->remaining_width = MAX (state->remaining_width, 0); + + pango_glyph_string_free (state->glyphs); + state->glyphs = NULL; + + return BREAK_ALL_FIT; + } + + uninsert_run (line); } } |