+ XCharStruct cc;
+ int x1 = xoff + ww * 0.18;
+ int x2 = xoff + ww * 0.82;
+ int x3 = xoff + ww;
+ int pixw, pixh;
+ Pixmap p;
+
+ y = 80;
+ {
+ int h = sc * (ascent + descent);
+ int min = (ascent + descent) * 4;
+ if (h < min) h = min;
+ if (i == 1) h *= 3;
+ y += h;
+ }
+
+ memset (&fake_c, 0, sizeof(fake_c));
+
+ if (!xft_p && i == 0)
+ cc = c;
+ else if (!xft_p && i == 1)
+ cc = overall;
+ else if (xft_p && i == 0)
+ {
+ /* Measure the glyph in the Xft way */
+ XGlyphInfo extents;
+ XftTextExtentsUtf8 (s->dpy,
+ s->metrics_xftfont,
+ (FcChar8 *) utxt, strlen(utxt),
+ &extents);
+ XGlyphInfo_to_XCharStruct (extents, fake_c);
+ cc = fake_c;
+ }
+ else if (xft_p)
+ {
+ /* Measure the glyph in the 16-bit way */
+ int dir, ascent, descent;
+ XTextExtents16 (s->metrics_font1, txt3, 1, &dir, &ascent, &descent,
+ &fake_c);
+ cc = fake_c;
+ }
+
+ pixw = margin * 2 + cc.rbearing - cc.lbearing;
+ pixh = margin * 2 + cc.ascent + cc.descent;
+ p = (pixw > 0 && pixh > 0
+ ? XCreatePixmap (s->dpy, dest, pixw, pixh, s->xgwa.depth)
+ : 0);
+
+ if (p)
+ {
+ Pixmap p2;
+ GC gc2 = XCreateGC (s->dpy, p, 0, 0);
+# ifdef HAVE_JWXYZ
+ jwxyz_XSetAntiAliasing (s->dpy, gc2, False);
+# endif
+ XSetFont (s->dpy, gc2, s->metrics_font1->fid);
+ XSetForeground (s->dpy, gc2, BlackPixelOfScreen (s->xgwa.screen));
+ XFillRectangle (s->dpy, p, gc2, 0, 0, pixw, pixh);
+ XSetForeground (s->dpy, gc, WhitePixelOfScreen (s->xgwa.screen));
+ XSetForeground (s->dpy, gc2, WhitePixelOfScreen (s->xgwa.screen));
+# ifdef HAVE_JWXYZ
+ jwxyz_XSetAntiAliasing (s->dpy, gc2,
+ s->debug_metrics_antialiasing_p);
+# endif
+
+ if (xft_p && i == 0)
+ {
+ XftDraw *xftdraw2 = XftDrawCreate (s->dpy, p, s->xgwa.visual,
+ s->xgwa.colormap);
+ XftDrawStringUtf8 (xftdraw2, &xftcolor,
+ s->metrics_xftfont,
+ -cc.lbearing + margin,
+ cc.ascent + margin,
+ (FcChar8 *) utxt, strlen(utxt));
+ XftDrawDestroy (xftdraw2);
+ }
+ else if (xft_p)
+ XDrawString16 (s->dpy, p, gc2,
+ -cc.lbearing + margin,
+ cc.ascent + margin,
+ txt3, 1);
+ else
+ XDrawString (s->dpy, p, gc2,
+ -cc.lbearing + margin,
+ cc.ascent + margin,
+ txt, strlen(txt));
+
+ {
+ unsigned x2, y2;
+ XImage *img = XGetImage (s->dpy, p, 0, 0, pixw, pixh,
+ ~0L, ZPixmap);
+ XImage *img2;
+
+ if (i == 1)
+ {
+ unsigned w = pixw - margin * 2, h = pixh - margin * 2;
+
+ if (margin > 0)
+ {
+ /* Check for ink escape. */
+ unsigned long ink = 0;
+ for (y2 = 0; y2 != pixh; ++y2)
+ for (x2 = 0; x2 != pixw; ++x2)
+ {
+ /* Sloppy... */
+ if (! (x2 >= margin &&
+ x2 < pixw - margin &&
+ y2 >= margin &&
+ y2 < pixh - margin))
+ ink |= XGetPixel (img, x2, y2);
+ }
+
+ if (ink & 0xFFFFFF)
+ {
+ XSetFont (s->dpy, gc, s->metrics_font2->fid);
+ XDrawString (s->dpy, dest, gc,
+ xoff + 10, 40,
+ "Ink escape!", 11);
+ }
+ }
+
+ /* ...And wasted space. */
+ if (w && h)
+ {
+ if (check_edge (s->dpy, dest, gc, 120, 60, "left",
+ img, margin, margin, 1, h) |
+ check_edge (s->dpy, dest, gc, 160, 60, "right",
+ img, margin + w - 1, margin, 1, h) |
+ check_edge (s->dpy, dest, gc, 200, 60, "top",
+ img, margin, margin, 0, w) |
+ check_edge (s->dpy, dest, gc, 240, 60, "bottom",
+ img, margin, margin + h - 1, 0, w))
+ {
+ XSetFont (s->dpy, gc, s->metrics_font2->fid);
+ XDrawString (s->dpy, dest, gc,
+ xoff + 10, 60,
+ "Wasted space: ", 14);
+ }
+ }
+ }
+
+ if (s->debug_metrics_antialiasing_p)
+ {
+ /* Draw a dark cyan boundary around antialiased glyphs */
+ img2 = XCreateImage (s->dpy, s->xgwa.visual, img->depth,
+ ZPixmap, 0, NULL,
+ img->width, img->height,
+ img->bitmap_pad, 0);
+ img2->data = malloc (img->bytes_per_line * img->height);
+
+ for (y2 = 0; y2 != pixh; ++y2)
+ for (x2 = 0; x2 != pixw; ++x2)
+ {
+ unsigned long px = XGetPixel (img, x2, y2);
+ if ((px & 0xffffff) == 0)
+ {
+ unsigned long neighbors = 0;
+ if (x2)
+ neighbors |= XGetPixel (img, x2 - 1, y2);
+ if (x2 != pixw - 1)
+ neighbors |= XGetPixel (img, x2 + 1, y2);
+ if (y2)
+ neighbors |= XGetPixel (img, x2, y2 - 1);
+ if (y2 != pixh - 1)
+ neighbors |= XGetPixel (img, x2, y2 + 1);
+ XPutPixel (img2, x2, y2,
+ (neighbors & 0xffffff
+ ? cyan
+ : BlackPixelOfScreen (s->xgwa.screen)));
+ }
+ else
+ {
+ XPutPixel (img2, x2, y2, px);
+ }
+ }
+ }
+ else
+ {
+ img2 = img;
+ img = NULL;
+ }
+
+ p2 = scale_ximage (s->xgwa.screen, s->window, img2, sc, margin);
+ if (img)
+ XDestroyImage (img);
+ XDestroyImage (img2);
+ }
+
+ XCopyArea (s->dpy, p2, dest, gc,
+ 0, 0, sc*pixw, sc*pixh,
+ xoff + x + sc * (cc.lbearing - margin),
+ y - sc * (cc.ascent + margin));
+ XFreePixmap (s->dpy, p);
+ XFreePixmap (s->dpy, p2);
+ XFreeGC (s->dpy, gc2);
+ }
+
+ if (i == 0)
+ {
+ XSetFont (s->dpy, gc, s->metrics_font1->fid);
+ XSetForeground (s->dpy, gc, WhitePixelOfScreen (s->xgwa.screen));
+# ifdef HAVE_JWXYZ
+ jwxyz_XSetAntiAliasing (s->dpy, gc, s->debug_metrics_antialiasing_p);
+# endif
+ sprintf (txt2, "%s [XX%sXX] [%s%s%s%s]",
+ (xft_p ? utxt : txt),
+ (xft_p ? utxt : txt),
+ (xft_p ? utxt : txt),
+ (xft_p ? utxt : txt),
+ (xft_p ? utxt : txt),
+ (xft_p ? utxt : txt));
+
+ if (xft_p)
+ XftDrawStringUtf8 (xftdraw, &xftcolor,
+ s->metrics_xftfont,
+ xoff + x/2 + (sc*cc.rbearing/2) - cc.rbearing/2
+ + 40,
+ ascent + 10,
+ (FcChar8 *) txt2, strlen(txt2));
+ else
+ XDrawString (s->dpy, dest, gc,
+ xoff + x/2 + (sc*cc.rbearing/2) - cc.rbearing/2,
+ ascent + 10,
+ txt2, strlen(txt2));
+# ifdef HAVE_JWXYZ
+ jwxyz_XSetAntiAliasing (s->dpy, gc, False);
+# endif
+ XSetFont (s->dpy, gc, s->metrics_font2->fid);
+ if (xft_p)
+ {
+ char *uptr;
+ char *tptr = txt2 + sprintf(txt2, "U+%04lX", s->debug_metrics_p);
+ *tptr++ = " ?_"[s->entering_unicode_p];
+ *tptr++ = ' ';
+
+ uptr = utxt;
+ while (*uptr)
+ {
+ tptr += sprintf (tptr, "0%03o ", (unsigned char) *uptr);
+ ++uptr;
+ }
+ *tptr++ = ' ';
+ uptr = utxt;
+ while (*uptr)
+ {
+ tptr += sprintf (tptr, "%02x ", (unsigned char) *uptr);
+ ++uptr;
+ }
+ }
+ else
+ sprintf (txt2, "%c %3ld 0%03lo 0x%02lx%s",
+ (char)s->debug_metrics_p, s->debug_metrics_p,
+ s->debug_metrics_p, s->debug_metrics_p,
+ (txt[0] < s->metrics_font1->min_char_or_byte2
+ ? " *" : ""));
+ XDrawString (s->dpy, dest, gc,
+ xoff + 10, 20,
+ txt2, strlen(txt2));
+ }
+
+# ifdef HAVE_JWXYZ
+ jwxyz_XSetAntiAliasing (s->dpy, gc, True);
+# endif
+
+ {
+ const char *ss = (j == 0
+ ? (i == 0 ? "char" : "overall")
+ : (i == 0 ? "utf8" : "16 bit"));
+ XSetFont (s->dpy, gc, s->metrics_font2->fid);
+
+ XSetForeground (s->dpy, gc, red);
+
+ sprintf (txt2, "%s ascent %d", ss, ascent);
+ XDrawString (s->dpy, dest, gc,
+ xoff + 10,
+ y - sc*ascent - 2,
+ txt2, strlen(txt2));
+ XDrawLine (s->dpy, dest, gc,
+ xoff, y - sc*ascent,
+ x3, y - sc*ascent);
+
+ sprintf (txt2, "%s descent %d", ss, descent);
+ XDrawString (s->dpy, dest, gc,
+ xoff + 10,
+ y + sc*descent - 2,
+ txt2, strlen(txt2));
+ XDrawLine (s->dpy, dest, gc,
+ xoff, y + sc*descent,
+ x3, y + sc*descent);
+ }
+