From 6bf290149e1bd3c20a19ed83a8f3c66794788b3c Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 24 Oct 2018 06:45:06 +0530 Subject: [PATCH] Allow specifying monospace when calling fc_match --- kitty/fontconfig.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/kitty/fontconfig.c b/kitty/fontconfig.c index 9123de462..5bd1a09d7 100644 --- a/kitty/fontconfig.c +++ b/kitty/fontconfig.c @@ -114,6 +114,7 @@ _fc_match(FcPattern *pat) { FcResult result; FcConfigSubstitute(NULL, pat, FcMatchPattern); FcDefaultSubstitute(pat); + /* printf("fc_match = %s\n", FcNameUnparse(pat)); */ match = FcFontMatch(NULL, pat, &result); if (match == NULL) { PyErr_SetString(PyExc_KeyError, "FcFontMatch() failed"); goto end; } ans = pattern_as_dict(match); @@ -145,16 +146,22 @@ end: static PyObject* fc_match(PyObject UNUSED *self, PyObject *args) { char *family = NULL; - int bold = 0, italic = 0, allow_bitmapped_fonts = 0; + int bold = 0, italic = 0, allow_bitmapped_fonts = 0, monospaced = 0; double size_in_pts = 0, dpi = 0; FcPattern *pat = NULL; PyObject *ans = NULL; - if (!PyArg_ParseTuple(args, "|zpppdd", &family, &bold, &italic, &allow_bitmapped_fonts, &size_in_pts, &dpi)) return NULL; + if (!PyArg_ParseTuple(args, "|zppppdd", &family, &bold, &italic, &monospaced, &allow_bitmapped_fonts, &size_in_pts, &dpi)) return NULL; pat = FcPatternCreate(); if (pat == NULL) return PyErr_NoMemory(); if (family && strlen(family) > 0) AP(FcPatternAddString, FC_FAMILY, (const FcChar8*)family, "family"); + if (monospaced) { + // pass the family,monospace as the family parameter to fc-match, + // which will fallback to using monospace if the family does not match. + AP(FcPatternAddString, FC_FAMILY, (const FcChar8*)"monospace", "family"); + AP(FcPatternAddInteger, FC_SPACING, FC_MONO, "spacing"); + } if (!allow_bitmapped_fonts) { AP(FcPatternAddBool, FC_OUTLINE, true, "outline"); AP(FcPatternAddBool, FC_SCALABLE, true, "scalable");