[pango/ltr-line-breaking-fixes: 4/6] Handle break-after-space correctly




commit e457a8820cfbfc41a8949f97e27ee1b1f8a67606
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri Nov 12 13:55:22 2021 -0500

    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.

 pango/pango-layout.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
---
diff --git a/pango/pango-layout.c b/pango/pango-layout.c
index 46fbafe1..c12c50b4 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;
 }
@@ -3976,6 +3985,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)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]