aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config.h7
-rw-r--r--x.c102
2 files changed, 108 insertions, 1 deletions
diff --git a/config.h b/config.h
index 7a7b4ed..40f8213 100644
--- a/config.h
+++ b/config.h
@@ -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 */
8static char *font = "curie"; 8static char *font = "curie";
9static 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};
9static int borderpx = 2; 14static int borderpx = 2;
10 15
11/* 16/*
@@ -24,7 +29,7 @@ char *stty_args = "stty raw pass8 nl -echo -iexten -cstopb 38400";
24char *vtiden = "\033[?6c"; 29char *vtiden = "\033[?6c";
25 30
26/* Kerning / character bounding-box multipliers */ 31/* Kerning / character bounding-box multipliers */
27static float cwscale = 0.6; 32static float cwscale = 0.65;
28static float chscale = 1.0; 33static float chscale = 1.0;
29 34
30/* 35/*
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();