summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2021-11-06 20:46:48 -0400
committerMatthias Clasen <mclasen@redhat.com>2021-11-06 23:47:16 -0400
commit45a31546a009d423586e5fe80c19eb1add6e16dd (patch)
tree4a210e4b4d60e3befff6f70aca2a08c791904a5a
parent9d389e936707ebcf84fbc64d07b8aa17cdf2ef04 (diff)
downloadpango-45a31546a009d423586e5fe80c19eb1add6e16dd.tar.gz
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.
-rw-r--r--pango/pango-item-private.h5
-rw-r--r--pango/pango-item.c68
2 files changed, 73 insertions, 0 deletions
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)++;
+ }
+ }
+ }
+}