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
This commit is contained in:
Bakkeby 2022-08-29 09:50:47 +02:00
parent 2906447fef
commit 89ced627cd

View File

@ -4,7 +4,11 @@ xloadsparefont(FcPattern *pattern, int flags)
FcPattern *match; FcPattern *match;
FcResult result; FcResult result;
#if USE_XFTFONTMATCH_PATCH
match = XftFontMatch(xw.dpy, xw.scr, pattern, &result);
#else
match = FcFontMatch(NULL, pattern, &result); match = FcFontMatch(NULL, pattern, &result);
#endif // USE_XFTFONTMATCH_PATCH
if (!match) { if (!match) {
return 1; return 1;
} }
@ -26,7 +30,7 @@ void
xloadsparefonts(void) xloadsparefonts(void)
{ {
FcPattern *pattern; FcPattern *pattern;
double sizeshift, fontval; double fontval;
int fc; int fc;
char **fp; char **fp;
@ -54,22 +58,28 @@ xloadsparefonts(void)
if (!pattern) if (!pattern)
die("can't open spare font %s\n", *fp); die("can't open spare font %s\n", *fp);
if (defaultfontsize > 0) { if (defaultfontsize > 0 && defaultfontsize != usedfontsize) {
sizeshift = usedfontsize - defaultfontsize; if (FcPatternGetDouble(pattern, FC_PIXEL_SIZE, 0, &fontval) ==
if (sizeshift != 0 &&
FcPatternGetDouble(pattern, FC_PIXEL_SIZE, 0, &fontval) ==
FcResultMatch) { FcResultMatch) {
fontval += sizeshift; fontval *= usedfontsize / defaultfontsize;
FcPatternDel(pattern, FC_PIXEL_SIZE); FcPatternDel(pattern, FC_PIXEL_SIZE);
FcPatternDel(pattern, FC_SIZE); FcPatternDel(pattern, FC_SIZE);
FcPatternAddDouble(pattern, FC_PIXEL_SIZE, fontval); 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); FcPatternAddBool(pattern, FC_SCALABLE, 1);
#if !USE_XFTFONTMATCH_PATCH
FcConfigSubstitute(NULL, pattern, FcMatchPattern); FcConfigSubstitute(NULL, pattern, FcMatchPattern);
XftDefaultSubstitute(xw.dpy, xw.scr, pattern); XftDefaultSubstitute(xw.dpy, xw.scr, pattern);
#endif // USE_XFTFONTMATCH_PATCH
if (xloadsparefont(pattern, FRC_NORMAL)) if (xloadsparefont(pattern, FRC_NORMAL))
die("can't open spare font %s\n", *fp); die("can't open spare font %s\n", *fp);