3
/* Get the metrics for a character. */
4
typedef struct gs_point_s {
7
typedef struct gs_int_point_s {
10
typedef struct gs_int_rect_s {
14
int x_char_metrics(XFontStruct* x11font, char chr, gs_point* pwidth, gs_int_rect* pbbox)
16
if (x11font->per_char == NULL) {
17
pwidth->x = x11font->max_bounds.width;
19
pbbox->p.x = x11font->max_bounds.lbearing;
20
pbbox->q.x = x11font->max_bounds.rbearing;
21
pbbox->p.y = -x11font->max_bounds.ascent;
22
pbbox->q.y = x11font->max_bounds.descent;
24
int i = (int)chr - x11font->min_char_or_byte2;
26
pwidth->x = x11font->per_char[i].width;
29
pbbox->p.x = x11font->per_char[i].lbearing;
30
pbbox->q.x = x11font->per_char[i].rbearing;
31
pbbox->p.y = -x11font->per_char[i].ascent;
32
pbbox->q.y = x11font->per_char[i].descent;
37
/* Render a character. */
39
x_render_char(Display* dpy, XFontStruct* x11font, char chr, int xo, int yo)
45
/* Display on an intermediate bitmap, then copy the bits. */
53
code = x_char_metrics(x11font, chr, &wxy, &bbox);
55
w = bbox.q.x - bbox.p.x;
56
h = bbox.q.y - bbox.p.y;
59
xpm = XCreatePixmap(dpy, InputOnly, w, h, 1);
60
fgc = XCreateGC(dpy, xpm, None, NULL);
61
XSetForeground(dpy, fgc, 0);
62
XFillRectangle(dpy, xpm, fgc, 0, 0, w, h);
63
XSetForeground(dpy, fgc, 1);
64
XSetFont(dpy, fgc, x11font->fid);
65
XDrawString(dpy, xpm, fgc, -bbox.p.x, -bbox.p.y, &chr, 1);
66
xim = XGetImage(dpy, xpm, 0, 0, w, h, 1, ZPixmap);
68
for (y = 0; y < h; y++) {
71
for (x = 0; x < w; x++) {
72
b = XGetPixel(xim, x, y);
77
XFreePixmap(dpy, xpm);