Ghostscript rendering to GdkPixmap



Hello,

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

----code----
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));
  gdk_flush();

  /* 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 */
      perror("fork");
      exit(1);
      break;

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

  waitpid(gs_pid, NULL, 0);
  return gs_pix;
}
----code----

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
buffered?

A full example is at http://www.phim.unibe.ch/~bzahnd/master.c


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

----code----
void exit_handler(int signum)
{
  gtk_main_quit();
}
----code----

I think that gtk_main_quit() is not signal save.


Greetings,

Beat

-- 
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

        http://www.phim.unibe.ch/rosina/rosina.html
                 http://rosetta.esa.int/




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