diff options
| author | Federico I <git@federicoigne.com> | 2020-03-21 12:13:31 +0000 |
|---|---|---|
| committer | Federico I <git@federicoigne.com> | 2020-03-21 12:13:31 +0000 |
| commit | 6524745f3a2e106037980b908c8890c650b16ba2 (patch) | |
| tree | 8add35ec39fb3ef5c3655843d1838f2c932e79c0 | |
| parent | 7922d05500ac68538819bf4028bdfbfe0e482810 (diff) | |
| download | st-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)
| -rw-r--r-- | config.h | 7 | ||||
| -rw-r--r-- | x.c | 102 |
2 files changed, 108 insertions, 1 deletions
| @@ -6,6 +6,11 @@ | |||
| 6 | * font: see http://freedesktop.org/software/fontconfig/fontconfig-user.html | 6 | * font: see http://freedesktop.org/software/fontconfig/fontconfig-user.html |
| 7 | */ | 7 | */ |
| 8 | static char *font = "curie"; | 8 | static char *font = "curie"; |
| 9 | static char *font2[] = { | ||
| 10 | "Twitter Color Emoji:size=8", | ||
| 11 | /* "Inconsolata for Powerline:pixelsize=12:antialias=true:autohint=true", */ | ||
| 12 | /* "Hack Nerd Font Mono:pixelsize=11:antialias=true:autohint=true", */ | ||
| 13 | }; | ||
| 9 | static int borderpx = 2; | 14 | static int borderpx = 2; |
| 10 | 15 | ||
| 11 | /* | 16 | /* |
| @@ -24,7 +29,7 @@ char *stty_args = "stty raw pass8 nl -echo -iexten -cstopb 38400"; | |||
| 24 | char *vtiden = "\033[?6c"; | 29 | char *vtiden = "\033[?6c"; |
| 25 | 30 | ||
| 26 | /* Kerning / character bounding-box multipliers */ | 31 | /* Kerning / character bounding-box multipliers */ |
| 27 | static float cwscale = 0.6; | 32 | static float cwscale = 0.65; |
| 28 | static float chscale = 1.0; | 33 | static float chscale = 1.0; |
| 29 | 34 | ||
| 30 | /* | 35 | /* |
| @@ -157,6 +157,8 @@ static void xhints(void); | |||
| 157 | static int xloadcolor(int, const char *, Color *); | 157 | static int xloadcolor(int, const char *, Color *); |
| 158 | static int xloadfont(Font *, FcPattern *); | 158 | static int xloadfont(Font *, FcPattern *); |
| 159 | static void xloadfonts(char *, double); | 159 | static void xloadfonts(char *, double); |
| 160 | static int xloadsparefont(FcPattern *, int); | ||
| 161 | static void xloadsparefonts(void); | ||
| 160 | static void xunloadfont(Font *); | 162 | static void xunloadfont(Font *); |
| 161 | static void xunloadfonts(void); | 163 | static void xunloadfonts(void); |
| 162 | static void xsetenv(void); | 164 | static 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 | ||
| 1010 | int | ||
| 1011 | xloadsparefont(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 | |||
| 1034 | void | ||
| 1035 | xloadsparefonts(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 | |||
| 1007 | void | 1106 | void |
| 1008 | xunloadfont(Font *f) | 1107 | xunloadfont(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(); |
