/* gcc `pkg-config --cflags --libs cairo` testcase-6617.c -o testcase-6617 */ #include #include #include #include /* This is a simple test case for demonstrating cairo bug #6617: * * With cairo 1.0.4, when drawing bitmapped text to xlib backend, * text after the first space does not appear. * https://bugs.freedesktop.org/show_bug.cgi?id=6617 * * As written, this testcase tries to use a bitmapped font named * "snap". If you have a snap.pcf file in a directory searched by * fontconfig, then this should work fine. Otherwise, you can install * this font via a package named "artwiz" or "xfonts-artwiz" or else * substitute a name other than "snap" in the call to * cairo_select_font_face below. */ static void draw (cairo_t *cr, int width, int height) { cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); /* white */ cairo_paint (cr); cairo_move_to (cr, 20, 20); cairo_select_font_face (cr, "snap", 0, 0); cairo_set_font_size (cr, 12); cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* black */ cairo_show_text (cr, "a b"); } static void xlib_draw (Display *dpy, Window window, int width, int height) { cairo_surface_t *surface; cairo_t *cr; surface = cairo_xlib_surface_create (dpy, window, DefaultVisual (dpy, DefaultScreen (dpy)), width, height); cr = cairo_create (surface); draw (cr, width, height); if (cairo_status (cr)) { printf("Cairo is unhappy: %s\n", cairo_status_to_string (cairo_status (cr))); exit(0); } cairo_destroy (cr); cairo_surface_destroy (surface); } static void handle_events(Display *dpy, Window window, int width, int height) { XEvent xev; KeyCode quit_code = XKeysymToKeycode (dpy, XStringToKeysym("Q")); while (1) { XNextEvent (dpy, &xev); switch (xev.type) { case KeyPress: if (xev.xkey.keycode == quit_code) return; break; case ConfigureNotify: width = xev.xconfigure.width; height = xev.xconfigure.height; break; case Expose: if (xev.xexpose.count == 0) xlib_draw (dpy, window, width, height); break; } } } int main (int argc, char *argv[]) { Display *dpy; Window root, window; int width = 400, height = 400; dpy = XOpenDisplay (NULL); if (dpy == NULL) { fprintf(stderr, "Failed to open display %s\n", XDisplayName(NULL)); return 1; } window = XCreateSimpleWindow(dpy, DefaultRootWindow (dpy), 0, 0, width, height, 0, WhitePixel(dpy, DefaultScreen (dpy)), WhitePixel(dpy, DefaultScreen (dpy))); XSelectInput(dpy, window, KeyPressMask | StructureNotifyMask | ExposureMask); XMapWindow (dpy, window); handle_events (dpy, window, width, height); XDestroyWindow (dpy, window); XCloseDisplay (dpy); return 0; }