[pango/line-breaker: 32/32] Make PangoLayoutRun a separate type




commit 8381876871c58da108570468e6b83364f604630d
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Jan 23 21:06:55 2022 -0500

    Make PangoLayoutRun a separate type
    
    It is nicer to have an opaque type for
    the iter, and only use PangoGlyphItem
    in the implementation.

 pango/pango-layout-run-private.h |  6 +++++-
 pango/pango-layout-run.c         |  6 +++---
 pango/pango-types.h              |  2 +-
 tests/testiter.c                 | 27 +++++++++++++----------
 utils/viewer-pangocairo.c        | 46 ++++++++++++++++++++++++----------------
 5 files changed, 53 insertions(+), 34 deletions(-)
---
diff --git a/pango/pango-layout-run-private.h b/pango/pango-layout-run-private.h
index 4d315da7..ce3b2bc8 100644
--- a/pango/pango-layout-run-private.h
+++ b/pango/pango-layout-run-private.h
@@ -6,9 +6,13 @@
 #include "pango-glyph-item.h"
 #include "pango-item-private.h"
 
+struct _PangoLayoutRun
+{
+  PangoGlyphItem glyph_item;
+};
 
 static inline PangoGlyphItem *
 pango_layout_run_get_glyph_item (PangoLayoutRun *run)
 {
-  return (PangoGlyphItem *)run;
+  return &run->glyph_item;
 }
diff --git a/pango/pango-layout-run.c b/pango/pango-layout-run.c
index 63965842..90edb3f0 100644
--- a/pango/pango-layout-run.c
+++ b/pango/pango-layout-run.c
@@ -9,13 +9,13 @@
 PangoItem *
 pango_layout_run_get_item (PangoLayoutRun *run)
 {
-  return run->item;
+  return run->glyph_item.item;
 }
 
 PangoGlyphString *
 pango_layout_run_get_glyphs (PangoLayoutRun *run)
 {
-  return run->glyphs;
+  return run->glyph_item.glyphs;
 }
 
 /**
@@ -40,7 +40,7 @@ pango_layout_run_get_extents (PangoLayoutRun   *run,
                               PangoRectangle   *ink_rect,
                               PangoRectangle   *logical_rect)
 {
-  PangoGlyphItem *glyph_item = run;
+  PangoGlyphItem *glyph_item = &run->glyph_item;
   ItemProperties properties;
   gboolean has_underline;
   gboolean has_overline;
diff --git a/pango/pango-types.h b/pango/pango-types.h
index 5d9f59bb..3a645e5f 100644
--- a/pango/pango-types.h
+++ b/pango/pango-types.h
@@ -55,7 +55,7 @@ typedef guint32 PangoGlyph;
 
 typedef struct _PangoLine PangoLine;
 typedef struct _PangoLines PangoLines;
-typedef struct _PangoGlyphItem PangoLayoutRun;
+typedef struct _PangoLayoutRun PangoLayoutRun;
 typedef struct _PangoLayoutIter PangoLayoutIter;
 
 /**
diff --git a/tests/testiter.c b/tests/testiter.c
index 7327e1df..5ac2f7c9 100644
--- a/tests/testiter.c
+++ b/tests/testiter.c
@@ -81,7 +81,7 @@ iter_char_test (PangoLayout *layout)
 {
   PangoRectangle   extents, run_extents;
   PangoLayoutIter *iter;
-  PangoGlyphItem  *run;
+  PangoLayoutRun  *run;
   int              num_chars;
   int              i, index, offset;
   int              leading_x, trailing_x, x0, x1;
@@ -117,26 +117,31 @@ iter_char_test (PangoLayout *layout)
         {
           PangoFontDescription *desc;
           char *str;
+          PangoItem *item;
+          PangoGlyphString *glyphs;
+
+          item = pango_layout_run_get_item (run);
+          glyphs = pango_layout_run_get_glyphs (run);
 
           /* Get needed data for the GlyphString */
           pango_layout_iter_get_run_extents (iter, NULL, &run_extents);
-          offset = run->item->offset;
-          rtl = run->item->analysis.level%2;
-          desc = pango_font_describe (run->item->analysis.font);
+          offset = item->offset;
+          rtl = item->analysis.level%2;
+          desc = pango_font_describe (item->analysis.font);
           str = pango_font_description_to_string (desc);
           verbose ("  (current run: font=%s,offset=%d,x=%d,len=%d,rtl=%d)\n",
-                   str, offset, run_extents.x, run->item->length, rtl);
+                   str, offset, run_extents.x, item->length, rtl);
           g_free (str);
           pango_font_description_free (desc);
 
           /* Calculate expected x result using index_to_x */
