replace hand rolled font_make() with XftFontOpenName() and merge into

font_init().
This commit is contained in:
okan 2012-11-28 14:14:44 +00:00
parent 93f64ffc55
commit fad4798e5b
3 changed files with 8 additions and 23 deletions

View File

@ -446,9 +446,9 @@ int font_descent(struct screen_ctx *);
void font_draw(struct screen_ctx *, const char *, int,
Drawable, int, int);
u_int font_height(struct screen_ctx *);
void font_init(struct screen_ctx *, const char *);
void font_init(struct screen_ctx *, const char *,
const char *);
int font_width(struct screen_ctx *, const char *, int);
XftFont *font_make(struct screen_ctx *, const char *);
void xev_loop(void);

3
conf.c
View File

@ -62,8 +62,7 @@ conf_gap(struct conf *c, struct screen_ctx *sc)
void
conf_font(struct conf *c, struct screen_ctx *sc)
{
font_init(sc, c->color[CWM_COLOR_FONT].name);
sc->font = font_make(sc, c->font);
font_init(sc, c->font, c->color[CWM_COLOR_FONT].name);
}
static struct color color_binds[] = {

24
font.c
View File

@ -49,7 +49,7 @@ font_height(struct screen_ctx *sc)
}
void
font_init(struct screen_ctx *sc, const char *color)
font_init(struct screen_ctx *sc, const char *name, const char *color)
{
sc->xftdraw = XftDrawCreate(X_Dpy, sc->rootwin,
DefaultVisual(X_Dpy, sc->which), DefaultColormap(X_Dpy, sc->which));
@ -59,6 +59,10 @@ font_init(struct screen_ctx *sc, const char *color)
if (!XftColorAllocName(X_Dpy, DefaultVisual(X_Dpy, sc->which),
DefaultColormap(X_Dpy, sc->which), color, &sc->xftcolor))
errx(1, "XftColorAllocName");
sc->font = XftFontOpenName(X_Dpy, sc->which, name);
if (sc->font == NULL)
errx(1, "XftFontOpenName");
}
int
@ -80,21 +84,3 @@ font_draw(struct screen_ctx *sc, const char *text, int len,
XftDrawStringUtf8(sc->xftdraw, &sc->xftcolor, sc->font, x, y,
(const FcChar8*)text, len);
}
XftFont *
font_make(struct screen_ctx *sc, const char *name)
{
XftFont *fn = NULL;
FcPattern *pat, *patx;
XftResult res;
if ((pat = FcNameParse((const FcChar8*)name)) == NULL)
return (NULL);
if ((patx = XftFontMatch(X_Dpy, sc->which, pat, &res)) != NULL)
fn = XftFontOpenPattern(X_Dpy, patx);
FcPatternDestroy(pat);
return (fn);
}