[pango/pango2: 129/195] lines: tweak the array api




commit 86d06548457386748416c097b5598a63bc885edb
Author: Matthias Clasen <mclasen redhat com>
Date:   Tue Jan 25 14:48:13 2022 -0500

    lines: tweak the array api
    
    Make this work like the line api, with
    pango_lines_get_lines() and pango_lines_get_line_count().
    Update all users.

 examples/cairotwisted.c     |   2 +-
 examples/parshape.c         |   4 +-
 pango/pango-layout.c        |  10 +--
 pango/pango-line-iter.c     |  77 +++++++++----------
 pango/pango-lines-private.h |   9 ++-
 pango/pango-lines.c         | 182 ++++++++++++++++++++++----------------------
 pango/pango-lines.h         |   6 +-
 pango/pango-renderer.c      |  12 +--
 pango/pangocairo-font.c     |   8 +-
 pango/pangofc-font.c        |   9 ++-
 pango/serializer.c          |   7 +-
 tests/test-bidi.c           |   2 +-
 tests/testiter.c            |   7 +-
 tests/testmisc.c            |  10 +--
 14 files changed, 176 insertions(+), 169 deletions(-)
---
diff --git a/examples/cairotwisted.c b/examples/cairotwisted.c
index 88f781b4..ff7952d4 100644
--- a/examples/cairotwisted.c
+++ b/examples/cairotwisted.c
@@ -492,7 +492,7 @@ draw_text (cairo_t *cr,
 
   pango_layout_set_text (layout, text, -1);
 
-  line = pango_lines_get_line (pango_layout_get_lines (layout), 0, NULL, NULL);
+  line = pango_lines_get_lines (pango_layout_get_lines (layout))[0];
 
   cairo_move_to (cr, x, y);
   pango_cairo_line_path (cr, line);
diff --git a/examples/parshape.c b/examples/parshape.c
index c09e1ddd..da4b5516 100644
--- a/examples/parshape.c
+++ b/examples/parshape.c
@@ -99,7 +99,9 @@ main (int argc, char *argv[])
 
   for (int i = 0; i < pango_lines_get_line_count (lines); i++)
     {
-      PangoLine *line = pango_lines_get_line (lines, i, &x, &y);
+      PangoLine *line = pango_lines_get_lines (lines)[i];
+
+      pango_lines_get_line_position (lines, i, &x, &y);
 
       cairo_save (cr);
       cairo_move_to (cr, x / (double)PANGO_SCALE, y / (double)PANGO_SCALE);
diff --git a/pango/pango-layout.c b/pango/pango-layout.c
index 6dacf398..c218422e 100644
--- a/pango/pango-layout.c
+++ b/pango/pango-layout.c
@@ -708,7 +708,7 @@ retry:
           {
             PangoLine *first_line;
             if (pango_lines_get_line_count (layout->lines) > 0)
-              first_line = pango_lines_get_line (layout->lines, 0, NULL, NULL);
+              first_line = pango_lines_get_lines (layout->lines)[0];
             else
               first_line = line;
             if (pango_line_get_resolved_direction (first_line) == PANGO_DIRECTION_LTR)
@@ -748,9 +748,7 @@ retry:
         {
           PangoLine *last;
 
-          last = pango_lines_get_line (layout->lines,
-                                       pango_lines_get_line_count (layout->lines) - 1,
-                                       NULL, NULL);
+          last = pango_lines_get_lines (layout->lines)[pango_lines_get_line_count (layout->lines) - 1];
           data = line_data_ref (last->data);
           start_index = data->length;
           start_offset = last->data->n_chars;
@@ -1641,7 +1639,7 @@ pango_layout_get_character_count (PangoLayout *layout)
 
   ensure_lines (layout);
 
-  line = pango_lines_get_line (layout->lines, 0, NULL, NULL);
+  line = pango_lines_get_lines (layout->lines)[0];
 
   return line->data->n_chars;
 }
@@ -1696,7 +1694,7 @@ pango_layout_get_log_attrs (PangoLayout *layout,
 
   ensure_lines (layout);
 
-  line = pango_lines_get_line (layout->lines, 0, NULL, NULL);
+  line = pango_lines_get_lines (layout->lines)[0];
 
   if (n_attrs)
     *n_attrs = line->data->n_chars + 1;
diff --git a/pango/pango-line-iter.c b/pango/pango-line-iter.c
index a24cf50a..bc9924a4 100644
--- a/pango/pango-line-iter.c
+++ b/pango/pango-line-iter.c
@@ -27,8 +27,7 @@ struct _PangoLineIter
   guint serial;
 
   int line_no;
-  int line_x;
-  int line_y;
+  Position line_pos;
   PangoLine *line;
   GSList *run_link;
   PangoRun *run;
@@ -118,8 +117,9 @@ update_cluster (PangoLineIter *iter,
   PangoGlyphItem *glyph_item;
   char *cluster_text;
   int  cluster_length;
+  PangoRun *run = iter->run_link->data;
 
-  glyph_item = pango_run_get_glyph_item (iter->run);
+  glyph_item = pango_run_get_glyph_item (run);
 
   iter->character_position = 0;
 
@@ -221,11 +221,13 @@ next_cluster_internal (PangoLineIter *iter,
                        gboolean       include_terminators)
 {
   PangoGlyphItem *glyph_item;
+  PangoRun *run;
 
-  if (iter->run == NULL)
+  if (iter->run_link == NULL)
     return next_nonempty_line (iter, include_terminators);
 
-  glyph_item = pango_run_get_glyph_item (iter->run);
+  run = iter->run_link->data;
+  glyph_item = pango_run_get_glyph_item (run);
 
   if (iter->next_cluster_glyph == glyph_item->glyphs->num_glyphs)
     {
@@ -245,46 +247,32 @@ static void
 update_run (PangoLineIter *iter,
             int            start_index)
 {
-  PangoGlyphItem *glyph_item;
-
   if (iter->run)
-    glyph_item = pango_run_get_glyph_item (iter->run);
-
-  if (iter->run_link == iter->line->runs)
-    iter->run_x = 0;
-  else
     {
-      iter->run_x += iter->end_x_offset + iter->run_width;
-      if (iter->run)
-        iter->run_x += glyph_item->start_x_offset;
-    }
+      PangoGlyphItem *glyph_item = pango_run_get_glyph_item (iter->run);
+
+      if (iter->run_link == iter->line->runs)
+        iter->run_x = 0;
+      else
+        iter->run_x += iter->run_width + iter->end_x_offset + glyph_item->start_x_offset;
 
-  if (iter->run)
-    {
       iter->run_width = pango_glyph_string_get_width (glyph_item->glyphs);
       iter->end_x_offset = glyph_item->end_x_offset;
+      iter->ltr = (glyph_item->item->analysis.level % 2) == 0;
+      iter->cluster_start = 0;
+      iter->cluster_x = iter->run_x;
+      update_cluster (iter, glyph_item->glyphs->log_clusters[0]);
     }
   else
     {
       /* The empty run at the end of a line */
+      iter->run_x = 0;
+
       iter->run_width = 0;
       iter->end_x_offset = 0;
-    }
-
-  if (iter->run)
-    iter->ltr = (glyph_item->item->analysis.level % 2) == 0;
-  else
-    iter->ltr = TRUE;
-
-  iter->cluster_start = 0;
-  iter->cluster_x = iter->run_x;
-
-  if (iter->run)
-    {
-      update_cluster (iter, glyph_item->glyphs->log_clusters[0]);
-    }
-  else
-    {
+      iter->ltr = TRUE;
+      iter->cluster_start = 0;
+      iter->cluster_x = iter->run_x;
       iter->cluster_width = 0;
       iter->character_position = 0;
       iter->cluster_num_chars = 0;
@@ -299,13 +287,13 @@ offset_line (PangoLineIter  *iter,
 {
   if (ink_rect)
     {
-      ink_rect->x += iter->line_x;
-      ink_rect->y += iter->line_y;
+      ink_rect->x += iter->line_pos.x;
+      ink_rect->y += iter->line_pos.y;
     }
   if (logical_rect)
     {
-      logical_rect->x += iter->line_x;
-      logical_rect->y += iter->line_y;
+      logical_rect->x += iter->line_pos.x;
+      logical_rect->y += iter->line_pos.y;
     }
 }
 
@@ -337,7 +325,8 @@ pango_line_iter_new (PangoLines *lines)
   iter->serial = pango_lines_get_serial (lines);
 
   iter->line_no = 0;
-  iter->line = pango_lines_get_line (iter->lines, 0, &iter->line_x, &iter->line_y);
+  iter->line = g_ptr_array_index (lines->lines, 0);
+  iter->line_pos = g_array_index (lines->positions, Position, 0);
   iter->run_link = iter->line->runs;
   if (iter->run_link)
     {
@@ -503,11 +492,13 @@ pango_line_iter_next_line (PangoLineIter *iter)
 {
   g_return_val_if_fail (ITER_IS_VALID (iter), FALSE);
 
-  iter->line = pango_lines_get_line (iter->lines, iter->line_no + 1, &iter->line_x, &iter->line_y);
-  if (!iter->line)
+  iter->line_no++;
+  if (iter->line_no == iter->lines->lines->len)
     return FALSE;
 
-  iter->line_no++;
+  iter->line = g_ptr_array_index (iter->lines->lines, iter->line_no);
+  iter->line_pos = g_array_index (iter->lines->positions, Position, iter->line_no);
+
   iter->run_link = iter->line->runs;
   if (iter->run_link)
     iter->run = iter->run_link->data;
@@ -853,7 +844,7 @@ pango_line_iter_get_line_baseline (PangoLineIter *iter)
 {
   g_return_val_if_fail (ITER_IS_VALID (iter), 0);
 
-  return iter->line_y;
+  return iter->line_pos.y;
 }
 
 /**
diff --git a/pango/pango-lines-private.h b/pango/pango-lines-private.h
index 13f33e1e..447d716c 100644
--- a/pango/pango-lines-private.h
+++ b/pango/pango-lines-private.h
@@ -22,10 +22,17 @@
 #include "pango-lines.h"
 
 
+typedef struct _Position Position;
+struct _Position
+{
+  int x, y;
+};
+
 struct _PangoLines
 {
   GObject parent_instance;
 
-  GArray *lines;
+  GPtrArray *lines;
+  GArray *positions;
   guint serial;
 };
diff --git a/pango/pango-lines.c b/pango/pango-lines.c
index 0fe15f71..9251fa71 100644
--- a/pango/pango-lines.c
+++ b/pango/pango-lines.c
@@ -41,13 +41,6 @@
 
 /*  {{{ PangoLines implementation */
 
-typedef struct _Line Line;
-struct _Line
-{
-  PangoLine *line;
-  int x, y;
-};
-
 struct _PangoLinesClass
 {
   GObjectClass parent_class;
@@ -59,7 +52,8 @@ static void
 pango_lines_init (PangoLines *lines)
 {
   lines->serial = 1;
-  lines->lines = g_array_new (FALSE, FALSE, sizeof (Line));
+  lines->lines = g_ptr_array_new_with_free_func ((GDestroyNotify) pango_line_free);
+  lines->positions = g_array_new (FALSE, FALSE, sizeof (Position));
 }
 
 static void
@@ -67,13 +61,8 @@ pango_lines_finalize (GObject *object)
 {
   PangoLines *lines = PANGO_LINES (object);
 
-  for (int i = 0; i < lines->lines->len; i++)
-    {
-      Line *line = &g_array_index (lines->lines, Line, i);
-      pango_line_free (line->line);
-    }
-
-  g_array_free (lines->lines, TRUE);
+  g_ptr_array_unref (lines->lines);
+  g_array_unref (lines->positions);
 
   G_OBJECT_CLASS (pango_lines_parent_class)->finalize (object);
 }
@@ -115,17 +104,16 @@ pango_line_get_cursors (PangoLines      *lines,
   int j;
   const char *p;
   PangoRectangle pos;
-  Line *l = NULL;
+  Position offset;
 
   g_assert (g_array_get_element_size (cursors) == sizeof (CursorPos));
   g_assert (cursors->len == 0);
 
   for (int i = 0; i < lines->lines->len; i++)
     {
-      Line *ll = &g_array_index (lines->lines, Line, i);
-      if (ll->line == line)
+      if (line == g_ptr_array_index (lines->lines, i))
         {
-          l = ll;
+          offset = g_array_index (lines->positions, Position, i);
           break;
         }
     }
@@ -149,7 +137,7 @@ pango_line_get_cursors (PangoLines      *lines,
                                      strong ? &pos : NULL,
                                      strong ? NULL : &pos);
 
-          cursor.x = pos.x + l->x;
+          cursor.x = pos.x + offset.x;
           cursor.pos = idx;
           g_array_append_val (cursors, cursor);
         }
@@ -218,13 +206,10 @@ pango_lines_add_line (PangoLines      *lines,
                       int              x_line,
                       int              y_line)
 {
-  Line l;
+  Position pos = { x_line, y_line };
 
-  l.line = line;
-  l.x = x_line;
-  l.y = y_line;
-
-  g_array_append_val (lines->lines, l);
+  g_ptr_array_add (lines->lines, line);
+  g_array_append_val (lines->positions, pos);
 
   lines->serial++;
   if (lines->serial == 0)
@@ -266,37 +251,53 @@ pango_lines_get_line_count (PangoLines *lines)
 }
 
 /**
- * pango_lines_get_line:
+ * pango_lines_get_lines:
  * @lines: a `PangoLines`
- * @num: the position of the line to get
+ *
+ * Gets the lines.
+ *
+ * The length of the returned array can be obtained with
+ * [method@Pango.Lines.get_line_count].
+ *
+ * Returns: (transfer none): the array of lines
+ */
+PangoLine **
+pango_lines_get_lines (PangoLines *lines)
+{
+  g_return_val_if_fail (PANGO_IS_LINES (lines), NULL);
+
+  return (PangoLine **)lines->lines->pdata;
+}
+
+/**
+ * pango_lines_get_line_position:
+ * pango_lines_get_lines:
+ * @lines: a `PangoLines`
+ * @num: the index of the line to get the position for
  * @line_x: (out) (optional): return location for the X coordinate
  * @line_y: (out) (optional): return location for the Y coordinate
  *
- * Gets the @num-th line of @lines.
- *
- * Returns: (transfer none) (nullable): the line that was found
+ * Gets the position of a line.
  */
-PangoLine *
-pango_lines_get_line (PangoLines  *lines,
-                      int          num,
-                      int         *line_x,
-                      int         *line_y)
+void
+pango_lines_get_line_position (PangoLines *lines,
+                               int         num,
+                               int        *line_x,
+                               int        *line_y)
 {
-  Line *l;
+  Position *pos;
 
-  g_return_val_if_fail (PANGO_IS_LINES (lines), NULL);
+  g_return_if_fail (PANGO_IS_LINES (lines));
 
   if (num >= lines->lines->len)
-    return NULL;
+    return;
 
-  l = &g_array_index (lines->lines, Line, num);
+  pos = &g_array_index (lines->positions, Position, num);
 
   if (line_x)
-    *line_x = l->x;
+    *line_x = pos->x;
   if (line_y)
-    *line_y = l->y;
-
-  return l->line;
+    *line_y = pos->y;
 }
 
 /* {{{ Miscellaneous */
@@ -321,9 +322,9 @@ pango_lines_get_unknown_glyphs_count (PangoLines *lines)
 
   for (int i = 0; i < lines->lines->len; i++)
     {
-      Line *ll = &g_array_index (lines->lines, Line, i);
+      PangoLine *line = g_ptr_array_index (lines->lines, i);
 
-      for (GSList *l = ll->line->runs; l; l = l->next)
+      for (GSList *l = line->runs; l; l = l->next)
         {
           PangoGlyphItem *run = l->data;
 
@@ -351,8 +352,8 @@ pango_lines_is_wrapped (PangoLines *lines)
 {
   for (int i = 0; i < lines->lines->len; i++)
     {
-      Line *l = &g_array_index (lines->lines, Line, i);
-      if (pango_line_is_wrapped (l->line))
+      PangoLine *line = g_ptr_array_index (lines->lines, i);
+      if (pango_line_is_wrapped (line))
         return TRUE;
     }
 
@@ -372,8 +373,8 @@ pango_lines_is_ellipsized (PangoLines *lines)
 {
   for (int i = 0; i < lines->lines->len; i++)
     {
-      Line *l = &g_array_index (lines->lines, Line, i);
-      if (pango_line_is_ellipsized (l->line))
+      PangoLine *line = g_ptr_array_index (lines->lines, i);
+      if (pango_line_is_ellipsized (line))
         return TRUE;
     }
 
@@ -393,8 +394,8 @@ pango_lines_is_hyphenated (PangoLines *lines)
 {
   for (int i = 0; i < lines->lines->len; i++)
     {
-      Line *l = &g_array_index (lines->lines, Line, i);
-      if (pango_line_is_hyphenated (l->line))
+      PangoLine *line = g_ptr_array_index (lines->lines, i);
+      if (pango_line_is_hyphenated (line))
         return TRUE;
     }
 
@@ -428,23 +429,24 @@ pango_lines_get_extents (PangoLines     *lines,
 {
   for (int i = 0; i < lines->lines->len; i++)
     {
-      Line *l = &g_array_index (lines->lines, Line, i);
+      PangoLine *line = g_ptr_array_index (lines->lines, i);
+      Position *pos = &g_array_index (lines->positions, Position, i);
       PangoRectangle line_ink;
       PangoRectangle line_logical;
       PangoLeadingTrim trim = PANGO_LEADING_TRIM_NONE;
 
-      if (l->line->starts_paragraph)
+      if (line->starts_paragraph)
         trim |= PANGO_LEADING_TRIM_START;
-      if (l->line->ends_paragraph)
+      if (line->ends_paragraph)
         trim |= PANGO_LEADING_TRIM_END;
 
-      pango_line_get_extents (l->line, &line_ink, NULL);
-      pango_line_get_trimmed_extents (l->line, trim, &line_logical);
+      pango_line_get_extents (line, &line_ink, NULL);
+      pango_line_get_trimmed_extents (line, trim, &line_logical);
 
-      line_ink.x += l->x;
-      line_ink.y += l->y;
-      line_logical.x += l->x;
-      line_logical.y += l->y;
+      line_ink.x += pos->x;
+      line_ink.y += pos->y;
+      line_logical.x += pos->x;
+      line_logical.y += pos->y;
 
       if (i == 0)
         {
@@ -519,16 +521,16 @@ pango_lines_get_size (PangoLines *lines,
 int
 pango_lines_get_baseline (PangoLines *lines)
 {
-  Line *l;
+  Position *pos;
 
   g_return_val_if_fail (PANGO_IS_LINES (lines), 0);
 
   if (lines->lines->len == 0)
     return 0;
 
-  l = &g_array_index (lines->lines, Line, 0);
+  pos = &g_array_index (lines->positions, Position, 0);
 
-  return l->y;
+  return pos->y;
 }
 
 /**
@@ -686,7 +688,7 @@ pango_lines_get_x_ranges (PangoLines *lines,
 }
 
 /* }}} */
- /* {{{ Editing API */
+  /* {{{ Editing API */
 
 /**
  * pango_lines_index_to_line:
@@ -718,38 +720,40 @@ pango_lines_index_to_line (PangoLines *lines,
                            int        *x_offset,
                            int        *y_offset)
 {
-  Line *found = NULL;
+  PangoLine *found = NULL;
   int num;
   int i;
+  Position pos;
 
   g_return_if_fail (PANGO_IS_LINES (lines));
 
   for (i = 0; i < lines->lines->len; i++)
     {
-      Line *l = &g_array_index (lines->lines, Line, i);
+      PangoLine *l = g_ptr_array_index (lines->lines, i);
 
-      if (l->line->start_index > idx && found)
+      if (l->start_index > idx && found)
         break;
 
       found = l;
+      pos = g_array_index (lines->positions, Position, i);
       num = i;
 
-      if (*line && *line == found->line)
+      if (*line && *line == found)
         break;
 
-      if (l->line->start_index + l->line->length > idx)
+      if (l->start_index + l->length > idx)
         break;
     }
 
   if (found)
     {
-      *line = found->line;
+      *line = found;
       if (line_no)
         *line_no = num;
       if (x_offset)
-        *x_offset = found->x;
+        *x_offset = pos.x;
       if (y_offset)
-        *y_offset = found->y;
+        *y_offset = pos.y;
 
       return;
     }
@@ -783,23 +787,24 @@ pango_lines_pos_to_line (PangoLines *lines,
 
   for (int i = 0; i < lines->lines->len; i++)
     {
-      Line *l = &g_array_index (lines->lines, Line, i);
+      PangoLine *line = g_ptr_array_index (lines->lines, i);
+      Position pos = g_array_index (lines->positions, Position, i);
       PangoRectangle ext;
 
-      pango_line_get_extents (l->line, NULL, &ext);
+      pango_line_get_extents (line, NULL, &ext);
 
-      ext.x += l->x;
-      ext.y += l->y;
+      ext.x += pos.x;
+      ext.y += pos.y;
 
       if (ext.x <= x && x <= ext.x + ext.width &&
           ext.y <= y && y <= ext.y + ext.height)
         {
           if (line_x)
-            *line_x = l->x;
+            *line_x = pos.x;
           if (line_y)
-            *line_y = l->y;
+            *line_y = pos.y;
 
-          return l->line;
+          return line;
         }
     }
 
@@ -1153,11 +1158,8 @@ pango_lines_move_cursor (PangoLines  *lines,
 
       if (off_start)
         {
-          PangoLine *prev_line;
-
-          prev_line = pango_lines_get_line (lines, line_no - 1, NULL, NULL);
-          if (!prev_line)
-            {
+         if (line_no == 0)
+           {
               if (new_line)
                 *new_line = NULL;
               *new_idx = -1;
@@ -1166,16 +1168,13 @@ pango_lines_move_cursor (PangoLines  *lines,
               return;
             }
 
-          line = prev_line;
           line_no--;
+          line = g_ptr_array_index (lines->lines, line_no);
           paragraph_boundary = (line->start_index + line->length != idx);
         }
       else
         {
-          PangoLine *next_line;
-
-          next_line = pango_lines_get_line (lines, line_no + 1, NULL, NULL);
-          if (!next_line)
+          if (line_no == lines->lines->len - 1)
             {
               if (new_line)
                 *new_line = NULL;
@@ -1184,8 +1183,9 @@ pango_lines_move_cursor (PangoLines  *lines,
               g_array_unref (cursors);
               return;
             }
-          line = next_line;
+
           line_no++;
+          line = g_ptr_array_index (lines->lines, line_no);
           paragraph_boundary = (line->start_index != idx);
         }
 
diff --git a/pango/pango-lines.h b/pango/pango-lines.h
index 3b379aff..77871565 100644
--- a/pango/pango-lines.h
+++ b/pango/pango-lines.h
@@ -47,7 +47,11 @@ PANGO_AVAILABLE_IN_ALL
 int                     pango_lines_get_line_count  (PangoLines        *lines);
 
 PANGO_AVAILABLE_IN_ALL
-PangoLine *             pango_lines_get_line        (PangoLines        *lines,
+PangoLine **            pango_lines_get_lines       (PangoLines        *lines);
+
+PANGO_AVAILABLE_IN_ALL
+void                    pango_lines_get_line_position
+                                                    (PangoLines        *lines,
                                                      int                num,
                                                      int               *line_x,
                                                      int               *line_y);
diff --git a/pango/pango-renderer.c b/pango/pango-renderer.c
index 6739cd00..da802c3e 100644
--- a/pango/pango-renderer.c
+++ b/pango/pango-renderer.c
@@ -578,20 +578,22 @@ pango_renderer_draw_lines (PangoRenderer *renderer,
   int n;
   PangoLine *line;
   int line_x, line_y;
+  PangoLine **l;
 
   g_return_if_fail (PANGO_IS_RENDERER_FAST (renderer));
 
   renderer->priv->lines = lines;
 
-  n = 0;
-  while ((line = pango_lines_get_line (lines, n, &line_x, &line_y)) != NULL)
+  l = pango_lines_get_lines (lines);
+  for (n = 0; n < pango_lines_get_line_count (lines); n++)
     {
+      line = l[n];
+      pango_lines_get_line_position (lines, n, &line_x, &line_y);
+
       if (n == 0)
         pango_renderer_activate_with_context (renderer, line->context);
 
-      pango_renderer_draw_layout_line (renderer, line, x + line_x, y + line_y);
-
-      n++;
+      pango_renderer_draw_line (renderer, line, x + line_x, y + line_y);
     }
 
   if (n > 0)
diff --git a/pango/pangocairo-font.c b/pango/pangocairo-font.c
index 4c3dc787..803920dd 100644
--- a/pango/pangocairo-font.c
+++ b/pango/pangocairo-font.c
@@ -190,14 +190,16 @@ static int
 max_glyph_width (PangoLayout *layout)
 {
   PangoLines *lines;
+  PangoLine **l;
   int max_width = 0;
 
   lines = pango_layout_get_lines (layout);
+  l = pango_lines_get_lines (lines);
+
   for (int i = 0; i < pango_lines_get_line_count (lines); i++)
     {
-      PangoLine *line = pango_lines_get_line (lines, i, NULL, NULL);
-      PangoRun **runs = pango_line_get_runs (line);
-      int n_runs = pango_line_get_run_count (line);
+      PangoRun **runs = pango_line_get_runs (l[i]);
+      int n_runs = pango_line_get_run_count (l[i]);
 
       for (int j = 0; j < n_runs; j++)
         {
diff --git a/pango/pangofc-font.c b/pango/pangofc-font.c
index 89088a85..d560181e 100644
--- a/pango/pangofc-font.c
+++ b/pango/pangofc-font.c
@@ -418,15 +418,16 @@ static int
 max_glyph_width (PangoLayout *layout)
 {
   PangoLines *lines;
+  PangoLine **l;
   int max_width = 0;
-  GSList *r;
 
   lines = pango_layout_get_lines (layout);
+  l = pango_lines_get_lines (lines);
+
   for (int i = 0; i < pango_lines_get_line_count (lines); i++)
     {
-      PangoLine *line = pango_lines_get_line (lines, i, NULL, NULL);
-      PangoRun **runs = pango_line_get_runs (line);
-      int n_runs = pango_line_get_run_count (line);
+      PangoRun **runs = pango_line_get_runs (l[i]);
+      int n_runs = pango_line_get_run_count (l[i]);
 
       for (int j = 0; j < n_runs; j++)
         {
diff --git a/pango/serializer.c b/pango/serializer.c
index 53a7c19a..787046b4 100644
--- a/pango/serializer.c
+++ b/pango/serializer.c
@@ -749,6 +749,7 @@ lines_to_json (GtkJsonPrinter *printer,
                PangoLines     *lines)
 {
   int width, height;
+  PangoLine **l;
 
   gtk_json_printer_start_object (printer, "output");
 
@@ -762,12 +763,12 @@ lines_to_json (GtkJsonPrinter *printer,
 
   gtk_json_printer_start_array (printer, "lines");
 
+  l = pango_lines_get_lines (lines);
   for (int i = 0; i < pango_lines_get_line_count (lines); i++)
     {
-      PangoLine *line;
       int x, y;
-      line = pango_lines_get_line (lines, i, &x, &y);
-      line_to_json (printer, line, x, y);
+      pango_lines_get_line_position (lines, i, &x, &y);
+      line_to_json (printer, l[i], x, y);
     }
 
   gtk_json_printer_end (printer);
diff --git a/tests/test-bidi.c b/tests/test-bidi.c
index aeae7c9d..3d174b62 100644
--- a/tests/test-bidi.c
+++ b/tests/test-bidi.c
@@ -127,7 +127,7 @@ test_move_cursor_line (void)
 
       text = pango_layout_get_text (layout);
       lines = pango_layout_get_lines (layout);
-      line = pango_lines_get_line (lines, 0, NULL, NULL);
+      line = pango_lines_get_lines (lines)[0];
 
       n_chars = g_utf8_strlen (text, -1);
 
diff --git a/tests/testiter.c b/tests/testiter.c
index 52125b28..43e6e932 100644
--- a/tests/testiter.c
+++ b/tests/testiter.c
@@ -261,7 +261,6 @@ test_glyphitem_iter (void)
   PangoLayout  *layout;
   PangoLine *line;
   const char *text;
-  GSList *l;
 
   fontmap = pango_cairo_font_map_get_default ();
   context = pango_font_map_create_context (fontmap);
@@ -273,10 +272,10 @@ test_glyphitem_iter (void)
   pango_layout_set_text (layout, "test تست", -1);
   text = pango_layout_get_text (layout);
 
-  line = pango_lines_get_line (pango_layout_get_lines (layout), 0, NULL, NULL);
+  line = pango_lines_get_lines (pango_layout_get_lines (layout))[0];
   for (int i = 0; i < pango_line_get_run_count (line); i++)
-    {
-    PangoGlyphItem *run = (PangoGlyphItem *)pango_line_get_runs (line)[i];
+  {
+    PangoGlyphItem *run = (PangoGlyphItem *)pango_line_get_runs (line)[i]; /* FIXME */
     int direction;
 
     for (direction = 0; direction < 2; direction++)
diff --git a/tests/testmisc.c b/tests/testmisc.c
index a8c6c689..4c3af64e 100644
--- a/tests/testmisc.c
+++ b/tests/testmisc.c
@@ -94,7 +94,7 @@ test_line_height (void)
   context = pango_font_map_create_context (pango_cairo_font_map_get_default ());
   layout = pango_layout_new (context);
   pango_layout_set_text (layout, "one\ttwo", -1);
-  line = pango_lines_get_line (pango_layout_get_lines (layout), 0, NULL, NULL);
+  line = pango_lines_get_lines (pango_layout_get_lines (layout))[0];
   pango_line_get_extents (line, NULL, &ext);
 
   g_assert_cmpint (ext.height, >, 0);
@@ -115,7 +115,7 @@ test_line_height2 (void)
   layout = pango_layout_new (context);
   pango_layout_set_text (layout, "one", -1);
 
-  line = pango_lines_get_line (pango_layout_get_lines (layout), 0, NULL, NULL);
+  line = pango_lines_get_lines (pango_layout_get_lines (layout))[0];
   g_assert_nonnull (line);
   pango_line_get_extents (line, NULL, &ext1);
 
@@ -123,7 +123,7 @@ test_line_height2 (void)
 
   pango_layout_set_text (layout, "", -1);
 
-  line = pango_lines_get_line (pango_layout_get_lines (layout), 0, NULL, NULL);
+  line = pango_lines_get_lines (pango_layout_get_lines (layout))[0];
   g_assert_nonnull (line);
   pango_line_get_extents (line, NULL, &ext2);
 
@@ -153,14 +153,14 @@ test_line_height3 (void)
   pango_layout_set_attributes (layout, attrs);
   pango_attr_list_unref (attrs);
 
-  line = pango_lines_get_line (pango_layout_get_lines (layout), 0, NULL, NULL);
+  line = pango_lines_get_lines (pango_layout_get_lines (layout))[0];
   g_assert_cmpint (pango_lines_get_line_count (pango_layout_get_lines (layout)), ==, 1);
   pango_line_get_extents (line, NULL, &ext1);
 
   pango_layout_set_text (layout, "", -1);
 
   g_assert_cmpint (pango_lines_get_line_count (pango_layout_get_lines (layout)), ==, 1);
-  line = pango_lines_get_line (pango_layout_get_lines (layout), 0, NULL, NULL);
+  line = pango_lines_get_lines (pango_layout_get_lines (layout))[0];
   pango_line_get_extents (line, NULL, &ext2);
 
   g_assert_cmpint (ext1.height, ==, ext2.height);


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