aboutsummaryrefslogtreecommitdiffstats
path: root/font.c
diff options
context:
space:
mode:
authoroga2008-06-15 02:47:46 +0000
committeroga2008-06-15 02:47:46 +0000
commit95f0da676903ac1975beaa3567cb8c5ba28660e5 (patch)
tree9b5c8fbd2442ccbde0b95a852321b9a5b5ee93f7 /font.c
parent436f35e0eec7bc1d4cebee440858aad0e2f5e123 (diff)
downloadcwm-95f0da676903ac1975beaa3567cb8c5ba28660e5.tar.gz
Rip out and burn the HASH_* stuff. We don't need a SPLAY tree for one font.
makes the code a lot simpler. While here rearrange the font handling functions to be less shit. ok and help okan@.
Diffstat (limited to 'font.c')
-rw-r--r--font.c97
1 files changed, 9 insertions, 88 deletions
diff --git a/font.c b/font.c
index 38670e5..85f54e5 100644
--- a/font.c
+++ b/font.c
@@ -16,51 +16,14 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-#include "hash.h"
#include "headers.h"
#include "calmwm.h"
-static XftFont *_make_font(struct screen_ctx *sc, struct fontdesc *fdp);
-
-HASH_GENERATE(fonthash, fontdesc, node, fontdesc_cmp);
-
-int
-fontdesc_cmp(struct fontdesc *a, struct fontdesc *b)
-{
- return (strcmp(a->name, b->name));
-}
-
-/*
- * Fowler/Noll/Vo hash
- * http://www.isthe.com/chongo/tech/comp/fnv/
- */
-
-#define FNV_P_32 ((unsigned int)0x01000193) /* 16777619 */
-#define FNV_1_32 ((unsigned int)0x811c9dc5) /* 2166136261 */
-
-unsigned int
-fontdesc_hash(struct fontdesc *fdp)
-{
- const unsigned char *p, *end, *start;
- unsigned int hash = FNV_1_32;
-
- start = fdp->name;
- end = (const unsigned char *)fdp->name + strlen(fdp->name);
-
- for (p = start; p < end; p++) {
- hash *= FNV_P_32;
- hash ^= (unsigned int)*p;
- }
-
- return (hash);
-}
-
void
font_init(struct screen_ctx *sc)
{
XColor xcolor, tmp;
- HASH_INIT(&sc->fonthash, fontdesc_hash);
sc->xftdraw = XftDrawCreate(X_Dpy, sc->rootwin,
DefaultVisual(X_Dpy, sc->which), DefaultColormap(X_Dpy, sc->which));
if (sc->xftdraw == NULL)
@@ -77,76 +40,34 @@ font_init(struct screen_ctx *sc)
sc->xftcolor.pixel = xcolor.pixel;
}
-struct fontdesc *
-font_getx(struct screen_ctx *sc, const char *name)
-{
- struct fontdesc *fdp;
-
- if ((fdp = font_get(sc, name)) == NULL)
- errx(1, "font_get()");
-
- return (fdp);
-}
-
-struct fontdesc *
-font_get(struct screen_ctx *sc, const char *name)
-{
- struct fontdesc fd, *fdp;
- XftFont *fn;
-
- fd.name = name;
-
- if ((fdp = HASH_FIND(fonthash, &sc->fonthash, &fd)) == NULL
- && (fn = _make_font(sc, &fd)) != NULL) {
- fdp = xmalloc(sizeof(*fdp));
- fdp->name = xstrdup(fd.name);
- fdp->fn = fn;
- fdp->sc = sc;
- HASH_INSERT(fonthash, &sc->fonthash, fdp);
- }
-
- return (fdp);
-}
-
int
-font_width(struct fontdesc *fdp, const char *text, int len)
+font_width(const char *text, int len)
{
XGlyphInfo extents;
- XftTextExtents8(X_Dpy, fdp->fn, (const XftChar8*)text, len, &extents);
+ XftTextExtents8(X_Dpy, Conf.DefaultFont, (const XftChar8*)text,
+ len, &extents);
return (extents.xOff);
}
void
-font_draw(struct fontdesc *fdp, const char *text, int len,
+font_draw(struct screen_ctx *sc, const char *text, int len,
Drawable d, int x, int y)
{
- XftDrawChange(fdp->sc->xftdraw, d);
+ XftDrawChange(sc->xftdraw, d);
/* Really needs to be UTF8'd. */
- XftDrawString8(fdp->sc->xftdraw, &fdp->sc->xftcolor, fdp->fn, x, y,
+ XftDrawString8(sc->xftdraw, &sc->xftcolor, Conf.DefaultFont, x, y,
(const FcChar8*)text, len);
}
-int
-font_ascent(struct fontdesc *fdp)
-{
- return (fdp->fn->ascent);
-}
-
-int
-font_descent(struct fontdesc *fdp)
-{
- return (fdp->fn->descent);
-}
-
-static XftFont *
-_make_font(struct screen_ctx *sc, struct fontdesc *fdp)
+XftFont *
+font_make(struct screen_ctx *sc, const char *name)
{
XftFont *fn = NULL;
FcPattern *pat, *patx;
XftResult res;
- if ((pat = FcNameParse(fdp->name)) == NULL)
+ if ((pat = FcNameParse(name)) == NULL)
return (NULL);
if ((patx = XftFontMatch(X_Dpy, sc->which, pat, &res)) != NULL)