[pango/line-breaking-fixes: 8/12] Improve the BREAK_ALL_FIT case
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pango/line-breaking-fixes: 8/12] Improve the BREAK_ALL_FIT case
- Date: Sun, 14 Nov 2021 20:33:34 +0000 (UTC)
commit 5de5c03385d2c4d3445c268e416ac6cd760a2015
Author: Matthias Clasen <mclasen redhat com>
Date: Fri Nov 12 21:00:37 2021 -0500
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.
pango/pango-layout.c | 39 ++++++++++++++++++++++++++++++---------
1 file changed, 30 insertions(+), 9 deletions(-)
---
diff --git a/pango/pango-layout.c b/pango/pango-layout.c
index 5cdaa531..13e974d2 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 = item->num_chars;
int break_num_chars = num_chars;
@@ -3918,11 +3929,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);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]