[hackers] [libdraw] initfont in case X lacks locale support || Connor Lane Smith

From: <hg_AT_suckless.org>
Date: Tue, 10 Aug 2010 17:43:22 +0000 (UTC)

changeset: 11:671b9e7831f7
tag: tip
user: Connor Lane Smith <cls_AT_lubutu.com>
date: Tue Aug 10 18:43:18 2010 +0100
files: initfont.c
description:
initfont in case X lacks locale support

diff -r 2b742ba8094a -r 671b9e7831f7 initfont.c
--- a/initfont.c Tue Aug 10 18:08:34 2010 +0100
+++ b/initfont.c Tue Aug 10 18:43:18 2010 +0100
@@ -2,30 +2,40 @@
 #include <X11/Xlib.h>
 #include "draw.h"
 
+#define DEFAULT "fixed"
 #define MAX(a, b) ((a) > (b) ? (a) : (b))
 
 void
 initfont(DC *dc, const char *s) {
- char *def, **missing, **names;
         int i, n;
- XFontStruct **xfonts;
 
- if((s == NULL || *s)
- && (dc->font.set = XCreateFontSet(dc->dpy, s ? s : "fixed", &missing, &n, &def))) {
+ dc->font.set = NULL;
+ if(s == NULL || *s) {
+ char *def, **missing;
+
+ dc->font.set = XCreateFontSet(dc->dpy, s ? s : DEFAULT, &missing, &n, &def);
+ if(missing)
+ XFreeStringList(missing);
+ }
+ if(dc->font.set) {
+ char **names;
+ XFontStruct **xfonts;
+
                 n = XFontsOfFontSet(dc->font.set, &xfonts, &names);
- dc->font.ascent = dc->font.descent = 0;
- for(i = 0; i < n; i++) {
+ for(i = dc->font.ascent = dc->font.descent = 0; i < n; i++) {
                         dc->font.ascent = MAX(dc->font.ascent, xfonts[i]->ascent);
                         dc->font.descent = MAX(dc->font.descent, xfonts[i]->descent);
                 }
- dc->font.height = dc->font.ascent + dc->font.descent;
         }
- else if(s) {
- if(missing)
- XFreeStringList(missing);
+ else if(s != NULL) {
                 weprintf("cannot load font '%s'\n", s);
                 initfont(dc, NULL);
         }
- else
- eprintf("cannot load font 'fixed'\n");
+ else {
+ if(!(dc->font.xfont = XLoadQueryFont(dc->dpy, DEFAULT)))
+ eprintf("cannot load fallback font\n");
+ dc->font.ascent = dc->font.xfont->ascent;
+ dc->font.descent = dc->font.xfont->descent;
+ }
+ dc->font.height = dc->font.ascent + dc->font.descent;
 }
Received on Tue Aug 10 2010 - 19:43:22 CEST

This archive was generated by hypermail 2.2.0 : Tue Aug 10 2010 - 19:48:04 CEST