Hey everyone,
I was looking around the other day and I found a really nice font
(tamsyn), but it seemed that st wouldn't work with it because it didn't
have a proper name.
The creator should update the font soon to include such a name, but I
also wrote a patch that allows st to load the font without that proper
name.
It's mostly copied from dmenu, since that was loading the fonts the same
way.
I hope it's ok and I didn't miss this already existing.
Greetings,
Tom
diff -r c5a118daa7d5 -r 14cb714c4444 st.c
--- a/st.c Thu Jan 27 17:51:01 2011 +0100
+++ b/st.c Thu Feb 03 12:14:02 2011 +0100
@@ -142,6 +142,7 @@
short lbearing;
short rbearing;
XFontSet set;
+ XFontStruct *xfont;
} font, bfont;
} DC;
@@ -1474,6 +1475,15 @@
}
void
+xgetxfontinfo(XFontStruct *font, int *ascent, int *descent, short *lbearing,
short *rbearing)
+{
+ *ascent = font->ascent;
+ *descent = font->descent;
+ *lbearing = font->min_bounds.lbearing;
+ *rbearing = font->max_bounds.rbearing;
+}
+
+void
xgetfontinfo(XFontSet set, int *ascent, int *descent, short *lbearing, short
*rbearing)
{
XFontStruct **xfonts;
@@ -1494,13 +1504,22 @@
void
initfonts(char *fontstr, char *bfontstr)
{
- if((dc.font.set = xinitfont(fontstr)) == NULL ||
- (dc.bfont.set = xinitfont(bfontstr)) == NULL)
- die("Can't load font %s\n", dc.font.set ? BOLDFONT : FONT);
- xgetfontinfo(dc.font.set, &dc.font.ascent, &dc.font.descent,
- &dc.font.lbearing, &dc.font.rbearing);
- xgetfontinfo(dc.bfont.set, &dc.bfont.ascent, &dc.bfont.descent,
- &dc.bfont.lbearing, &dc.bfont.rbearing);
+ if((dc.font.set = xinitfont(fontstr)) != NULL &&
+ (dc.bfont.set = xinitfont(bfontstr)) != NULL) {
+ xgetfontinfo(dc.font.set, &dc.font.ascent, &dc.font.descent,
+ &dc.font.lbearing, &dc.font.rbearing);
+ xgetfontinfo(dc.bfont.set, &dc.bfont.ascent, &dc.bfont.descent,
+ &dc.bfont.lbearing, &dc.bfont.rbearing);
+ }
+ else if ((dc.font.xfont = XLoadQueryFont(xw.dpy, fontstr)) != NULL &&
+ (dc.bfont.xfont = XLoadQueryFont(xw.dpy, bfontstr)) != NULL) {
+ xgetxfontinfo(dc.font.xfont, &dc.font.ascent, &dc.font.descent,
+ &dc.font.lbearing, &dc.font.rbearing);
+ xgetxfontinfo(dc.bfont.xfont, &dc.bfont.ascent,
&dc.bfont.descent,
+ &dc.bfont.lbearing, &dc.bfont.rbearing);
+ }
+ else
+ die("Can't load font %s\n", dc.font.xfont ? BOLDFONT : FONT);
}
void
@@ -1591,8 +1610,15 @@
}
}
- XmbDrawImageString(xw.dpy, xw.buf, base.mode & ATTR_BOLD ? dc.bfont.set
: dc.font.set,
- dc.gc, winx, winy, s, bytelen);
+ if (((base.mode & ATTR_BOLD) && dc.bfont.set) || dc.font.set) {
+ XmbDrawImageString(xw.dpy, xw.buf,
+ base.mode & ATTR_BOLD ? dc.bfont.set : dc.font.set,
+ dc.gc, winx, winy, s, bytelen);
+ }
+ else {
+ XSetFont(xw.dpy, dc.gc, (base.mode & ATTR_BOLD ? dc.bfont :
dc.font).xfont->fid);
+ XDrawImageString(xw.dpy, xw.buf, dc.gc, winx, winy, s, bytelen);
+ }
if(base.mode & ATTR_UNDERLINE)
XDrawLine(xw.dpy, xw.buf, dc.gc, winx, winy+1, winx+width-1,
winy+1);