[pango/pango2: 70/201] Move ItemProperties




commit e41da30d8064e477210ec110bf776ddedfe7d2bd
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Jan 15 17:18:17 2022 -0500

    Move ItemProperties
    
    This will be used in multiple places going forward,
    so move it to pango-item.c

 pango/pango-item-private.h |  21 ++++++++
 pango/pango-item.c         | 107 ++++++++++++++++++++++++++++++++++++
 pango/pango-layout.c       | 132 ++-------------------------------------------
 3 files changed, 131 insertions(+), 129 deletions(-)
---
diff --git a/pango/pango-item-private.h b/pango/pango-item-private.h
index dc250982..93265148 100644
--- a/pango/pango-item-private.h
+++ b/pango/pango-item-private.h
@@ -54,6 +54,27 @@ void               pango_item_unsplit                 (PangoItem *orig,
                                                        int        split_offset);
 
 
+typedef struct _ItemProperties ItemProperties;
+struct _ItemProperties
+{
+  guint uline_single   : 1;
+  guint uline_double   : 1;
+  guint uline_low      : 1;
+  guint uline_error    : 1;
+  guint strikethrough  : 1;
+  guint oline_single   : 1;
+  guint showing_space  : 1;
+  int            letter_spacing;
+  gboolean        shape_set;
+  PangoRectangle *shape_ink_rect;
+  PangoRectangle *shape_logical_rect;
+  double line_height;
+  int    absolute_line_height;
+};
+
+void               pango_item_get_properties          (PangoItem        *item,
+                                                       ItemProperties   *properties);
+
 G_END_DECLS
 
 #endif /* __PANGO_ITEM_PRIVATE_H__ */
diff --git a/pango/pango-item.c b/pango/pango-item.c
index 131094e6..4aa39bdc 100644
--- a/pango/pango-item.c
+++ b/pango/pango-item.c
@@ -359,3 +359,110 @@ pango_analysis_get_size_font (const PangoAnalysis *analysis)
 {
   return analysis->size_font;
 }
+
+/*< private >
+ * pango_item_get_properties:
+ * @item: a `PangoItem`
+ * @properties: `ItemProperties` struct to populate
+ *
+ * Extract useful information from the @item's attributes.
+ *
+ * Note that letter-spacing and shape are required to be constant
+ * across items. But underline and strikethrough can vary across
+ * an item, so we collect all the values that we find.
+ */
+void
+pango_item_get_properties (PangoItem      *item,
+                           ItemProperties *properties)
+{
+  GSList *tmp_list = item->analysis.extra_attrs;
+
+  properties->uline_single = FALSE;
+  properties->uline_double = FALSE;
+  properties->uline_low = FALSE;
+  properties->uline_error = FALSE;
+  properties->oline_single = FALSE;
+  properties->strikethrough = FALSE;
+  properties->showing_space = FALSE;
+  properties->letter_spacing = 0;
+  properties->shape_set = FALSE;
+  properties->shape_ink_rect = NULL;
+  properties->shape_logical_rect = NULL;
+  properties->line_height = 0.0;
+  properties->absolute_line_height = 0;
+
+  while (tmp_list)
+    {
+      PangoAttribute *attr = tmp_list->data;
+
+      switch ((int) attr->klass->type)
+        {
+        case PANGO_ATTR_UNDERLINE:
+          switch (((PangoAttrInt *)attr)->value)
+            {
+            case PANGO_UNDERLINE_NONE:
+              break;
+            case PANGO_UNDERLINE_SINGLE:
+            case PANGO_UNDERLINE_SINGLE_LINE:
+              properties->uline_single = TRUE;
+              break;
+            case PANGO_UNDERLINE_DOUBLE:
+            case PANGO_UNDERLINE_DOUBLE_LINE:
+              properties->uline_double = TRUE;
+              break;
+            case PANGO_UNDERLINE_LOW:
+              properties->uline_low = TRUE;
+              break;
+            case PANGO_UNDERLINE_ERROR:
+            case PANGO_UNDERLINE_ERROR_LINE:
+              properties->uline_error = TRUE;
+              break;
+            default:
+              g_assert_not_reached ();
+              break;
+            }
+          break;
+        case PANGO_ATTR_OVERLINE:
+          switch (((PangoAttrInt *)attr)->value)
+            {
+            case PANGO_OVERLINE_SINGLE:
+              properties->oline_single = TRUE;
+              break;
+            default:
+              g_assert_not_reached ();
+              break;
+            }
+          break;
+
+        case PANGO_ATTR_STRIKETHROUGH:
+          properties->strikethrough = ((PangoAttrInt *)attr)->value;
+          break;
+
+        case PANGO_ATTR_LETTER_SPACING:
+          properties->letter_spacing = ((PangoAttrInt *)attr)->value;
+          break;
+
+        case PANGO_ATTR_SHAPE:
+          properties->shape_set = TRUE;
+          properties->shape_logical_rect = &((PangoAttrShape *)attr)->logical_rect;
+          properties->shape_ink_rect = &((PangoAttrShape *)attr)->ink_rect;
+          break;
+
+        case PANGO_ATTR_LINE_HEIGHT:
+          properties->line_height = ((PangoAttrFloat *)attr)->value;
+          break;
+
+        case PANGO_ATTR_ABSOLUTE_LINE_HEIGHT:
+          properties->absolute_line_height = ((PangoAttrInt *)attr)->value;
+          break;
+
+        case PANGO_ATTR_SHOW:
+          properties->showing_space = (((PangoAttrInt *)attr)->value & PANGO_SHOW_SPACES) != 0;
+          break;
+
+        default:
+          break;
+        }
+      tmp_list = tmp_list->next;
+    }
+}
diff --git a/pango/pango-layout.c b/pango/pango-layout.c
index ae0235a5..fee1321e 100644
--- a/pango/pango-layout.c
+++ b/pango/pango-layout.c
@@ -91,35 +91,9 @@
 #include "pango-utils-internal.h"
 
 
