[pango/log-attr-tweaks: 22/23] break: Add pango_attr_break api




commit fc49ebb8b6bc6713800de6ae17215181167ed6d7
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 a08716a7..d2e4cb6a 100644
--- a/pango/break.c
+++ b/pango/break.c
@@ -2098,6 +2098,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,
@@ -2123,8 +2125,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,
@@ -2159,6 +2161,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
@@ -2186,6 +2192,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 460650cf..9cbd86f2 100644
--- a/pango/pango-layout.c
+++ b/pango/pango-layout.c
@@ -4260,12 +4260,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;
@@ -4281,12 +4282,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 *
@@ -4563,6 +4570,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]