cvsimport
This commit is contained in:
47
font.c
47
font.c
@@ -33,36 +33,52 @@
|
||||
int
|
||||
font_ascent(struct screen_ctx *sc)
|
||||
{
|
||||
return (sc->font->ascent);
|
||||
return (sc->xftfont->ascent);
|
||||
}
|
||||
|
||||
int
|
||||
font_descent(struct screen_ctx *sc)
|
||||
{
|
||||
return (sc->font->descent);
|
||||
return (sc->xftfont->descent);
|
||||
}
|
||||
|
||||
u_int
|
||||
font_height(struct screen_ctx *sc)
|
||||
{
|
||||
return (sc->font->height + 1);
|
||||
return (sc->xftfont->height + 1);
|
||||
}
|
||||
|
||||
void
|
||||
font_init(struct screen_ctx *sc, const char *name, const char *color)
|
||||
font_init(struct screen_ctx *sc, const char *name, const char **color)
|
||||
{
|
||||
int i;
|
||||
XRenderColor c;
|
||||
|
||||
sc->xftdraw = XftDrawCreate(X_Dpy, sc->rootwin,
|
||||
DefaultVisual(X_Dpy, sc->which), DefaultColormap(X_Dpy, sc->which));
|
||||
sc->visual, sc->colormap);
|
||||
if (sc->xftdraw == NULL)
|
||||
errx(1, "XftDrawCreate");
|
||||
|
||||
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)
|
||||
sc->xftfont = XftFontOpenName(X_Dpy, sc->which, name);
|
||||
if (sc->xftfont == NULL)
|
||||
errx(1, "XftFontOpenName");
|
||||
|
||||
for (i = 0; i < CWM_COLOR_MENU_MAX; i++) {
|
||||
if (*color[i] == '\0')
|
||||
break;
|
||||
if (!XftColorAllocName(X_Dpy, sc->visual, sc->colormap,
|
||||
color[i], &sc->xftcolor[i]))
|
||||
errx(1, "XftColorAllocName");
|
||||
}
|
||||
if (i == CWM_COLOR_MENU_MAX)
|
||||
return;
|
||||
|
||||
xu_xorcolor(sc->xftcolor[CWM_COLOR_MENU_BG].color,
|
||||
sc->xftcolor[CWM_COLOR_MENU_FG].color, &c);
|
||||
xu_xorcolor(sc->xftcolor[CWM_COLOR_MENU_FONT].color, c, &c);
|
||||
if (!XftColorAllocValue(X_Dpy, sc->visual, sc->colormap,
|
||||
&c, &sc->xftcolor[CWM_COLOR_MENU_FONT_SEL]))
|
||||
errx(1, "XftColorAllocValue");
|
||||
}
|
||||
|
||||
int
|
||||
@@ -70,7 +86,7 @@ font_width(struct screen_ctx *sc, const char *text, int len)
|
||||
{
|
||||
XGlyphInfo extents;
|
||||
|
||||
XftTextExtentsUtf8(X_Dpy, sc->font, (const FcChar8*)text,
|
||||
XftTextExtentsUtf8(X_Dpy, sc->xftfont, (const FcChar8*)text,
|
||||
len, &extents);
|
||||
|
||||
return (extents.xOff);
|
||||
@@ -78,9 +94,12 @@ font_width(struct screen_ctx *sc, const char *text, int len)
|
||||
|
||||
void
|
||||
font_draw(struct screen_ctx *sc, const char *text, int len,
|
||||
Drawable d, int x, int y)
|
||||
Drawable d, int active, int x, int y)
|
||||
{
|
||||
int color;
|
||||
|
||||
color = active ? CWM_COLOR_MENU_FONT_SEL : CWM_COLOR_MENU_FONT;
|
||||
XftDrawChange(sc->xftdraw, d);
|
||||
XftDrawStringUtf8(sc->xftdraw, &sc->xftcolor, sc->font, x, y,
|
||||
XftDrawStringUtf8(sc->xftdraw, &sc->xftcolor[color], sc->xftfont, x, y,
|
||||
(const FcChar8*)text, len);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user