+ int pixw = margin * 2 + cc.rbearing - cc.lbearing;
+ int pixh = margin * 2 + cc.ascent + cc.descent;
+ Pixmap 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_COCOA
+ jwxyz_XSetAntiAliasing (s->dpy, gc2, False);
+# endif
+ XSetFont (s->dpy, gc2, font->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_COCOA
+ jwxyz_XSetAntiAliasing (s->dpy, gc2, s->debug_metrics_antialiasing_p);
+# endif
+ 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, font2->fid);
+ XDrawString (s->dpy, dest, gc, 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, font2->fid);
+ XDrawString (s->dpy, dest, gc, 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,
+ 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, font->fid);
+ XSetForeground (s->dpy, gc, WhitePixelOfScreen (s->xgwa.screen));
+# ifdef HAVE_COCOA
+ jwxyz_XSetAntiAliasing (s->dpy, gc, s->debug_metrics_antialiasing_p);
+# endif
+ sprintf (txt2, "%c [XX%cXX] [%c%c%c%c]",
+ s->debug_metrics_p, s->debug_metrics_p,
+ s->debug_metrics_p, s->debug_metrics_p,
+ s->debug_metrics_p, s->debug_metrics_p);
+ XDrawString (s->dpy, dest, gc,
+ x + (sc*cc.rbearing/2) - cc.rbearing/2, ascent + 10,
+ txt2, strlen(txt2));
+# ifdef HAVE_COCOA
+ jwxyz_XSetAntiAliasing (s->dpy, gc, False);
+# endif
+ XSetFont (s->dpy, gc, font2->fid);
+ sprintf (txt2, "%c %3d 0%03o 0x%02x%s",
+ s->debug_metrics_p, s->debug_metrics_p,
+ s->debug_metrics_p, s->debug_metrics_p,
+ (txt[0] < font->min_char_or_byte2 ? " *" : ""));
+ XDrawString (s->dpy, dest, gc,
+ 10, 20,
+ txt2, strlen(txt2));
+ }
+
+# ifdef HAVE_COCOA
+ jwxyz_XSetAntiAliasing (s->dpy, gc, True);
+# endif
+
+ XSetFont (s->dpy, gc, font2->fid);
+