Skip to content

Commit 3e0855f

Browse files
committed
Properly convert font_features to a list
1 parent 822c936 commit 3e0855f

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

kitty/fast_data_types.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ class FontConfigPattern(TypedDict):
410410
postscript_name: str
411411
style: str
412412
spacing: str
413-
fontfeatures: str
413+
fontfeatures: List[str]
414414
weight: int
415415
width: int
416416
slant: int

kitty/fontconfig.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,21 @@ pattern_as_dict(FcPattern *pat) {
3737
if (PyDict_SetItemString(ans, #name, p) != 0) { Py_CLEAR(p); Py_CLEAR(ans); return NULL; } \
3838
Py_CLEAR(p); \
3939
}}
40+
41+
#define L(type, get, which, conv, name) { \
42+
type out; PyObject *p; int n = 0; \
43+
PyObject *l = PyList_New(0); \
44+
while (get(pat, which, n, &out) == FcResultMatch) { \
45+
p = conv(out); if (p == NULL) { Py_CLEAR(l); Py_CLEAR(ans); return NULL; } \
46+
if (PyList_Append(l, p) != 0) { Py_CLEAR(p); Py_CLEAR(l); Py_CLEAR(ans); return NULL; } \
47+
Py_CLEAR(p); \
48+
n++; \
49+
} \
50+
if (PyDict_SetItemString(ans, #name, l) != 0) { Py_CLEAR(l); Py_CLEAR(ans); return NULL; } \
51+
Py_CLEAR(l); \
52+
}
4053
#define S(which, key) G(FcChar8*, FcPatternGetString, which, PS, key)
54+
#define LS(which, key) L(FcChar8*, FcPatternGetString, which, PS, key)
4155
#define I(which, key) G(int, FcPatternGetInteger, which, PyLong_FromLong, key)
4256
#define B(which, key) G(int, FcPatternGetBool, which, pybool, key)
4357
#define E(which, key, conv) G(int, FcPatternGetInteger, which, conv, key)
@@ -46,7 +60,7 @@ pattern_as_dict(FcPattern *pat) {
4660
S(FC_STYLE, style);
4761
S(FC_FULLNAME, full_name);
4862
S(FC_POSTSCRIPT_NAME, postscript_name);
49-
S(FC_FONT_FEATURES, fontfeatures);
63+
LS(FC_FONT_FEATURES, fontfeatures);
5064
I(FC_WEIGHT, weight);
5165
I(FC_WIDTH, width)
5266
I(FC_SLANT, slant);

kitty/fonts/fontconfig.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def find_font_features(postscript_name: str) -> Tuple[str, ...]:
7878
return tuple()
7979

8080
features = []
81-
for feat in pat['fontfeatures'].split():
81+
for feat in pat['fontfeatures']:
8282
try:
8383
parsed = parse_font_feature(feat)
8484
except ValueError:

0 commit comments

Comments
 (0)