sites

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

st-font2-20190326-f64c2f8.diff (3760B)


      1 From f64c2f83a2e3ee349fe11100526110dfdf47067a Mon Sep 17 00:00:00 2001
      2 From: Kirill Bugaev <kirill.bugaev87@gmail.com>
      3 Date: Wed, 27 Mar 2019 01:28:56 +0800
      4 Subject: [PATCH] Some glyphs can be not present in font defined by default.
      5  For this glyphs st uses font-config and try to find them in font cache first.
      6  This patch append font defined in `font2` variable to the beginning of font
      7  cache. So it will be used as spare font.
      8 
      9 ---
     10  config.def.h |  1 +
     11  x.c          | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++
     12  2 files changed, 67 insertions(+)
     13 
     14 diff --git a/config.def.h b/config.def.h
     15 index 482901e..88eee0f 100644
     16 --- a/config.def.h
     17 +++ b/config.def.h
     18 @@ -6,6 +6,7 @@
     19   * font: see http://freedesktop.org/software/fontconfig/fontconfig-user.html
     20   */
     21  static char *font = "Liberation Mono:pixelsize=12:antialias=true:autohint=true";
     22 +static char *font2 = "Roboto Mono for Powerline:pixelsize=12:antialias=true:autohint=true";
     23  static int borderpx = 2;
     24  
     25  /*
     26 diff --git a/x.c b/x.c
     27 index 5828a3b..052b10b 100644
     28 --- a/x.c
     29 +++ b/x.c
     30 @@ -149,6 +149,7 @@ static void xhints(void);
     31  static int xloadcolor(int, const char *, Color *);
     32  static int xloadfont(Font *, FcPattern *);
     33  static void xloadfonts(char *, double);
     34 +static void xloadsparefont();
     35  static void xunloadfont(Font *);
     36  static void xunloadfonts(void);
     37  static void xsetenv(void);
     38 @@ -296,6 +297,7 @@ zoomabs(const Arg *arg)
     39  {
     40  	xunloadfonts();
     41  	xloadfonts(usedfont, arg->f);
     42 +	xloadsparefont();
     43  	cresize(0, 0);
     44  	redraw();
     45  	xhints();
     46 @@ -977,6 +979,67 @@ xloadfonts(char *fontstr, double fontsize)
     47  	FcPatternDestroy(pattern);
     48  }
     49  
     50 +void
     51 +xloadsparefont()
     52 +{
     53 +	FcPattern *fontpattern, *match;
     54 +	FcResult result;
     55 +
     56 +	/* add font2 to font cache as first 4 entries */
     57 +	if ( font2[0] == '-' )
     58 +		fontpattern = XftXlfdParse(font2, False, False);
     59 +	else
     60 +		fontpattern = FcNameParse((FcChar8 *)font2);
     61 +	if ( fontpattern ) {
     62 +		/* Allocate memory for the new cache entries. */
     63 +		frccap += 4;
     64 +		frc = xrealloc(frc, frccap * sizeof(Fontcache));
     65 +		/* add Normal */
     66 +		match = FcFontMatch(NULL, fontpattern, &result);
     67 +		if ( match ) 
     68 +			frc[frclen].font = XftFontOpenPattern(xw.dpy, match);
     69 +			if ( frc[frclen].font ) {
     70 +				frc[frclen].flags = FRC_NORMAL;
     71 +				frclen++;
     72 +			} else
     73 +				FcPatternDestroy(match);
     74 +		/* add Italic */
     75 +		FcPatternDel(fontpattern, FC_SLANT);
     76 +		FcPatternAddInteger(fontpattern, FC_SLANT, FC_SLANT_ITALIC);
     77 +		match = FcFontMatch(NULL, fontpattern, &result);
     78 +		if ( match )
     79 +			frc[frclen].font = XftFontOpenPattern(xw.dpy, match);
     80 +			if ( frc[frclen].font ) {
     81 +				frc[frclen].flags = FRC_ITALIC;
     82 +				frclen++;
     83 +			} else
     84 +				FcPatternDestroy(match);
     85 +		/* add Italic Bold */
     86 +		FcPatternDel(fontpattern, FC_WEIGHT);
     87 +		FcPatternAddInteger(fontpattern, FC_WEIGHT, FC_WEIGHT_BOLD);
     88 +		match = FcFontMatch(NULL, fontpattern, &result);
     89 +		if ( match )
     90 +			frc[frclen].font = XftFontOpenPattern(xw.dpy, match);
     91 +			if ( frc[frclen].font ) {
     92 +				frc[frclen].flags = FRC_ITALICBOLD;
     93 +				frclen++;
     94 +			} else 
     95 +				FcPatternDestroy(match);
     96 +		/* add Bold */
     97 +		FcPatternDel(fontpattern, FC_SLANT);
     98 +		FcPatternAddInteger(fontpattern, FC_SLANT, FC_SLANT_ROMAN);
     99 +		match = FcFontMatch(NULL, fontpattern, &result);
    100 +		if ( match )
    101 +			frc[frclen].font = XftFontOpenPattern(xw.dpy, match);
    102 +			if ( frc[frclen].font ) {
    103 +				frc[frclen].flags = FRC_BOLD;
    104 +				frclen++;
    105 +			} else 
    106 +				FcPatternDestroy(match);
    107 +		FcPatternDestroy(fontpattern);
    108 +	}
    109 +}
    110 +
    111  void
    112  xunloadfont(Font *f)
    113  {
    114 @@ -1057,6 +1120,9 @@ xinit(int cols, int rows)
    115  	usedfont = (opt_font == NULL)? font : opt_font;
    116  	xloadfonts(usedfont, 0);
    117  
    118 +	/* spare font (font2) */
    119 +	xloadsparefont();
    120 +
    121  	/* colors */
    122  	xw.cmap = XDefaultColormap(xw.dpy, xw.scr);
    123  	xloadcols();
    124 -- 
    125 2.21.0
    126