summaryrefslogtreecommitdiff
path: root/archive/st/patch/font2.c
diff options
context:
space:
mode:
authorauric <auric7@protonmail.com>2025-09-08 21:27:55 -0500
committerauric <auric7@protonmail.com>2025-09-08 21:27:55 -0500
commitde07b49b3249da05605f8c802b991a8588ab63b3 (patch)
tree295d6003f08dfce1d1b779892ce9c0be97d426a3 /archive/st/patch/font2.c
parent04cfeeb799b4ee6ac990e5d6e1b5302251133d77 (diff)
parente61da07522a060da98fa3a56db3d0360469b26cf (diff)
Resolved conflict, indulging new file layout
Diffstat (limited to 'archive/st/patch/font2.c')
-rw-r--r--archive/st/patch/font2.c104
1 files changed, 104 insertions, 0 deletions
diff --git a/archive/st/patch/font2.c b/archive/st/patch/font2.c
new file mode 100644
index 0000000..9fc0e2d
--- /dev/null
+++ b/archive/st/patch/font2.c
@@ -0,0 +1,104 @@
+int
+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;
+ }
+
+ if (!(frc[frclen].font = XftFontOpenPattern(xw.dpy, match))) {
+ FcPatternDestroy(match);
+ return 1;
+ }
+
+ frc[frclen].flags = flags;
+ /* Believe U+0000 glyph will present in each default font */
+ frc[frclen].unicodep = 0;
+ frclen++;
+
+ return 0;
+}
+
+void
+xloadsparefonts(void)
+{
+ FcPattern *pattern;
+ double fontval;
+ int fc;
+ char **fp;
+
+ if (frclen != 0)
+ die("can't embed spare fonts. cache isn't empty");
+
+ /* Calculate count of spare fonts */
+ fc = sizeof(font2) / sizeof(*font2);
+ if (fc == 0)
+ return;
+
+ /* Allocate memory for cache entries. */
+ if (frccap < 4 * fc) {
+ frccap += 4 * fc - frccap;
+ frc = xrealloc(frc, frccap * sizeof(Fontcache));
+ }
+
+ for (fp = font2; fp - font2 < fc; ++fp) {
+
+ if (**fp == '-')
+ pattern = XftXlfdParse(*fp, False, False);
+ else
+ pattern = FcNameParse((FcChar8 *)*fp);
+
+ if (!pattern)
+ die("can't open spare font %s\n", *fp);
+
+ if (defaultfontsize > 0 && defaultfontsize != usedfontsize) {
+ if (FcPatternGetDouble(pattern, FC_PIXEL_SIZE, 0, &fontval) ==
+ FcResultMatch) {
+ 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);
+
+ FcPatternDel(pattern, FC_SLANT);
+ FcPatternAddInteger(pattern, FC_SLANT, FC_SLANT_ITALIC);
+ if (xloadsparefont(pattern, FRC_ITALIC))
+ die("can't open spare font %s\n", *fp);
+
+ FcPatternDel(pattern, FC_WEIGHT);
+ FcPatternAddInteger(pattern, FC_WEIGHT, FC_WEIGHT_BOLD);
+ if (xloadsparefont(pattern, FRC_ITALICBOLD))
+ die("can't open spare font %s\n", *fp);
+
+ FcPatternDel(pattern, FC_SLANT);
+ FcPatternAddInteger(pattern, FC_SLANT, FC_SLANT_ROMAN);
+ if (xloadsparefont(pattern, FRC_BOLD))
+ die("can't open spare font %s\n", *fp);
+
+ FcPatternDestroy(pattern);
+ }
+} \ No newline at end of file