Xinqi Bao's Git
1 /* (C)opyright MMVI-MMVII Anselm R. Garbe <garbeam at gmail dot com>
2 * (C)opyright MMVI-MMVII Sander van Dijk <a dot h dot vandijk at gmail dot com>
3 * See LICENSE file for license details.
11 drawtext(const char *text
, unsigned long col
[ColLast
]) {
14 unsigned int len
, olen
;
16 XRectangle r
= { dc
.x
, dc
.y
, dc
.w
, dc
.h
};
18 XSetForeground(dpy
, dc
.gc
, col
[ColBG
]);
19 XFillRectangles(dpy
, dc
.drawable
, dc
.gc
, &r
, 1);
23 olen
= len
= strlen(text
);
26 memcpy(buf
, text
, len
);
28 h
= dc
.font
.ascent
+ dc
.font
.descent
;
29 y
= dc
.y
+ (dc
.h
/ 2) - (h
/ 2) + dc
.font
.ascent
;
31 /* shorten text if necessary */
32 while(len
&& (w
= textnw(buf
, len
)) > dc
.w
- h
)
43 return; /* too long */
44 gcv
.foreground
= col
[ColFG
];
46 XChangeGC(dpy
, dc
.gc
, GCForeground
, &gcv
);
47 XmbDrawString(dpy
, dc
.drawable
, dc
.font
.set
, dc
.gc
,
51 gcv
.font
= dc
.font
.xfont
->fid
;
52 XChangeGC(dpy
, dc
.gc
, GCForeground
| GCFont
, &gcv
);
53 XDrawString(dpy
, dc
.drawable
, dc
.gc
, x
, y
, buf
, len
);
58 textw(const char *text
) {
59 return textnw(text
, strlen(text
)) + dc
.font
.height
;
63 textnw(const char *text
, unsigned int len
) {
67 XmbTextExtents(dc
.font
.set
, text
, len
, NULL
, &r
);
70 return XTextWidth(dc
.font
.xfont
, text
, len
);