Adds additional font for italics

master
Jonathan Hodgson 3 years ago
parent f4aa84a841
commit 65482881da
  1. 1
      config.def.h
  2. 28
      x.c

@ -6,6 +6,7 @@
* font: see http://freedesktop.org/software/fontconfig/fontconfig-user.html
*/
static char *font = "Iosevka Nerd Font-10:antialias=true:autohint=true";
static char *italicfont = "Operator Mono Medium-10:antialias=true:autohint=true";
static int borderpx = 2;
/*

28
x.c

@ -156,7 +156,8 @@ static void xresize(int, int);
static void xhints(void);
static int xloadcolor(int, const char *, Color *);
static int xloadfont(Font *, FcPattern *);
static void xloadfonts(char *, double);
static int xloaditalicfont(Font *, FcPattern *);
static void xloadfonts(char *, char *, double);
static void xunloadfont(Font *);
static void xunloadfonts(void);
static void xsetenv(void);
@ -305,7 +306,7 @@ void
zoomabs(const Arg *arg)
{
xunloadfonts();
xloadfonts(usedfont, arg->f);
xloadfonts(usedfont, italicfont, arg->f);
cresize(0, 0);
redraw();
xhints();
@ -950,9 +951,10 @@ xloadfont(Font *f, FcPattern *pattern)
}
void
xloadfonts(char *fontstr, double fontsize)
xloadfonts(char *fontstr, char *italicfontstr, double fontsize)
{
FcPattern *pattern;
FcPattern *italicpattern;
double fontval;
if (fontstr[0] == '-')
@ -960,13 +962,21 @@ xloadfonts(char *fontstr, double fontsize)
else
pattern = FcNameParse((FcChar8 *)fontstr);
if (!pattern)
die("can't open font %s\n", fontstr);
if (italicfontstr[0] == '-')
italicpattern = XftXlfdParse(italicfontstr, False, False);
else
italicpattern = FcNameParse((FcChar8 *)italicfontstr);
if (!italicpattern)
die("can't open font %s\n", italicfontstr);
if (fontsize > 1) {
FcPatternDel(pattern, FC_PIXEL_SIZE);
FcPatternDel(pattern, FC_SIZE);
FcPatternAddDouble(pattern, FC_PIXEL_SIZE, (double)fontsize);
FcPatternDel(italicpattern, FC_PIXEL_SIZE);
FcPatternDel(italicpattern, FC_SIZE);
FcPatternAddDouble(italicpattern, FC_PIXEL_SIZE, (double)fontsize);
usedfontsize = fontsize;
} else {
if (FcPatternGetDouble(pattern, FC_PIXEL_SIZE, 0, &fontval) ==
@ -1002,9 +1012,9 @@ xloadfonts(char *fontstr, double fontsize)
win.ch = ceilf(dc.font.height * chscale);
FcPatternDel(pattern, FC_SLANT);
FcPatternAddInteger(pattern, FC_SLANT, FC_SLANT_ITALIC);
if (xloadfont(&dc.ifont, pattern))
die("can't open font %s\n", fontstr);
FcPatternAddInteger(italicpattern, FC_SLANT, FC_SLANT_ITALIC);
if (xloadfont(&dc.ifont, italicpattern))
die("can't open font %s\n", italicfontstr);
FcPatternDel(pattern, FC_WEIGHT);
FcPatternAddInteger(pattern, FC_WEIGHT, FC_WEIGHT_BOLD);
@ -1114,7 +1124,7 @@ xinit(int cols, int rows)
die("could not init fontconfig.\n");
usedfont = (opt_font == NULL)? font : opt_font;
xloadfonts(usedfont, 0);
xloadfonts(usedfont, italicfont, 0);
/* colors */
xw.cmap = XDefaultColormap(xw.dpy, xw.scr);

Loading…
Cancel
Save