[pango/pango2: 27/301] Drop PangoItem hackery
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pango/pango2: 27/301] Drop PangoItem hackery
- Date: Wed, 22 Jun 2022 15:53:32 +0000 (UTC)
commit c56ea84ff66f42b0fa4353fe2cc850d6678ec8fb
Author: Matthias Clasen <mclasen redhat com>
Date: Tue Feb 8 15:33:52 2022 -0500
Drop PangoItem hackery
Drop the abi hacks for PangoItem and just
add the char_offset field. Same for the
size_font field in PangoAnalysis.
pango/glyphstring.c | 18 +++++++-------
pango/itemize.c | 4 +--
pango/pango-item-private.h | 61 ----------------------------------------------
pango/pango-item.c | 43 ++++++++++++--------------------
pango/pango-item.h | 9 +++----
pango/pango-layout.c | 21 +++-------------
tests/test-itemize.c | 5 +---
7 files changed, 35 insertions(+), 126 deletions(-)
---
diff --git a/pango/glyphstring.c b/pango/glyphstring.c
index ea9a63981..20ee58ce3 100644
--- a/pango/glyphstring.c
+++ b/pango/glyphstring.c
@@ -331,17 +331,17 @@ pango_glyph_string_get_width (PangoGlyphString *glyphs)
*/
void
pango_glyph_string_get_logical_widths (PangoGlyphString *glyphs,
- const char *text,
- int length,
- int embedding_level,
- int *logical_widths)
+ const char *text,
+ int length,
+ int embedding_level,
+ int *logical_widths)
{
/* Build a PangoGlyphItem and call the other API */
- PangoItem item = {0, length, pango_utf8_strlen (text, length),
- {NULL, NULL, NULL,
- embedding_level, PANGO_GRAVITY_AUTO, 0,
- PANGO_SCRIPT_UNKNOWN, NULL,
- NULL}};
+ PangoItem item = {0, length, pango_utf8_strlen (text, length), 0,
+ {NULL, NULL,
+ embedding_level, PANGO_GRAVITY_AUTO, 0,
+ PANGO_SCRIPT_UNKNOWN, NULL,
+ NULL}};
PangoGlyphItem glyph_item = {&item, glyphs};
pango_glyph_item_get_logical_widths (&glyph_item, text, logical_widths);
diff --git a/pango/itemize.c b/pango/itemize.c
index 728ad7d98..2f5376bff 100644
--- a/pango/itemize.c
+++ b/pango/itemize.c
@@ -1373,7 +1373,7 @@ split_item_for_variant (const char *text,
start = text + item->offset;
end = start + item->length;
- offset = ((PangoItemPrivate *)item)->char_offset;
+ offset = item->char_offset;
p = start;
while (p < end)
@@ -1511,7 +1511,7 @@ reorder_items (PangoContext *context,
/* Also cmpute the char offset for each item here */
for (GList *l = items; l; l = l->next)
{
- PangoItemPrivate *item = l->data;
+ PangoItem *item = l->data;
item->char_offset = char_offset;
char_offset += item->num_chars;
}
diff --git a/pango/pango-item-private.h b/pango/pango-item-private.h
index 9d2fa8057..dc2509827 100644
--- a/pango/pango-item-private.h
+++ b/pango/pango-item-private.h
@@ -26,67 +26,6 @@
G_BEGIN_DECLS
-/**
- * We have to do some extra work for adding the char_offset field
- * to PangoItem to preserve ABI in the face of pango's open-coded
- * structs.
- *
- * Internally, pango uses the PangoItemPrivate type, and we use
- * a bit in the PangoAnalysis flags to indicate whether we are
- * dealing with a PangoItemPrivate struct or not.
- */
-
-#define PANGO_ANALYSIS_FLAG_HAS_CHAR_OFFSET (1 << 7)
-
-typedef struct _PangoAnalysisPrivate PangoAnalysisPrivate;
-
-struct _PangoAnalysisPrivate
-{
- gpointer reserved;
- PangoFont *size_font;
- PangoFont *font;
-
- guint8 level;
- guint8 gravity;
- guint8 flags;
-
- guint8 script;
- PangoLanguage *language;
-
- GSList *extra_attrs;
-};
-
-typedef struct _PangoItemPrivate PangoItemPrivate;
-
-#if defined(__x86_64__) && !defined(__ILP32__)
-
-struct _PangoItemPrivate
-{
- int offset;
- int length;
- int num_chars;
- int char_offset;
- PangoAnalysis analysis;
-};
-
-#else
-
-struct _PangoItemPrivate
-{
- int offset;
- int length;
- int num_chars;
- PangoAnalysis analysis;
- int char_offset;
-};
-
-#endif
-
-G_STATIC_ASSERT (offsetof (PangoItem, offset) == offsetof (PangoItemPrivate, offset));
-G_STATIC_ASSERT (offsetof (PangoItem, length) == offsetof (PangoItemPrivate, length));
-G_STATIC_ASSERT (offsetof (PangoItem, num_chars) == offsetof (PangoItemPrivate, num_chars));
-G_STATIC_ASSERT (offsetof (PangoItem, analysis) == offsetof (PangoItemPrivate, analysis));
-
void pango_analysis_collect_features (const PangoAnalysis *analysis,
hb_feature_t *features,
guint length,
diff --git a/pango/pango-item.c b/pango/pango-item.c
index 944bfe2d7..131094e6a 100644
--- a/pango/pango-item.c
+++ b/pango/pango-item.c
@@ -35,9 +35,7 @@
PangoItem *
pango_item_new (void)
{
- PangoItemPrivate *result = g_slice_new0 (PangoItemPrivate);
-
- result->analysis.flags |= PANGO_ANALYSIS_FLAG_HAS_CHAR_OFFSET;
+ PangoItem *result = g_slice_new0 (PangoItem);
return (PangoItem *)result;
}
@@ -64,12 +62,11 @@ pango_item_copy (PangoItem *item)
result->offset = item->offset;
result->length = item->length;
result->num_chars = item->num_chars;
- if (item->analysis.flags & PANGO_ANALYSIS_FLAG_HAS_CHAR_OFFSET)
- ((PangoItemPrivate *)result)->char_offset = ((PangoItemPrivate *)item)->char_offset;
+ result->char_offset = item->char_offset;
result->analysis = item->analysis;
- if (result->analysis.lang_engine)
- g_object_ref (result->analysis.lang_engine);
+ if (result->analysis.size_font)
+ g_object_ref (result->analysis.size_font);
if (result->analysis.font)
g_object_ref (result->analysis.font);
@@ -105,16 +102,13 @@ pango_item_free (PangoItem *item)
g_slist_free (item->analysis.extra_attrs);
}
- if (item->analysis.lang_engine)
- g_object_unref (item->analysis.lang_engine);
+ if (item->analysis.size_font)
+ g_object_unref (item->analysis.size_font);
if (item->analysis.font)
g_object_unref (item->analysis.font);
- if (item->analysis.flags & PANGO_ANALYSIS_FLAG_HAS_CHAR_OFFSET)
- g_slice_free (PangoItemPrivate, (PangoItemPrivate *)item);
- else
- g_slice_free (PangoItem, item);
+ g_slice_free (PangoItem, item);
}
G_DEFINE_BOXED_TYPE (PangoItem, pango_item,
@@ -164,8 +158,7 @@ pango_item_split (PangoItem *orig,
orig->offset += split_index;
orig->length -= split_index;
orig->num_chars -= split_offset;
- if (orig->analysis.flags & PANGO_ANALYSIS_FLAG_HAS_CHAR_OFFSET)
- ((PangoItemPrivate *)orig)->char_offset += split_offset;
+ orig->char_offset += split_offset;
return new_item;
}
@@ -190,9 +183,7 @@ pango_item_unsplit (PangoItem *orig,
orig->offset -= split_index;
orig->length += split_index;
orig->num_chars += split_offset;
-
- if (orig->analysis.flags & PANGO_ANALYSIS_FLAG_HAS_CHAR_OFFSET)
- ((PangoItemPrivate *)orig)->char_offset -= split_offset;
+ orig->char_offset -= split_offset;
}
static int
@@ -346,13 +337,11 @@ void
pango_analysis_set_size_font (PangoAnalysis *analysis,
PangoFont *font)
{
- PangoAnalysisPrivate *priv = (PangoAnalysisPrivate *)analysis;
-
- if (priv->size_font)
- g_object_unref (priv->size_font);
- priv->size_font = font;
- if (priv->size_font)
- g_object_ref (priv->size_font);
+ if (analysis->size_font)
+ g_object_unref (analysis->size_font);
+ analysis->size_font = font;
+ if (analysis->size_font)
+ g_object_ref (analysis->size_font);
}
/*< private >
@@ -368,7 +357,5 @@ pango_analysis_set_size_font (PangoAnalysis *analysis,
PangoFont *
pango_analysis_get_size_font (const PangoAnalysis *analysis)
{
- PangoAnalysisPrivate *priv = (PangoAnalysisPrivate *)analysis;
-
- return priv->size_font;
+ return analysis->size_font;
}
diff --git a/pango/pango-item.h b/pango/pango-item.h
index a23af6659..a67434ade 100644
--- a/pango/pango-item.h
+++ b/pango/pango-item.h
@@ -61,9 +61,8 @@ typedef struct _PangoItem PangoItem;
/**
* PangoAnalysis:
- * @shape_engine: unused, reserved
- * @lang_engine: unused, reserved
- * @font: the font for this segment.
+ * @size_font: font to use for determining line height
+ * @font: the font for this segment
* @level: the bidirectional level for this segment.
* @gravity: the glyph orientation for this segment (A `PangoGravity`).
* @flags: boolean flags for this segment (Since: 1.16).
@@ -76,8 +75,7 @@ typedef struct _PangoItem PangoItem;
*/
struct _PangoAnalysis
{
- gpointer shape_engine;
- gpointer lang_engine;
+ PangoFont *size_font;
PangoFont *font;
guint8 level;
@@ -108,6 +106,7 @@ struct _PangoItem
int offset;
int length;
int num_chars;
+ int char_offset;
PangoAnalysis analysis;
};
diff --git a/pango/pango-layout.c b/pango/pango-layout.c
index e6be71435..664223976 100644
--- a/pango/pango-layout.c
+++ b/pango/pango-layout.c
@@ -1822,8 +1822,7 @@ pango_layout_line_index_to_x (PangoLayoutLine *line,
/* Note: we simply assert here, since our items are all internally
* created. If that ever changes, we need to add a fallback here.
*/
- g_assert (run->item->analysis.flags & PANGO_ANALYSIS_FLAG_HAS_CHAR_OFFSET);
- attr_offset = ((PangoItemPrivate *)run->item)->char_offset;
+ attr_offset = run->item->char_offset;
pango_glyph_string_index_to_x_full (run->glyphs,
layout->text + run->item->offset,
@@ -5426,11 +5425,7 @@ pango_layout_line_get_x_ranges (PangoLayoutLine *line,
run_end_index = g_utf8_prev_char (line->layout->text + run_end_index) - line->layout->text;
- /* Note: we simply assert here, since our items are all internally
- * created. If that ever changes, we need to add a fallback here.
- */
- g_assert (run->item->analysis.flags & PANGO_ANALYSIS_FLAG_HAS_CHAR_OFFSET);
- attr_offset = ((PangoItemPrivate *)run->item)->char_offset;
+ attr_offset = run->item->char_offset;
pango_glyph_string_index_to_x_full (run->glyphs,
line->layout->text + run->item->offset,
@@ -6373,11 +6368,7 @@ justify_clusters (PangoLayoutLine *line,
dir = run->item->analysis.level % 2 == 0 ? +1 : -1;
- /* Note: we simply assert here, since our items are all internally
- * created. If that ever changes, we need to add a fallback here.
- */
- g_assert (run->item->analysis.flags & PANGO_ANALYSIS_FLAG_HAS_CHAR_OFFSET);
- offset = ((PangoItemPrivate *)run->item)->char_offset;
+ offset = run->item->char_offset;
for (have_cluster = dir > 0 ?
pango_glyph_item_iter_init_start (&cluster_iter, run, text) :
@@ -6511,11 +6502,7 @@ justify_words (PangoLayoutLine *line,
gboolean have_cluster;
int offset;
- /* Note: we simply assert here, since our items are all internally
- * created. If that ever changes, we need to add a fallback here.
- */
- g_assert (run->item->analysis.flags & PANGO_ANALYSIS_FLAG_HAS_CHAR_OFFSET);
- offset = ((PangoItemPrivate *)run->item)->char_offset;
+ offset = run->item->char_offset;
for (have_cluster = pango_glyph_item_iter_init_start (&cluster_iter, run, text);
have_cluster;
diff --git a/tests/test-itemize.c b/tests/test-itemize.c
index e5775985c..a12bddd7f 100644
--- a/tests/test-itemize.c
+++ b/tests/test-itemize.c
@@ -112,10 +112,7 @@ apply_attributes_to_items (GList *items,
static int
get_item_char_offset (PangoItem *item)
{
- if (item->analysis.flags & PANGO_ANALYSIS_FLAG_HAS_CHAR_OFFSET)
- return ((PangoItemPrivate *)item)->char_offset;
-
- return -1;
+ return item->char_offset;
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]