-loadfont(Display *dpy, Fnt *font, const char *fontstr)
-{
- char **missing, *def;
- int n;
-
- missing = NULL;
- def = "?";
- setlocale(LC_ALL, "");
- if(font->set)
- XFreeFontSet(dpy, font->set);
- font->set = XCreateFontSet(dpy, fontstr, &missing, &n, &def);
- if(missing) {
- while(n--)
- fprintf(stderr, "missing fontset: %s\n", missing[n]);
- XFreeStringList(missing);
- if(font->set) {
- XFreeFontSet(dpy, font->set);
- font->set = NULL;
- }
- }
- if(font->set) {
- XFontSetExtents *font_extents;
- XFontStruct **xfonts;
- char **font_names;
- unsigned int i;
-
- font->ascent = font->descent = 0;
- font_extents = XExtentsOfFontSet(font->set);
- n = XFontsOfFontSet(font->set, &xfonts, &font_names);
- for(i = 0, font->ascent = 0, font->descent = 0; i < n; i++) {
- if(font->ascent < (*xfonts)->ascent)
- font->ascent = (*xfonts)->ascent;
- if(font->descent < (*xfonts)->descent)
- font->descent = (*xfonts)->descent;
- xfonts++;
- }
- }
- else {
- if(font->xfont)
- XFreeFont(dpy, font->xfont);
- font->xfont = NULL;
- font->xfont = XLoadQueryFont(dpy, fontstr);
- if (!font->xfont)
- font->xfont = XLoadQueryFont(dpy, "fixed");
- if (!font->xfont)
- eprint("error, cannot load 'fixed' font\n");
- font->ascent = font->xfont->ascent;
- font->descent = font->xfont->descent;
+resizedc(DC *dc, unsigned int w, unsigned int h) {
+ if(dc->canvas)
+ XFreePixmap(dc->dpy, dc->canvas);
+
+ dc->w = w;
+ dc->h = h;
+ dc->canvas = XCreatePixmap(dc->dpy, DefaultRootWindow(dc->dpy), w, h,
+ DefaultDepth(dc->dpy, DefaultScreen(dc->dpy)));
+}
+
+int
+textnw(DC *dc, const char *text, size_t len) {
+ if(dc->font.set) {
+ XRectangle r;
+
+ XmbTextExtents(dc->font.set, text, len, NULL, &r);
+ return r.width;