summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2022-01-23 21:06:55 -0500
committerMatthias Clasen <mclasen@redhat.com>2022-01-25 15:29:16 -0500
commitd2602cc0ee6a0b7abb982e27ccf90b0da98ebedf (patch)
tree883cdb2cb8533cd08368decda9680f4f3e698a02
parent45762d6b50b29447ee97c759c7a7cc55cb534703 (diff)
downloadpango-d2602cc0ee6a0b7abb982e27ccf90b0da98ebedf.tar.gz
Make PangoLayoutRun a separate type
It is nicer to have an opaque type for the iter, and only use PangoGlyphItem in the implementation.
-rw-r--r--pango/pango-layout-run-private.h6
-rw-r--r--pango/pango-layout-run.c6
-rw-r--r--pango/pango-types.h2
-rw-r--r--tests/testiter.c27
-rw-r--r--utils/viewer-pangocairo.c46
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 69913b31..9643245e 100644
--- a/pango/pango-types.h
+++ b/pango/pango-types.h
@@ -54,7 +54,7 @@ typedef struct _PangoLanguage PangoLanguage;
typedef guint32 PangoGlyph;
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 c2f988fc..9ac54467 100644
--- a/utils/viewer-pangocairo.c
+++ b/utils/viewer-pangocairo.c
@@ -367,7 +367,7 @@ render_callback (PangoLayout *layout,
iter = pango_layout_get_iter (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_layout_get_iter (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);