changeset: 10:2b742ba8094a
tag: tip
user: Connor Lane Smith <cls_AT_lubutu.com>
date: Tue Aug 10 18:08:34 2010 +0100
files: commitdraw.c draw.h initfont.c
description:
improved initfont + style
diff -r ac97f7a70630 -r 2b742ba8094a commitdraw.c
--- a/commitdraw.c Thu Aug 05 15:58:14 2010 +0100
+++ b/commitdraw.c Tue Aug 10 18:08:34 2010 +0100
@@ -3,11 +3,11 @@
#include "draw.h"
void
-commitdraw(DC *dc, Window w)
+commitdraw(DC *dc, Window win)
{
XWindowAttributes wa;
- if(!XGetWindowAttributes(dc->dpy, w, &wa))
+ if(!XGetWindowAttributes(dc->dpy, win, &wa))
eprintf("cannot get window attributes\n");
- XCopyArea(dc->dpy, dc->canvas, w, dc->gc, 0, 0, wa.width, wa.height, 0, 0);
+ XCopyArea(dc->dpy, dc->canvas, win, dc->gc, 0, 0, wa.width, wa.height, 0, 0);
}
diff -r ac97f7a70630 -r 2b742ba8094a draw.h
--- a/draw.h Thu Aug 05 15:58:14 2010 +0100
+++ b/draw.h Tue Aug 10 18:08:34 2010 +0100
@@ -25,10 +25,10 @@
int descent;
int height;
} font;
-} DC; /* draw context */
+} DC; /* draw context */
/* forward declarations */
-void commitdraw(DC *dc, Window w);
+void commitdraw(DC *dc, Window win);
void drawrect(DC *dc, int x, int y, unsigned int w, unsigned int h, unsigned long color);
void drawtext(DC *dc, const char *text, unsigned long col[ColLast]);
void drawtextn(DC *dc, const char *text, size_t n, unsigned long col[ColLast]);
@@ -36,7 +36,7 @@
void freedraw(DC *dc);
unsigned long getcolor(DC *dc, const char *colstr);
DC *initdraw(void);
-void initfont(DC *dc, const char *fontstr);
+void initfont(DC *dc, const char *s);
void setcanvas(DC *dc, unsigned int w, unsigned int h);
int textnw(DC *dc, const char *text, size_t len);
int textw(DC *dc, const char *text);
diff -r ac97f7a70630 -r 2b742ba8094a initfont.c
--- a/initfont.c Thu Aug 05 15:58:14 2010 +0100
+++ b/initfont.c Tue Aug 10 18:08:34 2010 +0100
@@ -5,34 +5,27 @@
#define MAX(a, b) ((a) > (b) ? (a) : (b))
void
-initfont(DC *dc, const char *fontstr) {
+initfont(DC *dc, const char *s) {
+ char *def, **missing, **names;
int i, n;
+ XFontStruct **xfonts;
- dc->font.set = NULL;
- if(fontstr && *fontstr) {
- char *def, **missing;
-
- dc->font.set = XCreateFontSet(dc->dpy, fontstr, &missing, &n, &def);
- if(missing)
- XFreeStringList(missing);
- }
- if(dc->font.set) {
- char **names;
- XFontStruct **xfonts;
-
+ if((s == NULL || *s)
+ && (dc->font.set = XCreateFontSet(dc->dpy, s ? s : "fixed", &missing, &n, &def))) {
n = XFontsOfFontSet(dc->font.set, &xfonts, &names);
- for(i = dc->font.ascent = dc->font.descent = 0; i < n; i++) {
+ dc->font.ascent = dc->font.descent = 0;
+ for(i = 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(fontstr)
- weprintf("cannot load font '%s'\n", fontstr);
- if(!(dc->font.xfont = XLoadQueryFont(dc->dpy, "fixed")))
- eprintf("cannot load font 'fixed'\n");
- dc->font.ascent = dc->font.xfont->ascent;
- dc->font.descent = dc->font.xfont->descent;
+ else if(s) {
+ if(missing)
+ XFreeStringList(missing);
+ weprintf("cannot load font '%s'\n", s);
+ initfont(dc, NULL);
}
- dc->font.height = dc->font.ascent + dc->font.descent;
+ else
+ eprintf("cannot load font 'fixed'\n");
}
Received on Tue Aug 10 2010 - 19:08:38 CEST
This archive was generated by hypermail 2.2.0 : Tue Aug 10 2010 - 19:12:04 CEST