diff options
author | Matthias Clasen <mclasen@redhat.com> | 2022-01-15 17:18:17 -0500 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2022-01-24 07:46:42 -0500 |
commit | 8277d6c8789f6902149a373097dd7c9248386438 (patch) | |
tree | 28878813b2d557546b379cffab31e158222c3ed4 | |
parent | 3eba288ec502e3711ad1aef92fb149d1707e4900 (diff) | |
download | pango-8277d6c8789f6902149a373097dd7c9248386438.tar.gz |
Move ItemProperties
This will be used in multiple places going forward,
so move it to pango-item.c
-rw-r--r-- | pango/pango-item-private.h | 21 | ||||
-rw-r--r-- | pango/pango-item.c | 107 | ||||
-rw-r--r-- | 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 9d2fa805..db0e7932 100644 --- a/pango/pango-item-private.h +++ b/pango/pango-item-private.h @@ -115,6 +115,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 944bfe2d..cd046199 100644 --- a/pango/pango-item.c +++ b/pango/pango-item.c @@ -372,3 +372,110 @@ pango_analysis_get_size_font (const PangoAnalysis *analysis) return priv->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 d0cf62ea..4444bfd0 100644 --- a/pango/pango-layout.c +++ b/pango/pango-layout.c @@ -91,35 +91,9 @@ #include "pango-font-private.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, @@ -4040,7 +4011,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; @@ -5616,7 +5587,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; @@ -6094,7 +6065,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; } @@ -6783,103 +6754,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) |