sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

st-font2-bitmap-0.9.3.diff (3827B)


      1 diff --git a/config.def.h b/config.def.h
      2 index 2cd740a..1dd5a9b 100644
      3 --- a/config.def.h
      4 +++ b/config.def.h
      5 @@ -6,6 +6,12 @@
      6   * font: see http://freedesktop.org/software/fontconfig/fontconfig-user.html
      7   */
      8  static char *font = "Liberation Mono:pixelsize=12:antialias=true:autohint=true";
      9 +/* Spare fonts */
     10 +static char *font2[] = {
     11 +/*	"Inconsolata for Powerline:pixelsize=12:antialias=true:autohint=true", */
     12 +/*	"Hack Nerd Font Mono:pixelsize=11:antialias=true:autohint=true", */
     13 +};
     14 +
     15  static int borderpx = 2;
     16  
     17  /*
     18 diff --git a/x.c b/x.c
     19 index d73152b..36f8939 100644
     20 --- a/x.c
     21 +++ b/x.c
     22 @@ -157,6 +157,8 @@ static void xhints(void);
     23  static int xloadcolor(int, const char *, Color *);
     24  static int xloadfont(Font *, FcPattern *);
     25  static void xloadfonts(const char *, double);
     26 +static int xloadsparefont(FcPattern *, int);
     27 +static void xloadsparefonts(void);
     28  static void xunloadfont(Font *);
     29  static void xunloadfonts(void);
     30  static void xsetenv(void);
     31 @@ -306,6 +308,7 @@ zoomabs(const Arg *arg)
     32  {
     33  	xunloadfonts();
     34  	xloadfonts(usedfont, arg->f);
     35 +	xloadsparefonts();
     36  	cresize(0, 0);
     37  	redraw();
     38  	xhints();
     39 @@ -1050,6 +1053,101 @@ xloadfonts(const char *fontstr, double fontsize)
     40  	FcPatternDestroy(pattern);
     41  }
     42  
     43 +int
     44 +xloadsparefont(FcPattern *pattern, int flags)
     45 +{
     46 +	FcPattern *match;
     47 +	FcResult result;
     48 +
     49 +	match = FcFontMatch(NULL, pattern, &result);
     50 +	if (!match) {
     51 +		return 1;
     52 +	}
     53 +
     54 +	if (!(frc[frclen].font = XftFontOpenPattern(xw.dpy, match))) {
     55 +		FcPatternDestroy(match);
     56 +		return 1;
     57 +	}
     58 +
     59 +	frc[frclen].flags = flags;
     60 +	/* Believe U+0000 glyph will present in each default font */
     61 +	frc[frclen].unicodep = 0;
     62 +	frclen++;
     63 +
     64 +	return 0;
     65 +}
     66 +
     67 +void
     68 +xloadsparefonts(void)
     69 +{
     70 +	FcPattern *pattern;
     71 +	double sizeshift, fontval;
     72 +	int fc;
     73 +	char **fp;
     74 +
     75 +	if (frclen != 0)
     76 +		die("can't embed spare fonts. cache isn't empty");
     77 +
     78 +	/* Calculate count of spare fonts */
     79 +	fc = sizeof(font2) / sizeof(*font2);
     80 +	if (fc == 0)
     81 +		return;
     82 +
     83 +	/* Allocate memory for cache entries. */
     84 +	if (frccap < 4 * fc) {
     85 +		frccap += 4 * fc - frccap;
     86 +		frc = xrealloc(frc, frccap * sizeof(Fontcache));
     87 +	}
     88 +
     89 +	for (fp = font2; fp - font2 < fc; ++fp) {
     90 +
     91 +		if (**fp == '-')
     92 +			pattern = XftXlfdParse(*fp, False, False);
     93 +		else
     94 +			pattern = FcNameParse((FcChar8 *)*fp);
     95 +
     96 +		if (!pattern)
     97 +			die("can't open spare font %s\n", *fp);
     98 +
     99 +		if (defaultfontsize > 0) {
    100 +			sizeshift = usedfontsize - defaultfontsize;
    101 +			if (sizeshift != 0 &&
    102 +					FcPatternGetDouble(pattern, FC_PIXEL_SIZE, 0, &fontval) ==
    103 +					FcResultMatch) {
    104 +				fontval += sizeshift;
    105 +				FcPatternDel(pattern, FC_PIXEL_SIZE);
    106 +				FcPatternDel(pattern, FC_SIZE);
    107 +				FcPatternAddDouble(pattern, FC_PIXEL_SIZE, fontval);
    108 +			}
    109 +		}
    110 +
    111 +		FcPatternDel(pattern, FC_SCALABLE);
    112 +
    113 +		FcConfigSubstitute(NULL, pattern, FcMatchPattern);
    114 +		XftDefaultSubstitute(xw.dpy, xw.scr, pattern);
    115 +
    116 +		if (xloadsparefont(pattern, FRC_NORMAL))
    117 +			die("can't open spare font %s\n", *fp);
    118 +
    119 +		FcPatternDel(pattern, FC_SLANT);
    120 +		FcPatternAddInteger(pattern, FC_SLANT, FC_SLANT_ITALIC);
    121 +		if (xloadsparefont(pattern, FRC_ITALIC))
    122 +			die("can't open spare font %s\n", *fp);
    123 +
    124 +		FcPatternDel(pattern, FC_WEIGHT);
    125 +		FcPatternAddInteger(pattern, FC_WEIGHT, FC_WEIGHT_BOLD);
    126 +		if (xloadsparefont(pattern, FRC_ITALICBOLD))
    127 +			die("can't open spare font %s\n", *fp);
    128 +
    129 +		FcPatternDel(pattern, FC_SLANT);
    130 +		FcPatternAddInteger(pattern, FC_SLANT, FC_SLANT_ROMAN);
    131 +		if (xloadsparefont(pattern, FRC_BOLD))
    132 +			die("can't open spare font %s\n", *fp);
    133 +
    134 +		FcPatternDestroy(pattern);
    135 +	}
    136 +}
    137 +
    138  void
    139  xunloadfont(Font *f)
    140  {
    141 @@ -1147,6 +1245,9 @@ xinit(int cols, int rows)
    142  	usedfont = (opt_font == NULL)? font : opt_font;
    143  	xloadfonts(usedfont, 0);
    144  
    145 +	/* spare fonts */
    146 +	xloadsparefonts();
    147 +
    148  	/* colors */
    149  	xw.cmap = XDefaultColormap(xw.dpy, xw.scr);
    150  	xloadcols();