-          pango_glyph_string_index_to_x (run->glyphs,
-                                         (char *)(text + offset), run->item->length,
-                                         &run->item->analysis,
+          pango_glyph_string_index_to_x (glyphs,
+                                         (char *)(text + offset), item->length,
+                                         &item->analysis,
                                          index - offset, FALSE, &leading_x);
-          pango_glyph_string_index_to_x (run->glyphs,
-                                         (char *)(text + offset), run->item->length,
-                                         &run->item->analysis,
+          pango_glyph_string_index_to_x (glyphs,
+                                         (char *)(text + offset), item->length,
+                                         &item->analysis,
                                          index - offset, TRUE, &trailing_x);
 
           x0 = run_extents.x + MIN (leading_x, trailing_x);
diff --git a/utils/viewer-pangocairo.c b/utils/viewer-pangocairo.c
index 1ae751ee..0e4d8e37 100644
--- a/utils/viewer-pangocairo.c
+++ b/utils/viewer-pangocairo.c
@@ -367,7 +367,7 @@ render_callback (PangoLayout *layout,
           iter = pango_lines_get_iter (pango_layout_get_lines (layout));
           do
             {
-              PangoGlyphItem *run;
+              PangoLayoutRun *run;
               PangoRectangle rect;
 
               run = pango_layout_iter_get_run (iter);
@@ -444,7 +444,9 @@ render_callback (PangoLayout *layout,
           iter = pango_lines_get_iter (pango_layout_get_lines (layout));
           do
             {
-              PangoGlyphItem *run;
+              PangoLayoutRun *run;
+              PangoItem *item;
+              PangoGlyphString *glyphs;
               PangoRectangle rect;
               int x_pos, y_pos;
 
@@ -452,21 +454,24 @@ render_callback (PangoLayout *layout,
               if (!run)
                 continue;
 
+              item = pango_layout_run_get_item (run);
+              glyphs = pango_layout_run_get_glyphs (run);
+
               pango_layout_iter_get_run_extents (iter, NULL, &rect);
 
               x_pos = rect.x;
               y_pos = pango_layout_iter_get_run_baseline (iter);
 
-              for (int i = 0; i < run->glyphs->num_glyphs; i++)
+              for (int i = 0; i < glyphs->num_glyphs; i++)
                 {
                   PangoRectangle extents;
 
-                  pango_font_get_glyph_extents (run->item->analysis.font,
-                                                run->glyphs->glyphs[i].glyph,
+                  pango_font_get_glyph_extents (item->analysis.font,
+                                                glyphs->glyphs[i].glyph,
                                                 &extents, NULL);
 
-                  rect.x = x_pos + run->glyphs->glyphs[i].geometry.x_offset + extents.x;
-                  rect.y = y_pos + run->glyphs->glyphs[i].geometry.y_offset + extents.y;
+                  rect.x = x_pos + glyphs->glyphs[i].geometry.x_offset + extents.x;
+                  rect.y = y_pos + glyphs->glyphs[i].geometry.y_offset + extents.y;
                   rect.width = extents.width;
                   rect.height = extents.height;
 
@@ -478,12 +483,12 @@ render_callback (PangoLayout *layout,
                   cairo_stroke (cr);
 
                   cairo_arc (cr,
-                             (double) (x_pos + run->glyphs->glyphs[i].geometry.x_offset) / PANGO_SCALE,
-                             (double) (y_pos + run->glyphs->glyphs[i].geometry.y_offset) / PANGO_SCALE,
+                             (double) (x_pos + glyphs->glyphs[i].geometry.x_offset) / PANGO_SCALE,
+                             (double) (y_pos + glyphs->glyphs[i].geometry.y_offset) / PANGO_SCALE,
                              3.0, 0, 2*G_PI);
                   cairo_fill (cr);
 
-                  x_pos += run->glyphs->glyphs[i].geometry.width;
+                  x_pos += glyphs->glyphs[i].geometry.width;
                 }
             }
           while (pango_layout_iter_next_run (iter));
@@ -508,7 +513,9 @@ render_callback (PangoLayout *layout,
           do
             {
               PangoRectangle rect;
-              PangoGlyphItem *run;
+              PangoLayoutRun *run;
+              PangoItem *item;
+              PangoGlyphString *glyphs;
               const char *text, *start, *p;
               int x, y;
               gboolean trailing;
@@ -519,8 +526,11 @@ render_callback (PangoLayout *layout,
               if (!run)
                 continue;
 
+              item = pango_layout_run_get_item (run);
+              glyphs = pango_layout_run_get_glyphs (run);
+
               text = pango_layout_get_text (layout);
-              start = text + run->item->offset;
+              start = text + item->offset;
 
               offset = g_utf8_strlen (text, start - text);
 
@@ -528,14 +538,14 @@ render_callback (PangoLayout *layout,
 
               trailing = FALSE;
               p = start;
-              for (int i = 0; i <= run->item->num_chars; i++)
+              for (int i = 0; i <= item->num_chars; i++)
                 {
                   if (attrs[offset + i].is_cursor_position)
                     {
-                      pango_glyph_string_index_to_x_full (run->glyphs,
-                                                          text + run->item->offset,
-                                                          run->item->length,
-                                                          &run->item->analysis,
+                      pango_glyph_string_index_to_x_full (glyphs,
+                                                          text + item->offset,
+                                                          item->length,
+                                                          &item->analysis,
                                                           (PangoLogAttr *)attrs + offset,
                                                           p - start,
                                                           trailing,
@@ -554,7 +564,7 @@ render_callback (PangoLayout *layout,
                       g_free (s);
                    }
 
-                  if (i < run->item->num_chars)
+                  if (i < item->num_chars)
                     {
                       num++;
                       p = g_utf8_next_char (p);


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