Printing lines, shapes and pixmaps from a gnome canvas



Hi,

I have already sent a first (but incomplete) message ten days ago, but it does not appears in the archives, so I suppose it has not been delivered. If the two messages are delivered, don't take the other one into account.

I am currently working on adding a print function to the Gnome Canvas,
so that when a canvas has been filled, a simple call to
gnome_canvas_print(canvas, pc) will print it (it must fit on one page).

Typically, the code in the application will be (canvas is a GnomeCanvas* and pc a GnomePrintContext*):

gdouble matrix[6] = {1.0, 0.0, 0.0, -1.0, PageHeight - MarginTop, MarginLeft}; /*-1.0 necessary because of differing coordinates systems*/
   gnome_print_beginpage (pc, (const guchar*)"");
   gnome_print_concat (pc, matrix);
   gnome_canvas_print (canvas, pc);
   gnome_print_showpage (pc);


I have advanced with lines and shapes. It works in most cases, but some
problems remain:

    * there is apparently nothing corresponding to GDK_CAP_PROJECTING in
      libgnomeprint. I have no opinion about where the correspondig code
      should go (libgnomecanvas or libgnomeprint) or even if it's worth
      the effort;

    * no stipple support in libgnomeprint. Stipples seem to be used by
      someones  to add a transparency in an non-aa canvas, so it is
      possible to  use gnome_print_setopacity. May be more should be done.

    * I am not sure about dashes. I use gnome_print_setdash when the
      style is GDK_LINE_ON_OFF_DASH. The result is not exactly the same
      on paper and on the screen, but I effectively obtain a dashed
      line. I also tried GDK_LINE_DOUBLEDASH, but I obtain a solid line
      on my screen, so I don't know what to do with that.

With pixmaps, I encountered more problems.

When I first tried, pixmaps did not appeared in the preview. I could trace the problem to the -1 in the transform matrix (note that it works with gnome-print-0.x!). I tried to work around this by changing the rowstride argument in gnome_print_rgbimage to its negative counterpart but it does not work because the function fails if rowstride is less than 3. I finally realized that inversing the pixmap was not necessary, so now, I wrote this code:
   gnome_print_translate (pc, priv->x, priv->y + priv->height);
   gnome_print_scale (pc, priv->width, - priv->height);
   if (gdk_pixbuf_get_has_alpha (priv->pixbuf))
       gnome_print_rgbaimage (pc, gdk_pixbuf_get_pixels(priv->pixbuf),
                               gdk_pixbuf_get_width(priv->pixbuf),
                               gdk_pixbuf_get_height(priv->pixbuf),
                               gdk_pixbuf_get_rowstride(priv->pixbuf));
   else
       gnome_print_rgbimage (pc, gdk_pixbuf_get_pixels(priv->pixbuf),
                               gdk_pixbuf_get_width(priv->pixbuf),
                               gdk_pixbuf_get_height(priv->pixbuf),
                               gdk_pixbuf_get_rowstride(priv->pixbuf));
It works for preview, but if I try to really print (the primitives page in canvas_demo), the programs did nothing for about four minutes and the stopped. The messages are (4 min betwwen the two messages):

   Printing to Postscript...
   Process halted

with strace, things end with:

   brk(0x19853000)                         = 0x19853000
   brk(0x19854000)                         = 0x19854000
   brk(0x19855000)                         = 0x19855000
   brk(0x19856000)                         = 0x19856000
   brk(0x19857000)                         = 0x19857000
+++ killed by SIGKILL +++

I tried several modifications. If only one pixmap and an ellipse are left in the page, strace does not write anything after some time and the program never ends. This might be (and probably is) an infinite loop. It occurs only when printing a RGBA pixbuf to Postscript when shapes (not rectangles) are present. Everything works correctly with RGB pixbufs.

What other things remain to be done?
* Widgets items: I don't know if it is interesting to print widgets, or even if it is possible; copying a drawable into a pixmap to print it later only works if the widget is visible on the screen (if I have correctly understood the docs). * Text and Rich text items: these use PangoLayout and there has been some discussion about PangoLayout printing recently int this list, so I'll wait for it to be done (or may be I can participate with my poor competencies?).

Current state of the code is available upon request.

Best regards,

Jean Bréfort






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