From 89ced627cdd856837dd849c4032530d980bfa661 Mon Sep 17 00:00:00 2001 From: Bakkeby Date: Mon, 29 Aug 2022 09:50:47 +0200 Subject: [PATCH] font2: adding use XftFontMatch patch compatibility Also adding support for using size in addition to pixelsize when configuring fonts. Ref. https://github.com/bakkeby/dwm-flexipatch/issues/294 --- patch/font2.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/patch/font2.c b/patch/font2.c index 7477ced..9fc0e2d 100644 --- a/patch/font2.c +++ b/patch/font2.c @@ -4,7 +4,11 @@ xloadsparefont(FcPattern *pattern, int flags) FcPattern *match; FcResult result; + #if USE_XFTFONTMATCH_PATCH + match = XftFontMatch(xw.dpy, xw.scr, pattern, &result); + #else match = FcFontMatch(NULL, pattern, &result); + #endif // USE_XFTFONTMATCH_PATCH if (!match) { return 1; } @@ -26,7 +30,7 @@ void xloadsparefonts(void) { FcPattern *pattern; - double sizeshift, fontval; + double fontval; int fc; char **fp; @@ -54,22 +58,28 @@ xloadsparefonts(void) if (!pattern) die("can't open spare font %s\n", *fp); - if (defaultfontsize > 0) { - sizeshift = usedfontsize - defaultfontsize; - if (sizeshift != 0 && - FcPatternGetDouble(pattern, FC_PIXEL_SIZE, 0, &fontval) == + if (defaultfontsize > 0 && defaultfontsize != usedfontsize) { + if (FcPatternGetDouble(pattern, FC_PIXEL_SIZE, 0, &fontval) == FcResultMatch) { - fontval += sizeshift; + fontval *= usedfontsize / defaultfontsize; FcPatternDel(pattern, FC_PIXEL_SIZE); FcPatternDel(pattern, FC_SIZE); FcPatternAddDouble(pattern, FC_PIXEL_SIZE, fontval); + } else if (FcPatternGetDouble(pattern, FC_SIZE, 0, &fontval) == + FcResultMatch) { + fontval *= usedfontsize / defaultfontsize; + FcPatternDel(pattern, FC_PIXEL_SIZE); + FcPatternDel(pattern, FC_SIZE); + FcPatternAddDouble(pattern, FC_SIZE, fontval); } } FcPatternAddBool(pattern, FC_SCALABLE, 1); + #if !USE_XFTFONTMATCH_PATCH FcConfigSubstitute(NULL, pattern, FcMatchPattern); XftDefaultSubstitute(xw.dpy, xw.scr, pattern); + #endif // USE_XFTFONTMATCH_PATCH if (xloadsparefont(pattern, FRC_NORMAL)) die("can't open spare font %s\n", *fp);