[pango/log-attr-tweaks: 31/32] break: Add pango_attr_break api




commit 128b867142b87e8eed698261955b6fe004b5a3ec
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Aug 21 23:12:45 2021 -0400

    break: Add pango_attr_break api
    
    So far, we've been applying attribute-based
    customization while doing per-item tailoring.
    But this is suboptimal, since it means we don't
    have a full view of the log attrs, and can't
    do invariant fixes that cross item boundaries.
    
    Therefore, add a separate pango_attr_break
    api that applies attributes to to the whole
    paragraph, and make PangoLayout use it.

 pango/break.c        | 42 ++++++++++++++++++++++++++++++++++++++++--
 pango/pango-break.h  |  8 ++++++++
 pango/pango-layout.c | 22 +++++++++++++++-------
 3 files changed, 63 insertions(+), 9 deletions(-)
---
diff --git a/pango/break.c b/pango/break.c
index efddc9e6..6a6765e3 100644
--- a/pango/break.c
+++ b/pango/break.c
@@ -2084,6 +2084,8 @@ check_space_invariants (const char          *text,
  * and can be %NULL.
  *
  * See [func@Pango.tailor_break] for language-specific breaks.
+ *
+ * See [func@Pango.attr_break] for attribute-based customization.
  */
 void
 pango_default_break (const char    *text,
@@ -2109,8 +2111,8 @@ pango_default_break (const char    *text,
  * For most purposes you may want to use
  * [func@Pango.get_log_attrs].
  *
- * Deprecated: 1.44: Use [func@Pango.default_break] and
- *   [func@Pango.tailor_break]
+ * Deprecated: 1.44: Use [func@Pango.default_break],
+ *   [func@Pango.tailor_break] and func@Pango.attr_break].
  */
 void
 pango_break (const char    *text,
@@ -2145,6 +2147,10 @@ pango_break (const char    *text,
  * If @offset is not -1, it is used to apply attributes
  * from @analysis that are relevant to line breaking.
  *
+ * Note that it is better to pass -1 for @offset and
+ * use [func@Pango.attr_break] to apply attributes to
+ * the whole paragraph.
+ *
  * Since: 1.44
  */
 void
@@ -2172,6 +2178,38 @@ pango_tailor_break (const char    *text,
     }
 }
 
+/**
+ * pango_attr_break:
+ * @text: text to break. Must be valid UTF-8
+ * @length: length of text in bytes (may be -1 if @text is nul-terminated)
+ * @attr_list: `PangoAttrList` to apply
+ * @offset: Byte offset of @text from the beginning of the paragraph
+ * @attrs: (array length=attrs_len): array with one `PangoLogAttr`
+ *   per character in @text, plus one extra, to be filled in
+ * @attrs_len: length of @attrs array
+ *
+ * Apply customization from attributes to the breaks in @attrs.
+ *
+ * The line breaks are assumed to have been produced
+ * by [func@Pango.default_break] and [func@Pango.tailor_break].
+ *
+ * Since: 1.50
+ */
+void
+pango_attr_break (const char    *text,
+                  int            length,
+                  PangoAttrList *attr_list,
+                  int            offset,
+                  PangoLogAttr  *attrs,
+                  int            attrs_len)
+{
+  GSList *attributes;
+
+  attributes = pango_attr_list_get_attributes (attr_list);
+  break_attrs (text, length, attributes, offset, attrs, attrs_len);
+  g_slist_free_full (attributes, (GDestroyNotify)pango_attribute_destroy);
+}
+
 /**
  * pango_get_log_attrs:
  * @text: text to process. Must be valid UTF-8
diff --git a/pango/pango-break.h b/pango/pango-break.h
index 15db125b..b5a0a7f7 100644
--- a/pango/pango-break.h
+++ b/pango/pango-break.h
@@ -123,6 +123,14 @@ void                    pango_tailor_break      (const char    *text,
                                                  PangoLogAttr  *attrs,
                                                  int            attrs_len);
 
+PANGO_AVAILABLE_IN_1_50
+void                    pango_attr_break        (const char    *text,
+                                                 int            length,
+                                                 PangoAttrList *attr_list,
+                                                 int            offset,
+                                                 PangoLogAttr  *attrs,
+                                                 int            attrs_len);
+
 #define PANGO_VALIDATE_ERROR (pango_validate_error_quark ())
 
 typedef enum
diff --git a/pango/pango-layout.c b/pango/pango-layout.c
index 99cb6381..9a2a15b2 100644
--- a/pango/pango-layout.c
+++ b/pango/pango-layout.c
@@ -4256,12 +4256,13 @@ process_line (PangoLayout    *layout,
 }
 
 static void
-get_items_log_attrs (const char   *text,
-                     int           start,
-                     int           length,
-                     GList        *items,
-                     PangoLogAttr *log_attrs,
-                     int           log_attrs_len)
+get_items_log_attrs (const char    *text,
+                     int            start,
+                     int            length,
+                     GList         *items,
+                     PangoAttrList *attrs,
+                     PangoLogAttr  *log_attrs,
+                     int            log_attrs_len)
 {
   int offset = 0;
   GList *l;
@@ -4277,12 +4278,18 @@ get_items_log_attrs (const char   *text,
       pango_tailor_break (text + item->offset,
                           item->length,
                           &item->analysis,
-                          item->offset,
+                          -1,
                           log_attrs + offset,
                           item->num_chars + 1);
 
       offset += item->num_chars;
     }
+
+  if (attrs && items)
+    {
+      PangoItem *item = items->data;
+      pango_attr_break (text + start, length, attrs, item->offset, log_attrs, log_attrs_len);
+    }
 }
 
 static PangoAttrList *
@@ -4559,6 +4566,7 @@ pango_layout_check_lines (PangoLayout *layout)
                              start - layout->text,
                              delimiter_index + delim_len,
                              state.items,
+                             shape_attrs,
                              layout->log_attrs + start_offset,
                              layout->n_chars + 1 - start_offset);
 


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