aboutsummaryrefslogtreecommitdiff
path: root/x.c
diff options
context:
space:
mode:
authorFederico I <git@federicoigne.com>2020-03-21 12:13:31 +0000
committerFederico I <git@federicoigne.com>2020-03-21 12:13:31 +0000
commit6524745f3a2e106037980b908c8890c650b16ba2 (patch)
tree8add35ec39fb3ef5c3655843d1838f2c932e79c0 /x.c
parent7922d05500ac68538819bf4028bdfbfe0e482810 (diff)
downloadst-6524745f3a2e106037980b908c8890c650b16ba2.tar.gz
st-6524745f3a2e106037980b908c8890c650b16ba2.zip
Apply Font2 patch (with working color emoji support)
Patch Homepage: https://st.suckless.org/patches/font2/ Patch Link: https://st.suckless.org/patches/font2/st-font2-20190416-ba72400.diff Additional notes: This patch involved multiple steps: + libXft needs to be patched to avoid instant crash of st. The patch was submitted as a PR here (https://gitlab.freedesktop.org/xorg/lib/libxft/-/merge_requests/1) and here for the patch file (https://gitlab.freedesktop.org/xorg/lib/libxft/-/merge_requests/1/diffs.patch). Gentoo x11-libs/libXft package can be easily patched following the instructions here (https://wiki.gentoo.org/wiki//etc/portage/patches). A patched package is available in the AUR for ArchLinux users (https://aur.archlinux.org/packages/libxft-bgra/); + Install a font supporting colored emoji. In this case I prefer the Twitter Color Emoji font buy Joy Pixels (formerly EmojiOne) has been tested and works as well. Follow the instructions here to install the font (https://github.com/eosrei/twemoji-color-font#manual-install-on-any-linux). They also suggest to install Bitstream Vera font to use for serif/sans/sans serif fonts due to its (almost absent) coverage of emojis, which won't interfere with the emoji font. The installation script also deploys a fontconfig file to properly setup fonts. From initial tests seems to work out of the box; + Apply patch (manually)
Diffstat (limited to 'x.c')
-rw-r--r--x.c102
1 files changed, 102 insertions, 0 deletions
diff --git a/x.c b/x.c
index 48a6676..be1d3d0 100644
--- a/x.c
+++ b/x.c
@@ -157,6 +157,8 @@ static void xhints(void);
157static int xloadcolor(int, const char *, Color *); 157static int xloadcolor(int, const char *, Color *);
158static int xloadfont(Font *, FcPattern *); 158static int xloadfont(Font *, FcPattern *);
159static void xloadfonts(char *, double); 159static void xloadfonts(char *, double);
160static int xloadsparefont(FcPattern *, int);
161static void xloadsparefonts(void);
160static void xunloadfont(Font *); 162static void xunloadfont(Font *);
161static void xunloadfonts(void); 163static void xunloadfonts(void);
162static void xsetenv(void); 164static void xsetenv(void);
@@ -305,6 +307,7 @@ zoomabs(const Arg *arg)
305{ 307{
306 xunloadfonts(); 308 xunloadfonts();
307 xloadfonts(usedfont, arg->f); 309 xloadfonts(usedfont, arg->f);
310 xloadsparefonts();
308 cresize(0, 0); 311 cresize(0, 0);
309 redraw(); 312 redraw();
310 xhints(); 313 xhints();
@@ -1004,6 +1007,102 @@ xloadfonts(char *fontstr, double fontsize)
1004 FcPatternDestroy(pattern); 1007 FcPatternDestroy(pattern);
1005} 1008}
1006 1009
1010int
1011xloadsparefont(FcPattern *pattern, int flags)
1012{
1013 FcPattern *match;
1014 FcResult result;
1015
1016 match = FcFontMatch(NULL, pattern, &result);
1017 if (!match) {
1018 return 1;
1019 }
1020
1021 if (!(frc[frclen].font = XftFontOpenPattern(xw.dpy, match))) {
1022 FcPatternDestroy(match);
1023 return 1;
1024 }
1025
1026 frc[frclen].flags = flags;
1027 /* Believe U+0000 glyph will present in each default font */
1028 frc[frclen].unicodep = 0;
1029 frclen++;
1030
1031 return 0;
1032}
1033
1034void
1035xloadsparefonts(void)
1036{
1037 FcPattern *pattern;
1038 double sizeshift, fontval;
1039 int fc;
1040 char **fp;
1041
1042 if (frclen != 0)
1043 die("can't embed spare fonts. cache isn't empty");
1044
1045 /* Calculate count of spare fonts */
1046 fc = sizeof(font2) / sizeof(*font2);
1047 if (fc == 0)
1048 return;
1049
1050 /* Allocate memory for cache entries. */
1051 if (frccap < 4 * fc) {
1052 frccap += 4 * fc - frccap;
1053 frc = xrealloc(frc, frccap * sizeof(Fontcache));
1054 }
1055
1056 for (fp = font2; fp - font2 < fc; ++fp) {
1057
1058 if (**fp == '-')
1059 pattern = XftXlfdParse(*fp, False, False);
1060 else
1061 pattern = FcNameParse((FcChar8 *)*fp);
1062
1063 if (!pattern)
1064 die("can't open spare font %s\n", *fp);
1065
1066 if (defaultfontsize > 0) {
1067 sizeshift = usedfontsize - defaultfontsize;
1068 if (sizeshift != 0 &&
1069 FcPatternGetDouble(pattern, FC_PIXEL_SIZE, 0, &fontval) ==
1070 FcResultMatch) {
1071 fontval += sizeshift;
1072 FcPatternDel(pattern, FC_PIXEL_SIZE);
1073 FcPatternDel(pattern, FC_SIZE);
1074 FcPatternAddDouble(pattern, FC_PIXEL_SIZE, fontval);
1075 }
1076 }
1077
1078 FcPatternAddBool(pattern, FC_SCALABLE, 1);
1079
1080 FcConfigSubstitute(NULL, pattern, FcMatchPattern);
1081 XftDefaultSubstitute(xw.dpy, xw.scr, pattern);
1082
1083 if (xloadsparefont(pattern, FRC_NORMAL))
1084 die("can't open spare font %s\n", *fp);
1085
1086 FcPatternDel(pattern, FC_SLANT);
1087 FcPatternAddInteger(pattern, FC_SLANT, FC_SLANT_ITALIC);
1088 if (xloadsparefont(pattern, FRC_ITALIC))
1089 die("can't open spare font %s\n", *fp);
1090
1091 FcPatternDel(pattern, FC_WEIGHT);
1092 FcPatternAddInteger(pattern, FC_WEIGHT, FC_WEIGHT_BOLD);
1093 if (xloadsparefont(pattern, FRC_ITALICBOLD))
1094 die("can't open spare font %s\n", *fp);
1095
1096 FcPatternDel(pattern, FC_SLANT);
1097 FcPatternAddInteger(pattern, FC_SLANT, FC_SLANT_ROMAN);
1098 if (xloadsparefont(pattern, FRC_BOLD))
1099 die("can't open spare font %s\n", *fp);
1100
1101 FcPatternDestroy(pattern);
1102 }
1103}
1104
1105
1007void 1106void
1008xunloadfont(Font *f) 1107xunloadfont(Font *f)
1009{ 1108{
@@ -1101,6 +1200,9 @@ xinit(int cols, int rows)
1101 usedfont = (opt_font == NULL)? font : opt_font; 1200 usedfont = (opt_font == NULL)? font : opt_font;
1102 xloadfonts(usedfont, 0); 1201 xloadfonts(usedfont, 0);
1103 1202
1203 /* spare fonts */
1204 xloadsparefonts();
1205
1104 /* colors */ 1206 /* colors */
1105 xw.cmap = XDefaultColormap(xw.dpy, xw.scr); 1207 xw.cmap = XDefaultColormap(xw.dpy, xw.scr);
1106 xloadcols(); 1208 xloadcols();