+static unsigned long
+fontglide_draw_metrics (state *s)
+{
+ char txt[2];
+ char *fn = (s->font_override ? s->font_override : "fixed");
+ XFontStruct *font = XLoadQueryFont (s->dpy, fn);
+ XCharStruct c, overall;
+ int dir, ascent, descent;
+ int x, y;
+ GC gc;
+ unsigned long red = 0xFFFF0000; /* so shoot me */
+ unsigned long green = 0xFF00FF00;
+ unsigned long blue = 0xFF6666FF;
+ int i;
+
+ txt[0] = s->debug_metrics_p;
+ txt[1] = 0;
+
+ gc = XCreateGC (s->dpy, s->window, 0, 0);
+ XSetFont (s->dpy, gc, font->fid);
+
+#ifdef HAVE_COCOA
+ jwxyz_XSetAntiAliasing (s->dpy, gc, False);
+#endif
+
+ XTextExtents (font, txt, strlen(txt),
+ &dir, &ascent, &descent, &overall);
+ c = font->per_char[((unsigned char *) txt)[0] - font->min_char_or_byte2];
+
+ XClearWindow (s->dpy, s->window);
+
+ x = (s->xgwa.width - overall.width) / 2;
+ y = (s->xgwa.height - (2 * (ascent + descent))) / 2;
+
+ for (i = 0; i < 2; i++)
+ {
+ XCharStruct cc = (i == 0 ? c : overall);
+ int x1 = 20;
+ int x2 = s->xgwa.width - 40;
+ int x3 = s->xgwa.width;
+
+ XSetForeground (s->dpy, gc, red);
+ XDrawLine (s->dpy, s->window, gc, 0, y - ascent, x3, y - ascent);
+ XDrawLine (s->dpy, s->window, gc, 0, y + descent, x3, y + descent);
+
+ XSetForeground (s->dpy, gc, green);
+ /* ascent, baseline, descent */
+ XDrawLine (s->dpy, s->window, gc, x1, y - cc.ascent, x2, y - cc.ascent);
+ XDrawLine (s->dpy, s->window, gc, x1, y, x2, y);
+ XDrawLine (s->dpy, s->window, gc, x1, y + cc.descent, x2, y + cc.descent);
+
+ /* origin, width */
+ XSetForeground (s->dpy, gc, blue);
+ XDrawLine (s->dpy, s->window, gc,
+ x, y - ascent - 10,
+ x, y + descent + 10);
+ XDrawLine (s->dpy, s->window, gc,
+ x + cc.width, y - ascent - 10,
+ x + cc.width, y + descent + 10);
+
+ /* lbearing, rbearing */
+ XSetForeground (s->dpy, gc, green);
+ XDrawLine (s->dpy, s->window, gc,
+ x + cc.lbearing, y - ascent,
+ x + cc.lbearing, y + descent);
+ XDrawLine (s->dpy, s->window, gc,
+ x + cc.rbearing, y - ascent,
+ x + cc.rbearing, y + descent);
+
+ XSetForeground (s->dpy, gc, WhitePixelOfScreen (s->xgwa.screen));
+ XDrawString (s->dpy, s->window, gc, x, y, txt, strlen(txt));
+
+ y += (ascent + descent) * 2;
+ }
+
+ XFreeGC (s->dpy, gc);
+ XFreeFont (s->dpy, font);
+ return s->frame_delay;
+}
+
+