commit d18d7c66f8d6eb6e74f87a368b920895f4eed969
parent 70f3dfff77eef6cb5e446299b5b34d581a314a7e
Author: Anselm R. Garbe <garbeam@wmii.de>
Date: Mon, 1 May 2006 23:32:04 +0200
checking locale now in blitz_loadfont (prevents ugly artefacts)
Diffstat:
5 files changed, 62 insertions(+), 25 deletions(-)
diff --git a/cmd/wm/bar.c b/cmd/wm/bar.c
@@ -65,7 +65,7 @@ unsigned int
height_of_bar()
{
enum { BAR_PADDING = 4 };
- return blitzfont.xfont->ascent + blitzfont.xfont->descent + BAR_PADDING;
+ return blitzfont.ascent + blitzfont.descent + BAR_PADDING;
}
void
diff --git a/cmd/wmiimenu.c b/cmd/wmiimenu.c
@@ -358,7 +358,7 @@ main(int argc, char *argv[])
| SubstructureRedirectMask | SubstructureNotifyMask;
mrect.width = DisplayWidth(dpy, screen);
- mrect.height = draw.font.xfont->ascent + draw.font.xfont->descent + 4;
+ mrect.height = draw.font.ascent + draw.font.descent + 4;
mrect.y = DisplayHeight(dpy, screen) - mrect.height;
mrect.x = 0;
diff --git a/liblitz/blitz.h b/liblitz/blitz.h
@@ -4,6 +4,7 @@
*/
#include <X11/Xlib.h>
+#include <X11/Xlocale.h>
#define BLITZ_FONT "fixed"
#define BLITZ_SELCOLORS "#ffffff #285577 #4c7899"
@@ -23,6 +24,8 @@ typedef struct {
typedef struct {
XFontStruct *xfont;
XFontSet set;
+ int ascent;
+ int descent;
} BlitzFont;
typedef struct {
diff --git a/liblitz/draw.c b/liblitz/draw.c
@@ -60,18 +60,27 @@ xdrawtext(Display *dpy, BlitzDraw *d)
unsigned int x = 0, y = 0, w = 1, h = 1, shortened = 0;
unsigned int len = 0;
static char text[2048];
+ XGCValues gcv;
if (!d->data)
return;
len = strlen(d->data);
cext_strlcpy(text, d->data, sizeof(text));
- XSetFont(dpy, d->gc, d->font.xfont->fid);
- h = d->font.xfont->ascent + d->font.xfont->descent;
- y = d->rect.y + d->rect.height / 2 - h / 2 + d->font.xfont->ascent;
+ gcv.foreground = d->color.fg;
+ gcv.background = d->color.bg;
+ if(d->font.set)
+ XChangeGC(dpy, d->gc, GCForeground | GCBackground, &gcv);
+ else {
+ gcv.font = d->font.xfont->fid;
+ XChangeGC(dpy, d->gc, GCForeground | GCBackground | GCFont, &gcv);
+ }
+
+ h = d->font.ascent + d->font.descent;
+ y = d->rect.y + d->rect.height / 2 - h / 2 + d->font.ascent;
/* shorten text if necessary */
- while (len && (w = XTextWidth(d->font.xfont, text, len)) > d->rect.width) {
+ while (len && (w = blitz_textwidth(dpy, &d->font, text)) > d->rect.width) {
text[len - 1] = 0;
len--;
shortened = 1;
@@ -100,8 +109,6 @@ xdrawtext(Display *dpy, BlitzDraw *d)
x = d->rect.x + h / 2;
break;
}
- XSetBackground(dpy, d->gc, d->color.bg);
- XSetForeground(dpy, d->gc, d->color.fg);
if(d->font.set)
XmbDrawString(dpy, d->drawable, d->font.set, d->gc, x, y, text, len);
else
diff --git a/liblitz/font.c b/liblitz/font.c
@@ -6,6 +6,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <locale.h>
#include <cext.h>
#include "blitz.h"
@@ -13,8 +14,8 @@
unsigned int
blitz_textwidth(Display *dpy, BlitzFont *font, char *text)
{
- XRectangle r;
if(font->set) {
+ XRectangle r;
XmbTextExtents(font->set, text, strlen(text), nil, &r);
return r.width;
}
@@ -26,25 +27,51 @@ blitz_loadfont(Display *dpy, BlitzFont *font, char *fontstr)
{
char *fontname = fontstr;
char **missing = nil, *def = "?";
- int nmissing;
+ char *loc = setlocale(LC_ALL, "");
+ int n;
+
if(font->set)
XFreeFontSet(dpy, font->set);
- if(font->xfont)
- XFreeFont(dpy, font->xfont);
- font->xfont = XLoadQueryFont(dpy, fontname);
- if (!font->xfont) {
- fontname = "fixed";
- font->xfont = XLoadQueryFont(dpy, fontname);
- }
- if (!font->xfont) {
- fprintf(stderr, "%s", "liblitz: error, cannot load 'fixed' font\n");
- exit(1);
+ font->set = nil;
+ if(!loc || !strcmp(loc, "C") || !strcmp(loc, "POSIX")|| !XSupportsLocale()) {
+ font->set = XCreateFontSet(dpy, fontname, &missing, &n, &def);
+ if(missing) {
+ while(n--)
+ fprintf(stderr, "liblitz: missing fontset: %s\n", missing[n]);
+ XFreeStringList(missing);
+ }
}
- font->set = XCreateFontSet(dpy, fontname, &missing, &nmissing, &def);
+ if(font->set) {
+ XFontSetExtents *font_extents;
+ XFontStruct **xfonts;
+ char **font_names;
+ unsigned int i;
- if(missing) {
- while(nmissing--)
- fprintf(stderr, "liblitz: missing fontset: %s\n", missing[nmissing]);
- XFreeStringList(missing);
+ 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 = nil;
+ font->xfont = XLoadQueryFont(dpy, fontname);
+ if (!font->xfont) {
+ fontname = "fixed";
+ font->xfont = XLoadQueryFont(dpy, fontname);
+ }
+ if (!font->xfont) {
+ fprintf(stderr, "%s", "liblitz: error, cannot load 'fixed' font\n");
+ exit(1);
+ }
+ font->ascent = font->xfont->ascent;
+ font->descent = font->xfont->descent;
}
}