-typedef struct _ItemProperties ItemProperties;
 typedef struct _ParaBreakState ParaBreakState;
 typedef struct _LastTabState LastTabState;
 
-/* Note that letter_spacing and shape are constant across items,
- * since we pass them into itemization.
- *
- * uline and strikethrough can vary across an item, so we collect
- * all the values that we find.
- *
- * See pango_layout_get_item_properties for details.
- */
-struct _ItemProperties
-{
-  guint uline_single   : 1;
-  guint uline_double   : 1;
-  guint uline_low      : 1;
-  guint uline_error    : 1;
-  guint strikethrough  : 1;
-  guint oline_single   : 1;
-  guint showing_space  : 1;
-  gint            letter_spacing;
-  gboolean        shape_set;
-  PangoRectangle *shape_ink_rect;
-  PangoRectangle *shape_logical_rect;
-  double line_height;
-  int    absolute_line_height;
-};
-
 typedef struct _PangoLayoutLinePrivate PangoLayoutLinePrivate;
 
 struct _PangoLayoutLinePrivate
@@ -191,9 +165,6 @@ static void pango_layout_line_leaked (PangoLayoutLine *line);
 static PangoLayoutLine * _pango_layout_iter_get_line (PangoLayoutIter *iter);
 static PangoLayoutRun *  _pango_layout_iter_get_run  (PangoLayoutIter *iter);
 
