+ {
+ 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);
+ }
+
+
+ /* ascent, descent, baseline */