diff options
author | Christoph Lohmann <20h@r-36.net> | 2012-09-30 20:10:58 +0200 |
---|---|---|
committer | Christoph Lohmann <20h@r-36.net> | 2012-09-30 20:10:58 +0200 |
commit | 9cae1eb0ded2e1ca604753893e2307531ef73afc (patch) | |
tree | 101de87791d9b28f3ab37fcb0a756bf4305441c1 | |
parent | ed5b8700a6e6c14b814dcc2e54a90eb1868070b5 (diff) | |
download | st-9cae1eb0ded2e1ca604753893e2307531ef73afc.tar.gz st-9cae1eb0ded2e1ca604753893e2307531ef73afc.tar.bz2 st-9cae1eb0ded2e1ca604753893e2307531ef73afc.zip |
Remove the cruft of the user to have to define the different font styles.
-rw-r--r-- | st.c | 60 |
1 files changed, 55 insertions, 5 deletions
@@ -336,6 +336,7 @@ static int isfullutf8(char *, int); static void *xmalloc(size_t); static void *xrealloc(void *, size_t); static void *xcalloc(size_t nmemb, size_t size); +static char *smstrcat(char *, ...); static void (*handler[LASTEvent])(XEvent *) = { [KeyPress] = kpress, @@ -393,6 +394,44 @@ xcalloc(size_t nmemb, size_t size) { return p; } +char * +smstrcat(char *src, ...) +{ + va_list fmtargs; + char *ret, *p, *v; + int len, slen, flen; + + len = slen = strlen(src); + + va_start(fmtargs, src); + for(;;) { + v = va_arg(fmtargs, char *); + if(v == NULL) + break; + len += strlen(v); + } + va_end(fmtargs); + + p = ret = xmalloc(len+1); + memmove(p, src, slen); + p += slen; + + va_start(fmtargs, src); + for(;;) { + v = va_arg(fmtargs, char *); + if(v == NULL) + break; + flen = strlen(v); + memmove(p, v, flen); + p += flen; + } + va_end(fmtargs); + + ret[len] = '\0'; + + return ret; +} + int utf8decode(char *s, long *u) { uchar c; @@ -2017,11 +2056,22 @@ xinitfont(Font *f, char *fontstr) { } void -initfonts(char *fontstr, char *bfontstr, char *ifontstr, char *ibfontstr) { +initfonts(char *fontstr) { + char *fstr; + xinitfont(&dc.font, fontstr); - xinitfont(&dc.bfont, bfontstr); - xinitfont(&dc.ifont, ifontstr); - xinitfont(&dc.ibfont, ibfontstr); + + fstr = smstrcat(fontstr, ":weight=bold", NULL); + xinitfont(&dc.bfont, fstr); + free(fstr); + + fstr = smstrcat(fontstr, ":slant=italic,oblique", NULL); + xinitfont(&dc.ifont, fstr); + free(fstr); + + fstr = smstrcat(fontstr, ":weight=bold:slant=italic,oblique", NULL); + xinitfont(&dc.ibfont, fstr); + free(fstr); } void @@ -2037,7 +2087,7 @@ xinit(void) { xw.vis = XDefaultVisual(xw.dpy, xw.scr); /* font */ - initfonts(FONT, BOLDFONT, ITALICFONT, ITALICBOLDFONT); + initfonts(FONT); /* XXX: Assuming same size for bold font */ xw.cw = dc.font.rbearing - dc.font.lbearing; |