-static void pango_layout_get_item_properties (PangoItem      *item,
-                                              ItemProperties *properties);
-
 static void pango_layout_get_empty_extents_and_height_at_index (PangoLayout    *layout,
                                                                 int             index,
                                                                 PangoRectangle *logical_rect,
@@ -4039,7 +4010,7 @@ process_item (PangoLayout     *layout,
    */
   if (!state->glyphs)
     {
-      pango_layout_get_item_properties (item, &state->properties);
+      pango_item_get_properties (item, &state->properties);
       state->glyphs = shape_run (line, state, item);
       state->log_widths_offset = 0;
       processing_new_item = TRUE;
@@ -5609,7 +5580,7 @@ pango_layout_run_get_extents_and_height (PangoLayoutRun *run,
   if (G_UNLIKELY (!run_ink && !run_logical && !line_logical && !height))
     return;
 
-  pango_layout_get_item_properties (run->item, &properties);
+  pango_item_get_properties (run->item, &properties);
 
   has_underline = properties.uline_single || properties.uline_double ||
                   properties.uline_low || properties.uline_error;
@@ -6087,7 +6058,7 @@ get_item_letter_spacing (PangoItem *item)
 {
   ItemProperties properties;
 
-  pango_layout_get_item_properties (item, &properties);
+  pango_item_get_properties (item, &properties);
 
   return properties.letter_spacing;
 }
@@ -6834,103 +6805,6 @@ pango_layout_line_postprocess (PangoLayoutLine *line,
   line->layout->is_ellipsized |= ellipsized;
 }
 
-static void
-pango_layout_get_item_properties (PangoItem      *item,
-                                  ItemProperties *properties)
-{
-  GSList *tmp_list = item->analysis.extra_attrs;
-
-  properties->uline_single = FALSE;
-  properties->uline_double = FALSE;
-  properties->uline_low = FALSE;
-  properties->uline_error = FALSE;
-  properties->oline_single = FALSE;
-  properties->strikethrough = FALSE;
-  properties->showing_space = FALSE;
-  properties->letter_spacing = 0;
-  properties->shape_set = FALSE;
-  properties->shape_ink_rect = NULL;
-  properties->shape_logical_rect = NULL;
-  properties->line_height = 0.0;
-  properties->absolute_line_height = 0;
-
-  while (tmp_list)
-    {
-      PangoAttribute *attr = tmp_list->data;
-
-      switch ((int) attr->klass->type)
-        {
-        case PANGO_ATTR_UNDERLINE:
-          switch (((PangoAttrInt *)attr)->value)
-            {
-            case PANGO_UNDERLINE_NONE:
-              break;
-            case PANGO_UNDERLINE_SINGLE:
-            case PANGO_UNDERLINE_SINGLE_LINE:
-              properties->uline_single = TRUE;
-              break;
-            case PANGO_UNDERLINE_DOUBLE:
-            case PANGO_UNDERLINE_DOUBLE_LINE:
-              properties->uline_double = TRUE;
-              break;
-            case PANGO_UNDERLINE_LOW:
-              properties->uline_low = TRUE;
-              break;
-            case PANGO_UNDERLINE_ERROR:
-            case PANGO_UNDERLINE_ERROR_LINE:
-              properties->uline_error = TRUE;
-              break;
-            default:
-              g_assert_not_reached ();
-              break;
-            }
-          break;
-
-        case PANGO_ATTR_OVERLINE:
-          switch (((PangoAttrInt *)attr)->value)
-            {
-            case PANGO_OVERLINE_SINGLE:
-              properties->oline_single = TRUE;
-              break;
-            default:
-              g_assert_not_reached ();
-              break;
-            }
-          break;
-
-        case PANGO_ATTR_STRIKETHROUGH:
-          properties->strikethrough = ((PangoAttrInt *)attr)->value;
-          break;
-
-        case PANGO_ATTR_LETTER_SPACING:
-          properties->letter_spacing = ((PangoAttrInt *)attr)->value;
-          break;
-
-        case PANGO_ATTR_SHAPE:
-          properties->shape_set = TRUE;
-          properties->shape_logical_rect = &((PangoAttrShape *)attr)->logical_rect;
-          properties->shape_ink_rect = &((PangoAttrShape *)attr)->ink_rect;
-          break;
-
-        case PANGO_ATTR_LINE_HEIGHT:
-          properties->line_height = ((PangoAttrFloat *)attr)->value;
-          break;
-
-        case PANGO_ATTR_ABSOLUTE_LINE_HEIGHT:
-          properties->absolute_line_height = ((PangoAttrInt *)attr)->value;
-          break;
-
-        case PANGO_ATTR_SHOW:
-          properties->showing_space = (((PangoAttrInt *)attr)->value & PANGO_SHOW_SPACES) != 0;
-          break;
-
-        default:
-          break;
-        }
-      tmp_list = tmp_list->next;
-    }
-}
-
 static int
 next_cluster_start (PangoGlyphString *gs,
                     int               cluster_start)


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