diff options
author | Anselm R. Garbe <garbeam@wmii.de> | 2006-07-12 15:17:22 +0200 |
---|---|---|
committer | Anselm R. Garbe <garbeam@wmii.de> | 2006-07-12 15:17:22 +0200 |
commit | dfd84f9bf3b9d949412a73bc62a43109b340d395 (patch) | |
tree | ebeac582951e2ef574f50018298c4bc928849d64 /font.c | |
parent | 7696c89c90c926f6371b1ee3ec1b13dd2414aa40 (diff) | |
download | dwm-dfd84f9bf3b9d949412a73bc62a43109b340d395.tar.gz |
simplified several portions of code through replacing rect structs with x,y,h,w counterparts (much more readable)
Diffstat (limited to 'font.c')
-rw-r--r-- | font.c | 81 |
1 files changed, 0 insertions, 81 deletions
@@ -1,81 +0,0 @@ -/* - * (C)opyright MMIV-MMVI Anselm R. Garbe <garbeam at gmail dot com> - * See LICENSE file for license details. - */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <locale.h> - -unsigned int -textwidth_l(BlitzFont *font, char *text, unsigned int len) -{ - if(font->set) { - XRectangle r; - XmbTextExtents(font->set, text, len, nil, &r); - return r.width; - } - return XTextWidth(font->xfont, text, len); -} - -unsigned int -textwidth(BlitzFont *font, char *text) -{ - return blitz_textwidth_l(font, text, strlen(text)); -} - -void -loadfont(Blitz *blitz, BlitzFont *font) -{ - char *fontname = font->fontstr; - char **missing = nil, *def = "?"; - int n; - - setlocale(LC_ALL, ""); - if(font->set) - XFreeFontSet(blitz->dpy, font->set); - font->set = XCreateFontSet(blitz->dpy, fontname, &missing, &n, &def); - if(missing) { - while(n--) - fprintf(stderr, "missing fontset: %s\n", missing[n]); - XFreeStringList(missing); - if(font->set) { - XFreeFontSet(blitz->dpy, font->set); - font->set = nil; - } - } - 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(blitz->dpy, font->xfont); - font->xfont = nil; - font->xfont = XLoadQueryFont(blitz->dpy, fontname); - if (!font->xfont) { - fontname = "fixed"; - font->xfont = XLoadQueryFont(blitz->dpy, fontname); - } - if (!font->xfont) { - fprintf(stderr, "%s", "error, cannot load 'fixed' font\n"); - exit(1); - } - font->ascent = font->xfont->ascent; - font->descent = font->xfont->descent; - } -} |