diff options
author | Matthias Clasen <mclasen@redhat.com> | 2021-11-12 13:55:22 -0500 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2021-11-12 18:41:15 -0500 |
commit | 86303ad26445ce7f7490f7e7a6690c611d83ea5e (patch) | |
tree | 58bf31b934bca82c125e96d0539f24fb81573d40 | |
parent | e439198c96c34f23bb38d07493b572776f118e01 (diff) | |
download | pango-86303ad26445ce7f7490f7e7a6690c611d83ea5e.tar.gz |
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.
-rw-r--r-- | pango/pango-layout.c | 16 |
1 files changed, 15 insertions, 1 deletions
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) |