/* gcc `pkg-config --cflags --libs cairo` testcase-7494.c -o testcase-7494 */ #include #include #include #include /* This is a simple test case for demonstrating cairo bug #7494: * * With cairo 1.2.0, non-antialiased xlib text doesn't appear after first space * https://bugs.freedesktop.org/show_bug.cgi?id=7494 * * This testcase simply uses the default font, but disables * antialiasing to demonstrate bug #7494. The correct behavior would * be for both of the characters "a" and "b" to appear. The buggy * behavior is that only the character "a" appears. */ static void draw (cairo_t *cr, int width, int height) { cairo_font_options_t *font_options; cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); /* white */ cairo_paint (cr); cairo_move_to (cr, 20, 20); cairo_set_font_size (cr, 12); font_options = cairo_font_options_create (); cairo_font_options_set_antialias (font_options, CAIRO_ANTIALIAS_NONE); cairo_set_font_options (cr, font_options); 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; }