diff options
author | Matthias Clasen <mclasen@redhat.com> | 2021-11-14 17:04:29 -0500 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2021-11-14 18:55:09 -0500 |
commit | f7e1c6338eba0d775c55d9f4ea7f1ef86b95adc8 (patch) | |
tree | e603198efaba2e725bbe25bdfe072d6dc351117a /pango/pango-layout.c | |
parent | 320b0750e8c6d167e298cbb0ab7855a1e22a2c8a (diff) | |
download | pango-f7e1c6338eba0d775c55d9f4ea7f1ef86b95adc8.tar.gz |
layout: Simplify things one more time
The key insight here is that if we find a broken item
does not fit, we are only interested in finding an
*earlier* breakpoint - the later ones aren't going
to produce a shorter run.
So we can just keep track of the last char we want
to allow breaking at.
This fixes the case of finding the minimum width
with wrap mode PANGO_WRAP_WORD.
Diffstat (limited to 'pango/pango-layout.c')
-rw-r--r-- | pango/pango-layout.c | 25 |
1 files changed, 9 insertions, 16 deletions
diff --git a/pango/pango-layout.c b/pango/pango-layout.c index dd43b46f..594bd6ea 100644 --- a/pango/pango-layout.c +++ b/pango/pango-layout.c @@ -3880,13 +3880,13 @@ process_item (PangoLayout *layout, } else { - int num_chars = item->num_chars; - int break_num_chars = num_chars; + int num_chars; + int break_num_chars = item->num_chars; int break_width = width; int orig_width = width; int break_extra_width = 0; gboolean retrying_with_char_breaks = FALSE; - gboolean *break_disabled; + int last_break_char = item->num_chars; if (processing_new_item) { @@ -3899,9 +3899,6 @@ process_item (PangoLayout *layout, pango_glyph_item_get_logical_widths (&glyph_item, layout->text, state->log_widths); } - break_disabled = g_alloca (sizeof (gboolean) * (item->num_chars + 1)); - memset (break_disabled, 0, sizeof (gboolean) * (item->num_chars + 1)); - retry_break: /* break_extra_width gets normally set from find_break_extra_width inside @@ -3929,7 +3926,7 @@ process_item (PangoLayout *layout, /* See how much of the item we can stuff in the line. */ width = 0; - for (num_chars = 0; num_chars < item->num_chars; num_chars++) + for (num_chars = 0; num_chars < last_break_char; num_chars++) { extra_width = find_break_extra_width (layout, state, num_chars); @@ -3937,8 +3934,7 @@ process_item (PangoLayout *layout, break; /* If there are no previous runs we have to take care to grab at least one char. */ - if (!break_disabled[num_chars] && - can_break_at (layout, state->start_offset + num_chars, retrying_with_char_breaks) && + if (can_break_at (layout, state->start_offset + num_chars, retrying_with_char_breaks) && (num_chars > 0 || line->runs)) { break_num_chars = num_chars; @@ -3952,9 +3948,9 @@ process_item (PangoLayout *layout, if (layout->wrap == PANGO_WRAP_WORD_CHAR && force_fit && break_width + break_extra_width > state->remaining_width && !retrying_with_char_breaks) { retrying_with_char_breaks = TRUE; - num_chars = item->num_chars; + last_break_char = item->num_chars; + break_num_chars = item->num_chars; width = orig_width; - break_num_chars = num_chars; break_width = width; goto retry_break; } @@ -4003,7 +3999,7 @@ process_item (PangoLayout *layout, 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 < last_break_char && break_num_chars > 1) { /* Unsplit the item, disable the breakpoint, try again */ @@ -4012,11 +4008,8 @@ process_item (PangoLayout *layout, pango_item_free (new_item); pango_item_unsplit (item, length, break_num_chars); - break_disabled[break_num_chars] = TRUE; - - num_chars = item->num_chars; + last_break_char = break_num_chars; width = orig_width; - break_num_chars = num_chars; break_width = width; goto retry_break; |