Ghostscript rendering to GdkPixmap


I wrote a function which gets Ghostscript rendering to a GdkPixmap:

GdkPixmap *gdk_ps_pixmap_new(GdkWindow *window,
    gint width, gint height, gint depth)
  GdkPixmap *gs_pix;
  GdkAtom gs_atom, type_atom;

  Window xwin;
  Pixmap pixm;

  pid_t gs_pid;
  char buf[1024];

  /* a standard GdkPixmap */
  gs_pix = gdk_pixmap_new(window, width, height, depth);

  /* setting the GHOSTVIEW property */
  sprintf(buf, "%ld %d %d %d %d %d %g %g %d %d %d %d",
      0L, 0, 0, 0, 300, 200, 72., 72., 0, 0, 0, 0);
  gs_atom = gdk_atom_intern("GHOSTVIEW", FALSE);
  type_atom = gdk_atom_intern("STRING", FALSE);
  gdk_property_change(window, gs_atom, type_atom, 8,
      GDK_PROP_MODE_REPLACE, buf, strlen(buf));

  /* setting up the connections to Xlib */
  xwin = GDK_WINDOW_XWINDOW(window);
  pixm = GDK_WINDOW_XWINDOW(gs_pix);

  sprintf(buf, "GHOSTVIEW='%ld %ld' gs -dNOPLATFONTS -dQUIET "
      "-sDEVICE=x11alpha -dNOPAUSE test.eps -c quit", xwin, pixm);

  /* launch ghostscript */
  switch(gs_pid = fork()) {
    case -1:
      /* ouch, fork() failed */

    case 0:
      /* child */
      execl("/bin/sh", "sh", "-c", buf, NULL);

  waitpid(gs_pid, NULL, 0);
  return gs_pix;

This works fine. The only problem is that this functions returns after
Ghostscript has terminated. How can I get it to render the pixmap in the
background? Whithout waitpid() it isnt't working.

Second question: why is this gdk_flush() required? Is gdk somehow

A full example is at

Another question: how can i avoid signal handlers like this one:

void exit_handler(int signum)

I think that gtk_main_quit() is not signal save.



Beat Zahnd
Physikalisches Institut
University of Bern                   phone  ++41 31 631 34 66
Sidlerstrasse 5                      fax    ++41 31 631 44 05
CH-3012 Bern (Switzerland)    mailto:beat zahnd phim unibe ch

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]