[pango/small-caps: 1/11] pango-item: Add a helper
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pango/small-caps: 1/11] pango-item: Add a helper
- Date: Sun, 7 Nov 2021 03:56:15 +0000 (UTC)
commit 45a31546a009d423586e5fe80c19eb1add6e16dd
Author: Matthias Clasen <mclasen redhat com>
Date: Sat Nov 6 20:46:48 2021 -0400
pango-item: Add a helper
Add a helper function that used to live with the Harfbuzz
shaping code in shape.c. It will be used in the itemize code
too, in the future.
pango/pango-item-private.h | 5 ++++
pango/pango-item.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 73 insertions(+)
---
diff --git a/pango/pango-item-private.h b/pango/pango-item-private.h
index 8680fa4b..dd3f89fc 100644
--- a/pango/pango-item-private.h
+++ b/pango/pango-item-private.h
@@ -68,6 +68,11 @@ G_STATIC_ASSERT (offsetof (PangoItem, length) == offsetof (PangoItemPrivate, len
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,
+ guint *num_features);
+
G_END_DECLS
#endif /* __PANGO_ITEM_PRIVATE_H__ */
diff --git a/pango/pango-item.c b/pango/pango-item.c
index 484d5f1f..4b02c277 100644
--- a/pango/pango-item.c
+++ b/pango/pango-item.c
@@ -231,3 +231,71 @@ pango_item_apply_attrs (PangoItem *item,
item->analysis.extra_attrs = g_slist_concat (item->analysis.extra_attrs, attrs);
}
+
+void
+pango_analysis_collect_features (const PangoAnalysis *analysis,
+ hb_feature_t *features,
+ guint length,
+ guint *num_features)
+{
+ GSList *l;
+
+ pango_font_get_features (analysis->font, features, length, num_features);
+
+ for (l = analysis->extra_attrs; l && *num_features < length; l = l->next)
+ {
+ PangoAttribute *attr = l->data;
+ if (attr->klass->type == PANGO_ATTR_FONT_FEATURES)
+ {
+ PangoAttrFontFeatures *fattr = (PangoAttrFontFeatures *) attr;
+ const gchar *feat;
+ const gchar *end;
+ int len;
+
+ feat = fattr->features;
+
+ while (feat != NULL && *num_features < length)
+ {
+ end = strchr (feat, ',');
+ if (end)
+ len = end - feat;
+ else
+ len = -1;
+ if (hb_feature_from_string (feat, len, &features[*num_features]))
+ {
+ features[*num_features].start = attr->start_index;
+ features[*num_features].end = attr->end_index;
+ (*num_features)++;
+ }
+
+ if (end == NULL)
+ break;
+
+ feat = end + 1;
+ }
+ }
+ }
+
+ /* Turn off ligatures when letterspacing */
+ for (l = analysis->extra_attrs; l && *num_features < length; l = l->next)
+ {
+ PangoAttribute *attr = l->data;
+ if (attr->klass->type == PANGO_ATTR_LETTER_SPACING)
+ {
+ hb_tag_t tags[] = {
+ HB_TAG('l','i','g','a'),
+ HB_TAG('c','l','i','g'),
+ HB_TAG('d','l','i','g'),
+ };
+ int i;
+ for (i = 0; i < G_N_ELEMENTS (tags); i++)
+ {
+ features[*num_features].tag = tags[i];
+ features[*num_features].value = 0;
+ features[*num_features].start = attr->start_index;
+ features[*num_features].end = attr->end_index;
+ (*num_features)++;
+ }
+ }
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]