[pango/line-breaker: 9/41] itemize: Break paragraph separators




commit 7b5fceaa4e1632289fec1aed57c1f82641d0714a
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri Jan 14 20:23:12 2022 -0500

    itemize: Break paragraph separators
    
    We don't normally meet paragraph separators
    in the text that gets itemized. But if we do,
    we want them in their own items.

 pango/itemize.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
---
diff --git a/pango/itemize.c b/pango/itemize.c
index 01399b7e..26a19177 100644
--- a/pango/itemize.c
+++ b/pango/itemize.c
@@ -944,6 +944,7 @@ itemize_state_process_run (ItemizeState *state)
   const char *p;
   gboolean last_was_forced_break = FALSE;
   gboolean is_space;
+  gunichar prev_wc = 0;
 
   /* Only one character has type G_UNICODE_LINE_SEPARATOR in Unicode 4.0;
    * update this if that changes. */
@@ -959,7 +960,8 @@ itemize_state_process_run (ItemizeState *state)
        p = g_utf8_next_char (p))
     {
       gunichar wc = g_utf8_get_char (p);
-      gboolean is_forced_break = (wc == '\t' || wc == LINE_SEPARATOR);
+      gboolean is_forced_break = wc == '\t' || wc == '\r' || wc == '\n' ||
+                                 wc == 0x2028 || wc == 0x2029;
       PangoFont *font;
       int font_position;
 
@@ -975,12 +977,17 @@ itemize_state_process_run (ItemizeState *state)
           is_space = FALSE;
         }
 
-      itemize_state_add_character (state, font, font_position,
-                                   is_forced_break || last_was_forced_break,
-                                   p,
-                                   is_space);
+      /* Don't break between \r and \n */
+      if (prev_wc == '\r' && wc == '\n')
+        state->item->num_chars++;
+      else
+        itemize_state_add_character (state, font, font_position,
+                                     is_forced_break || last_was_forced_break,
+                                     p,
+                                     is_space);
 
       last_was_forced_break = is_forced_break;
+      prev_wc = wc;
     }
 
   /* Finish the final item from the current segment */


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