[pango/log-attr-tweaks: 18/23] layout: Validate external log attrs




commit 488d715e71dcb22c94559b1975a51d447846d0e7
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Aug 21 15:42:18 2021 -0400

    layout: Validate external log attrs
    
    These might be nonsense, better do some checks.

 pango/break.c        | 27 +++++++++++++++++++++++----
 pango/pango-layout.c |  9 ++++++++-
 2 files changed, 31 insertions(+), 5 deletions(-)
---
diff --git a/pango/break.c b/pango/break.c
index 88fe6e15..50bca699 100644
--- a/pango/break.c
+++ b/pango/break.c
@@ -1874,6 +1874,13 @@ check_line_char (int                  pos,
       return FALSE;
     }
 
+  if (attr->is_line_break && !attr->is_char_break)
+    {
+      g_set_error (error,
+                   PANGO_VALIDATE_ERROR, PANGO_VALIDATE_ERROR_BREAK,
+                   "char %d: Line breaks must also be marked as char breaks", pos);
+      return FALSE;
+    }
   if (break_type == G_UNICODE_BREAK_OPEN_PUNCTUATION &&
       prev_break_type == G_UNICODE_BREAK_OPEN_PUNCTUATION &&
       attr->is_line_break && !attr->is_mandatory_break)
@@ -1964,6 +1971,14 @@ check_word_invariants (const char          *text,
           break;
 
         case AFTER_START:
+          if (log_attrs[i].is_word_end)
+            {
+              if (log_attrs[i].is_word_start)
+                state = AFTER_START;
+              else
+                state = AFTER_END;
+              break;
+           }
           if (log_attrs[i].is_word_start)
             {
               g_set_error (error,
@@ -1971,8 +1986,6 @@ check_word_invariants (const char          *text,
                            "char %d: Unexpected word start", i);
               return FALSE;
             }
-          if (log_attrs[i].is_word_end)
-            state = AFTER_END;
           break;
 
         default:
@@ -2018,6 +2031,14 @@ check_sentence_invariants (const char          *text,
           break;
 
         case AFTER_START:
+          if (log_attrs[i].is_sentence_end)
+            {
+              if (log_attrs[i].is_sentence_start)
+                state = AFTER_START;
+              else
+                state = AFTER_END;
+              break;
+            }
           if (log_attrs[i].is_sentence_start)
             {
               g_set_error (error,
@@ -2025,8 +2046,6 @@ check_sentence_invariants (const char          *text,
                            "char %d: Unexpected sentence start", i);
               return FALSE;
             }
-          if (log_attrs[i].is_sentence_end)
-            state = AFTER_END;
           break;
 
         default:
diff --git a/pango/pango-layout.c b/pango/pango-layout.c
index f9bbcad6..460650cf 100644
--- a/pango/pango-layout.c
+++ b/pango/pango-layout.c
@@ -1589,7 +1589,14 @@ pango_layout_set_log_attrs (PangoLayout        *layout,
                             const PangoLogAttr *attrs,
                             int                 n_attrs)
 {
-  g_return_if_fail (layout->n_chars + 1 == n_attrs);
+  GError *error = NULL;
+
+  if (!pango_validate_log_attrs (layout->text, layout->length, attrs, n_attrs, &error))
+    {
+      g_warning ("pango_layout_set_log_attrs: %s", error->message);
+      g_error_free (error);
+      return;
+    }
 
   if (!layout->log_attrs)
     layout->log_attrs = g_new (PangoLogAttr, layout->n_chars + 1);


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