]> git.ekhem.eu.org Git - st.git/commitdiff
Patch font2
authorJakub Czajka <jakub@ekhem.eu.org>
Sat, 25 Dec 2021 16:26:46 +0000 (17:26 +0100)
committerJakub Czajka <jakub@ekhem.eu.org>
Sat, 14 Oct 2023 20:54:24 +0000 (22:54 +0200)
config.def.h
config.h
x.c

index 57d98da5c6bb6167934bffd9312701b76c3a18b9..09a05ea8e1d55fb0933217a9fe7c6fa914c49e1a 100644 (file)
@@ -6,6 +6,11 @@
  * font: see http://freedesktop.org/software/fontconfig/fontconfig-user.html
  */
 static char *font = "Liberation Mono:pixelsize=12:antialias=true:autohint=true";
++/* Spare fonts */
++static char *font2[] = {
++        "Noto Emoji:pixelsize=12:antialias=true:autohint=true",
++};
+
 static int borderpx = 2;
 
 /*
index 2475bcf8fdc8502fb8fb94edb101f22656a01016..53d34aa49895923721540906b24ed753f50383b5 100644 (file)
--- a/config.h
+++ b/config.h
@@ -6,6 +6,11 @@
  * font: see http://freedesktop.org/software/fontconfig/fontconfig-user.html
  */
 static char *font = "Liberation Mono:pixelsize=12:antialias=true:autohint=true";
+/* Spare fonts */
+static char *font2[] = {
+        "Noto Emoji:pixelsize=12:antialias=true:autohint=true",
+};
+
 static int borderpx = 2;
 
 /*
diff --git a/x.c b/x.c
index 09ed2cb30e131cdf45e3e94e4ebcfa040dce1d9f..1e490eb8260d761cf86c63f4826d176cb936c483 100644 (file)
--- a/x.c
+++ b/x.c
@@ -172,6 +172,8 @@ static void xhints(void);
 static int xloadcolor(int, const char *, Color *);
 static int xloadfont(Font *, FcPattern *);
 static void xloadfonts(const char *, double);
+static int xloadsparefont(FcPattern *, int);
+static void xloadsparefonts(void);
 static void xunloadfont(Font *);
 static void xunloadfonts(void);
 static void xsetenv(void);
@@ -325,6 +327,7 @@ zoomabs(const Arg *arg)
 {
        xunloadfonts();
        xloadfonts(usedfont, arg->f);
+       xloadsparefonts();
        cresize(0, 0);
        redraw();
        xhints();
@@ -1079,6 +1082,101 @@ xloadfonts(const char *fontstr, double fontsize)
        FcPatternDestroy(pattern);
 }
 
+int
+xloadsparefont(FcPattern *pattern, int flags)
+{
+       FcPattern *match;
+       FcResult result;
+
+       match = FcFontMatch(NULL, pattern, &result);
+       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 sizeshift, 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) {
+                       sizeshift = usedfontsize - defaultfontsize;
+                       if (sizeshift != 0 &&
+                                       FcPatternGetDouble(pattern, FC_PIXEL_SIZE, 0, &fontval) ==
+                                       FcResultMatch) {
+                               fontval += sizeshift;
+                               FcPatternDel(pattern, FC_PIXEL_SIZE);
+                               FcPatternDel(pattern, FC_SIZE);
+                               FcPatternAddDouble(pattern, FC_PIXEL_SIZE, fontval);
+                       }
+               }
+
+               FcPatternAddBool(pattern, FC_SCALABLE, 1);
+
+               FcConfigSubstitute(NULL, pattern, FcMatchPattern);
+               XftDefaultSubstitute(xw.dpy, xw.scr, pattern);
+
+               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);
+       }
+}
+
 void
 xunloadfont(Font *f)
 {
@@ -1187,6 +1285,9 @@ xinit(int cols, int rows)
        usedfont = (opt_font == NULL)? font : opt_font;
        xloadfonts(usedfont, 0);
 
+       /* spare fonts */
+       xloadsparefonts();
+
        /* colors */
        xw.cmap = XCreateColormap(xw.dpy, parent, xw.vis, None);
        xloadcols();