[pango/line-breaking-fixes: 7/12] layout: simplify breakpoint disabling




commit 37cfa9b160bae4466ab5584091eccf6f10b4a1b6
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri Nov 12 13:48:56 2021 -0500

    layout: simplify breakpoint disabling
    
    Make this a purely local thing, without modifying
    log_attrs.

 pango/pango-layout.c | 41 ++++++++---------------------------------
 1 file changed, 8 insertions(+), 33 deletions(-)
---
diff --git a/pango/pango-layout.c b/pango/pango-layout.c
index 2e50b6bb..34787f0e 100644
--- a/pango/pango-layout.c
+++ b/pango/pango-layout.c
@@ -3525,31 +3525,6 @@ shape_tab (PangoLayoutLine  *line,
     }
 }
 
-#define DISABLE_BREAKPOINT_FLAG (1 << 16)
-
-static inline void
-disable_breakpoint (PangoLayout *layout,
-                    int          offset)
-{
-  layout->log_attrs[offset].reserved |= DISABLE_BREAKPOINT_FLAG;
-}
-
-static inline gboolean
-breakpoint_is_disabled (PangoLayout *layout,
-                        int          offset)
-{
-  return (layout->log_attrs[offset].reserved & DISABLE_BREAKPOINT_FLAG) != 0;
-}
-
-static void
-clear_breakpoint_flags (PangoLayout *layout,
-                        int          start,
-                        int          end)
-{
-  for (int i = start; i < end; i++)
-    layout->log_attrs[i].reserved = 0;
-}
-
 static inline gboolean
 can_break_at (PangoLayout *layout,
               gint         offset,
@@ -3567,8 +3542,6 @@ can_break_at (PangoLayout *layout,
 
   if (offset == layout->n_chars)
     return TRUE;
-  else if (breakpoint_is_disabled (layout, offset))
-    return FALSE;
   else if (wrap == PANGO_WRAP_WORD)
     return layout->log_attrs[offset].is_line_break;
   else if (wrap == PANGO_WRAP_CHAR)
@@ -3928,6 +3901,7 @@ process_item (PangoLayout     *layout,
       int orig_width = width;
       int break_extra_width = 0;
       gboolean retrying_with_char_breaks = FALSE;
+      gboolean *break_disabled;
 
       if (processing_new_item)
         {
@@ -3940,7 +3914,8 @@ process_item (PangoLayout     *layout,
           pango_glyph_item_get_logical_widths (&glyph_item, layout->text, state->log_widths);
         }
 
-      clear_breakpoint_flags (layout, state->start_offset, state->start_offset + item->num_chars);
+      break_disabled = g_alloca (sizeof (gboolean) * (item->num_chars + 1));
+      memset (break_disabled, 0, sizeof (gboolean) * (item->num_chars + 1));
 
     retry_break:
 
@@ -3955,7 +3930,8 @@ process_item (PangoLayout     *layout,
             break;
 
           /* If there are no previous runs we have to take care to grab at least one char. */
-          if (can_break_at (layout, state->start_offset + num_chars, retrying_with_char_breaks) &&
+          if (!break_disabled[num_chars] &&
+              can_break_at (layout, state->start_offset + num_chars, retrying_with_char_breaks) &&
               (num_chars > 0 || line->runs))
             {
               break_num_chars = num_chars;
@@ -4016,13 +3992,14 @@ process_item (PangoLayout     *layout,
 
               if (break_needs_hyphen (layout, state, break_num_chars))
                 new_item->analysis.flags |= PANGO_ANALYSIS_FLAG_NEED_HYPHEN;
+
               /* Add the width back, to the line, reshape, subtract the new width */
               state->remaining_width += break_width;
               insert_run (line, state, new_item, FALSE);
 
               break_width = pango_glyph_string_get_width (((PangoGlyphItem *)(line->runs->data))->glyphs);
               if (break_width > state->remaining_width &&
-                  !breakpoint_is_disabled (layout, state->start_offset + break_num_chars) &&
+                  !break_disabled[break_num_chars] &&
                   break_num_chars > 1)
                 {
                   /* Unsplit the item, disable the breakpoint, try again */
@@ -4031,7 +4008,7 @@ process_item (PangoLayout     *layout,
                   pango_item_free (new_item);
                   pango_item_unsplit (item, length, break_num_chars);
 
-                  disable_breakpoint (layout, state->start_offset + break_num_chars);
+                  break_disabled[break_num_chars] = TRUE;
 
                   num_chars = item->num_chars;
                   width = orig_width;
@@ -4648,8 +4625,6 @@ pango_layout_check_lines (PangoLayout *layout)
     }
   while (!done);
 
-  clear_breakpoint_flags (layout, 0, layout->n_chars + 1);
-
   g_free (state.log_widths);
   g_list_free_full (state.baseline_shifts, g_free);
 


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