diff options
author | Matthias Clasen <mclasen@redhat.com> | 2021-11-08 13:47:52 +0000 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2021-11-08 13:47:52 +0000 |
commit | 78d4efd6af8fc37b93b1dafb7c3b7101b389a565 (patch) | |
tree | 857deeac1c70f10038c2e967d0238f1845964533 /pango/pango-item.c | |
parent | 9d389e936707ebcf84fbc64d07b8aa17cdf2ef04 (diff) | |
parent | 1790dbf9da8a4249528833ead1af32d232861b64 (diff) | |
download | pango-78d4efd6af8fc37b93b1dafb7c3b7101b389a565.tar.gz |
Merge branch 'small-caps' into 'main'
Emulate Small Caps if not available from the font
See merge request GNOME/pango!497
Diffstat (limited to 'pango/pango-item.c')
-rw-r--r-- | pango/pango-item.c | 68 |
1 files changed, 68 insertions, 0 deletions
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)++; + } + } + } +} |