From 4397a1814fd1ecc998c0dcd542ae2fcc8da6827f Mon Sep 17 00:00:00 2001 From: ant Date: Sat, 4 Jan 2025 21:59:53 +0100 Subject: [PATCH] fontfeature patch --- hb.c | 13 +++++-------- hb.h | 4 ++++ patches.def.h | 6 +++++- x.c | 20 ++++++++++++++++++++ 4 files changed, 34 insertions(+), 9 deletions(-) diff --git a/hb.c b/hb.c index ae3dcc3..d2edd98 100644 --- a/hb.c +++ b/hb.c @@ -35,13 +35,6 @@ typedef struct { static RuneBuffer hbrunebuffer = { 0, NULL }; static hb_buffer_t *hbbuffer; -/* - * Poplulate the array with a list of font features, wrapped in FEATURE macro, - * e. g. - * FEATURE('c', 'a', 'l', 't'), FEATURE('d', 'l', 'i', 'g') - */ -hb_feature_t features[] = { }; - void hbcreatebuffer(void) { @@ -125,7 +118,11 @@ hbtransform(HbTransformData *data, XftFont *xfont, const Glyph *glyphs, int star hb_buffer_add_codepoints(buffer, hbrunebuffer.runes, length, 0, length); /* Shape the segment. */ - hb_shape(font, buffer, features, sizeof(features)/sizeof(hb_feature_t)); + #if FONTFEATURES_PATCH + hb_shape(font, buffer, data->features, data->features_count); + #else + hb_shape(font, buffer, NULL, 0); + #endif /* Get new glyph info. */ hb_glyph_info_t *info = hb_buffer_get_glyph_infos(buffer, &glyph_count); diff --git a/hb.h b/hb.h index cb7ea48..3517855 100644 --- a/hb.h +++ b/hb.h @@ -7,6 +7,10 @@ typedef struct { hb_glyph_info_t *glyphs; hb_glyph_position_t *positions; unsigned int count; +#if FONTFEATURES_PATCH + hb_feature_t *features; + int features_count; +#endif // FONTFEATURES_PATCH } HbTransformData; void hbcreatebuffer(void); diff --git a/patches.def.h b/patches.def.h index ae5d37b..dbfb2a0 100644 --- a/patches.def.h +++ b/patches.def.h @@ -233,7 +233,11 @@ * https://github.com/cog1to/st-ligatures * https://st.suckless.org/patches/ligatures/ */ -#define LIGATURES_PATCH 0 +#define LIGATURES_PATCH 1 + +/* This patch add support for custom font features. It depends on the LIGATURES_PATCH patch + */ +#define FONTFEATURES_PATCH 1 /* This patch makes st ignore terminal color attributes by forcing display of the default * foreground and background colors only - making for a monochrome look. Idea ref. diff --git a/x.c b/x.c index be1a6ba..a54304f 100644 --- a/x.c +++ b/x.c @@ -1724,6 +1724,26 @@ xmakeglyphfontspecs(XftGlyphFontSpec *specs, const Glyph *glyphs, int len, int x xp = winx, yp = winy + font->ascent; #endif // VERTCENTER_PATCH cluster_xp = xp; cluster_yp = yp; + #if FONTFEATURES_PATCH + { // Get font features + shaped.features = (hb_feature_t *) malloc(sizeof(hb_feature_t) * 128); + FcChar8 *s; + int feature_idx = 0; + while (FcPatternGetString(font->pattern, FC_FONT_FEATURES, feature_idx, &s) == FcResultMatch) { + if (strlen(s) != 4) + die("Invalid font feature tag"); + if (feature_idx >= 128) + die("Too many font features"); + shaped.features[feature_idx].tag = HB_TAG(s[0], s[1], s[2], s[3]); + shaped.features[feature_idx].value = 1; + shaped.features[feature_idx].start = HB_FEATURE_GLOBAL_START; + shaped.features[feature_idx].end = HB_FEATURE_GLOBAL_END; + feature_idx++; + } + shaped.features_count = feature_idx; + } + #endif // FONTFEATURES_PATCH + /* Shape the segment. */ hbtransform(&shaped, font->match, glyphs, 0, len); #endif // LIGATURES_PATCH