[cairo] X11 v. XQuartz

Jennifer Adams jma at cola.iges.org
Thu Aug 8 11:00:55 PDT 2013

Follow up: 
I wrote a short C program to demonstrate the problem. It works with X11, and reliably fails with XQuartz (the rendering is incomplete). I realize this is probably an issue for the XQuartz folks, but before I go there, it would be nice to rule out incorrect Cairo code. The results are the same whether I compile and run my demo on my laptop or on a remote linux server that I connect to using ssh. I updated the images in the links given in my first message. 

for compiling on a mac:
gcc -Wall -g xdemo.c -o xdemo -I/opt/local/include/cairo -L/opt/local/lib  -lcairo -lX11

for compiling on linux server (CentOS 5.9):
gcc -Wall -g xdemo.c -o xdemo -I/usr/include/cairo -L/usr/lib64  -lcairo -lX11

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <cairo.h>
#include <cairo-xlib.h>

int main () {
  Display *display = (Display *)NULL; 
  XEvent xev;
  KeyCode quit;
  Window win;
  Visual *visual;
  cairo_surface_t *surface;
  cairo_t *cr;
  int snum,flag,r,a;
  double x,y,x0,y0,c;

  /* Create X window */
  display = XOpenDisplay(0);
  snum = DefaultScreen(display);
  win = XCreateSimpleWindow(display, RootWindow(display,snum),100, 0, 500, 500, 4,
			    BlackPixel(display,snum), WhitePixel(display,snum));

  /* Set event type 'Q' for quit */
  quit = XKeysymToKeycode(display, XStringToKeysym("Q"));
  XSelectInput(display, win, KeyPressMask|StructureNotifyMask|ExposureMask);
  /* Display Window */
  XMapWindow(display, win);

  /* Wait for the expose event that indicates window is up */
  while (flag)  {
    switch  (xev.type) {
    case Expose:
      if (xev.xexpose.count != 0) break;
      else flag = 0;

  /* create the cairo surface */
  visual = DefaultVisual(display,snum);
  surface = cairo_xlib_surface_create (display, win, visual, 500, 500);
  cr = cairo_create(surface);

  /* say hello */
  cairo_set_source_rgb(cr, 0, 0, 0);
  cairo_select_font_face (cr, "sans-serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
  cairo_set_font_size (cr, 32);
  cairo_move_to (cr, 10, 42);
  cairo_show_text (cr, "Hello!");

  /* draw concentric circles made up of tiny line segments */
  for (r=10; r<=240; r+=10) {
    cairo_set_source_rgb(cr, c, c, c);
    for (a=0; a<360; a++) {
      x = 250 + r*cos((double)(a)*3.14159/180.0);
      y = 250 + r*sin((double)(a)*3.14159/180.0);
      if (a==0) {
	x0 = x;
	y0 = y;
	cairo_move_to(cr, x, y);
	cairo_line_to(cr, x, y);

  /* wait for user to hit 'Q'  ... */
  while (1) {
    XNextEvent(display, &xev);
    switch(xev.type) {
    case KeyPress:
	XKeyEvent *kev = &xev.xkey;
	if (kev->keycode == quit) return 0;
  return 0;

On Aug 6, 2013, at 5:13 PM, Jennifer Adams wrote:

> Dear Experts,
> I am a developer of GrADS, a visualization tool for meteorological data. GrADS uses X11 for its interactive display window, but it also has a batch mode, so you can create graphics without the use of X. We have developed an interface for Cairo to do the rendering, not only to the X window, but also to create png, ps, eps, pdf, and svg output. 
> The problem I am having is with the X rendering when using XQuartz. Everything looks right when I use the old (deprecated) X11 application on my Mac, but if I use XQuartz, I get an incomplete rendering, illustrated by two screen shots (links are given below.) The graphical elements are very basic, these plots contain nothing but line segments and filled rectangles. 
> http://iges.org/jma/x11.png
> http://iges.org/jma/xquartz.png
> The batch-mode renderings by Cairo are correct, and the non-Cairo version of GrADS does not exhibit the problem with the X window display, so I am pretty sure that Cairo and XQuartz are not playing well together. 
> I am running Mac OS X 10.7.5. When running the old X11 application, the version information in the "About X11" window says: XQuartz 2.6.5 (xorg-server 1.10.6). When running XQuartz, the version numbers are more recent: XQuartz 2.7.4 (xorg-server 1.13.0). The Cairo version is 1.12.8.
> I searched through my 2-yr archive of forum emails and found nothing related to rendering problems with XQuartz. Any suggestions or ideas about what might be going wrong would be most welcome. 
> --Jennifer
> --
> Jennifer M. Adams
> Center for Ocean-Land-Atmosphere Studies (COLA)
> 111 Research Hall, Mail Stop 2B3
> George Mason University
> 4400 University Drive
> Fairfax, VA 22030 
> -- 
> cairo mailing list
> cairo at cairographics.org
> http://lists.cairographics.org/mailman/listinfo/cairo

Jennifer M. Adams
Center for Ocean-Land-Atmosphere Studies (COLA)
111 Research Hall, Mail Stop 2B3
George Mason University
4400 University Drive
Fairfax, VA 22030 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cairographics.org/archives/cairo/attachments/20130808/d0f87745/attachment-0001.html>

More information about the cairo mailing list