commit 3cf728e1d0397620117800271f99ccd611ba7310
Author: Kirill Bugaev <kirill.bugaev87_AT_gmail.com>
Date: Tue Apr 16 05:57:57 2019 +0800
New version of font2 patch for st added.
diff --git a/st.suckless.org/patches/font2/index.md b/st.suckless.org/patches/font2/index.md
index acb4f59f..95c88dd3 100644
--- a/st.suckless.org/patches/font2/index.md
+++ b/st.suckless.org/patches/font2/index.md
_AT_@ -5,13 +5,36 @@ Description
-----------
This patch allows to add spare font besides default. Some glyphs can be
not present in default font. For this glyphs st uses font-config and try
-to find them in font cache first. This patch append font defined in
-`font2` variable to the beginning of font cache.
+to find them in font cache first. This patch append fonts defined in
+`font2` variable to the beginning of font cache. So they will be used
+first for glyphs that absent in default font.
+
+Example
+-------------
+`static char *font = "Bitstream Vera Sans Mono:pixelsize=11:antialias=true:autohint=true";`
+without patch.
+
+[![Screenshot1](st-font2-wopatch1.png)](st-font2-wopatch1.png)
+[![Screenshot2](st-font2-wopatch2.png)](st-font2-wopatch2.png)
+
+
+`static char *font2[] = {
+ "Inconsolata for Powerline:pixelsize=12:antialias=true:autohint=true"
+};`
+[![Screenshot3](st-font2-wpatch1.png)](st-font2-wpatch1.png)
+[![Screenshot4](st-font2-wpatch2.png)](st-font2-wpatch2.png)
Download
--------
* [st-font2-20190326-f64c2f8.diff](st-font2-20190326-f64c2f8.diff)
+* [st-font2-20190416-ba72400.diff](st-font2-20190416-ba72400.diff)
+
+Changelog
+---------
+* multiple fonts support
+* size of spare fonts changes according to size of default font
+* fonts loading procedure fixed
-Authors
+Author
-------
* Kirill Bugaev <kirill.bugaev87_AT_gmail.com>
diff --git a/st.suckless.org/patches/font2/st-font2-20190416-ba72400.diff b/st.suckless.org/patches/font2/st-font2-20190416-ba72400.diff
new file mode 100644
index 00000000..c7a2950c
--- /dev/null
+++ b/st.suckless.org/patches/font2/st-font2-20190416-ba72400.diff
_AT_@ -0,0 +1,167 @@
+From ba724004c6a368e452114f7dc147a9978fe0f3b4 Mon Sep 17 00:00:00 2001
+From: Kirill Bugaev <kirill.bugaev87_AT_gmail.com>
+Date: Tue, 16 Apr 2019 04:31:30 +0800
+Subject: [PATCH] This patch allows to add spare font besides default. Some
+ glyphs can be not present in default font. For this glyphs st uses
+ font-config and try to find them in font cache first. This patch append fonts
+ defined in font2 variable to the beginning of font cache. So they will be
+ used first for glyphs that absent in default font.
+
+---
+ config.def.h | 6 +++
+ x.c | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++
+ 2 files changed, 107 insertions(+)
+
+diff --git a/config.def.h b/config.def.h
+index 482901e..676719e 100644
+--- a/config.def.h
++++ b/config.def.h
+_AT_@ -6,6 +6,12 @@
+ * 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[] = {
++/* "Inconsolata for Powerline:pixelsize=12:antialias=true:autohint=true", */
++/* "Hack Nerd Font Mono:pixelsize=11:antialias=true:autohint=true", */
++};
++
+ static int borderpx = 2;
+
+ /*
+diff --git a/x.c b/x.c
+index 5828a3b..d37e59d 100644
+--- a/x.c
++++ b/x.c
+_AT_@ -149,6 +149,8 @@ static void xhints(void);
+ static int xloadcolor(int, const char *, Color *);
+ static int xloadfont(Font *, FcPattern *);
+ static void xloadfonts(char *, double);
++static int xloadsparefont(FcPattern *, int);
++static void xloadsparefonts(void);
+ static void xunloadfont(Font *);
+ static void xunloadfonts(void);
+ static void xsetenv(void);
+_AT_@ -296,6 +298,7 @@ zoomabs(const Arg *arg)
+ {
+ xunloadfonts();
+ xloadfonts(usedfont, arg->f);
++ xloadsparefonts();
+ cresize(0, 0);
+ redraw();
+ xhints();
+_AT_@ -977,6 +980,101 @@ xloadfonts(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
", *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
", *fp);
++
++ FcPatternDel(pattern, FC_SLANT);
++ FcPatternAddInteger(pattern, FC_SLANT, FC_SLANT_ITALIC);
++ if (xloadsparefont(pattern, FRC_ITALIC))
++ die("can't open spare font %s
", *fp);
++
++ FcPatternDel(pattern, FC_WEIGHT);
++ FcPatternAddInteger(pattern, FC_WEIGHT, FC_WEIGHT_BOLD);
++ if (xloadsparefont(pattern, FRC_ITALICBOLD))
++ die("can't open spare font %s
", *fp);
++
++ FcPatternDel(pattern, FC_SLANT);
++ FcPatternAddInteger(pattern, FC_SLANT, FC_SLANT_ROMAN);
++ if (xloadsparefont(pattern, FRC_BOLD))
++ die("can't open spare font %s
", *fp);
++
++ FcPatternDestroy(pattern);
++ }
++}
++
+ void
+ xunloadfont(Font *f)
+ {
+_AT_@ -1057,6 +1155,9 @@ xinit(int cols, int rows)
+ usedfont = (opt_font == NULL)? font : opt_font;
+ xloadfonts(usedfont, 0);
+
++ /* spare fonts */
++ xloadsparefonts();
++
+ /* colors */
+ xw.cmap = XDefaultColormap(xw.dpy, xw.scr);
+ xloadcols();
+--
+2.21.0
+
diff --git a/st.suckless.org/patches/font2/st-font2-wopatch1.png b/st.suckless.org/patches/font2/st-font2-wopatch1.png
new file mode 100644
index 00000000..7a912eef
Binary files /dev/null and b/st.suckless.org/patches/font2/st-font2-wopatch1.png differ
diff --git a/st.suckless.org/patches/font2/st-font2-wopatch2.png b/st.suckless.org/patches/font2/st-font2-wopatch2.png
new file mode 100644
index 00000000..54087e76
Binary files /dev/null and b/st.suckless.org/patches/font2/st-font2-wopatch2.png differ
diff --git a/st.suckless.org/patches/font2/st-font2-wpatch1.png b/st.suckless.org/patches/font2/st-font2-wpatch1.png
new file mode 100644
index 00000000..6108462c
Binary files /dev/null and b/st.suckless.org/patches/font2/st-font2-wpatch1.png differ
diff --git a/st.suckless.org/patches/font2/st-font2-wpatch2.png b/st.suckless.org/patches/font2/st-font2-wpatch2.png
new file mode 100644
index 00000000..70688356
Binary files /dev/null and b/st.suckless.org/patches/font2/st-font2-wpatch2.png differ
Received on Mon Apr 15 2019 - 23:58:48 CEST