+static int x11font_width_8(unifont_drawctx *ctx, x11font_individual *xfi,
+ const void *vstring, int start, int length)
+{
+ const char *string = (const char *)vstring;
+ return XTextWidth(xfi->xfs, string+start, length);
+}
+
+#ifdef DRAW_TEXT_GDK
+static void x11font_gdk_setup(unifont_drawctx *ctx, x11font_individual *xfi)
+{
+ Display *disp = GDK_DISPLAY_XDISPLAY(gdk_display_get_default());
+ XSetFont(disp, GDK_GC_XGC(ctx->u.gdk.gc), xfi->xfs->fid);
+}
+
+static void x11font_gdk_draw_16(unifont_drawctx *ctx,
+ x11font_individual *xfi, int x, int y,
+ const void *vstring, int start, int length)
+{
+ Display *disp = GDK_DISPLAY_XDISPLAY(gdk_display_get_default());
+ const XChar2b *string = (const XChar2b *)vstring;
+ XDrawString16(disp, GDK_DRAWABLE_XID(ctx->u.gdk.target),
+ GDK_GC_XGC(ctx->u.gdk.gc), x, y, string+start, length);
+}
+
+static void x11font_gdk_draw_8(unifont_drawctx *ctx,
+ x11font_individual *xfi, int x, int y,
+ const void *vstring, int start, int length)
+{
+ Display *disp = GDK_DISPLAY_XDISPLAY(gdk_display_get_default());
+ const char *string = (const char *)vstring;
+ XDrawString(disp, GDK_DRAWABLE_XID(ctx->u.gdk.target),
+ GDK_GC_XGC(ctx->u.gdk.gc), x, y, string+start, length);
+}
+#endif
+
+#ifdef DRAW_TEXT_CAIRO
+static void x11font_cairo_setup(unifont_drawctx *ctx, x11font_individual *xfi)
+{
+ if (xfi->pixmap == None) {
+ Display *disp = GDK_DISPLAY_XDISPLAY(gdk_display_get_default());
+ XGCValues gcvals;
+ GdkWindow *widgetwin = gtk_widget_get_window(ctx->u.cairo.widget);
+ int widgetscr = GDK_SCREEN_XNUMBER(gdk_window_get_screen(widgetwin));
+
+ xfi->pixwidth =
+ xfi->xfs->max_bounds.rbearing - xfi->xfs->min_bounds.lbearing;
+ xfi->pixheight =
+ xfi->xfs->max_bounds.ascent + xfi->xfs->max_bounds.descent;
+ xfi->pixoriginx = -xfi->xfs->min_bounds.lbearing;
+ xfi->pixoriginy = xfi->xfs->max_bounds.ascent;
+
+ xfi->rowsize = cairo_format_stride_for_width(CAIRO_FORMAT_A1,
+ xfi->pixwidth);
+ xfi->allsize = xfi->rowsize * xfi->pixheight;
+
+ {
+ /*
+ * Test host endianness and use it to set xfi->indexflip,
+ * which is XORed into our left-shift counts in order to
+ * implement the CAIRO_FORMAT_A1 specification, in which
+ * each bitmap byte is oriented LSB-first on little-endian
+ * platforms and MSB-first on big-endian ones.
+ *
+ * This is the same technique Cairo itself uses to test
+ * endianness, so hopefully it'll work in any situation
+ * where Cairo is usable at all.
+ */
+ static const int endianness_test = 1;
+ xfi->indexflip = (*((char *) &endianness_test) == 1) ? 0 : 7;
+ }
+
+ xfi->pixmap = XCreatePixmap
+ (disp,
+ GDK_DRAWABLE_XID(gtk_widget_get_window(ctx->u.cairo.widget)),
+ xfi->pixwidth, xfi->pixheight, 1);
+ gcvals.foreground = WhitePixel(disp, widgetscr);
+ gcvals.background = BlackPixel(disp, widgetscr);
+ gcvals.font = xfi->xfs->fid;
+ xfi->gc = XCreateGC(disp, xfi->pixmap,
+ GCForeground | GCBackground | GCFont, &gcvals);