[cairo] Paginating a png image.

Gerdus van Zyl gerdusvanzyl at gmail.com
Thu Nov 26 23:19:32 PST 2009


I think you need to keep the rectangle the same:
cairo_rectangle (cr, 0.0, 0.0, (double)width, (double)page_height);

and move the offset to the source:
cairo_set_source_surface (cr, the_surface, 0.0,
(double)page_height*page_nr); //the y could also be negative can't
remember

~G

On Thu, Nov 26, 2009 at 8:59 PM, Richard Shann <richard.shann at virgin.net> wrote:
> I am trying to print a .png image which is created by an external
> application as several pages abutted vertically. (That is the width is
> the width of A4 paper, the height is number_pages * the height of A4).
>
> I am using the GtkPrintOperation, and can get the first page, but the
> subsequent pages are (largely) blank.
>
> In the callback for the begin-print I set up the cairo surface
> and compute the number of pages from by scaling by 842/595 which is A4
> aspect ratio.
>
>  the_surface = cairo_image_surface_create_from_png (image.png);
>  int src_width = cairo_image_surface_get_width(the_surface);
>  int src_height = cairo_image_surface_get_height(the_surface);
>
>  int width = 595;
>  int height = 842;
>  int page_height =  height*((double)src_width)/width;
>  int num_pages = src_height/page_height;
>  gtk_print_operation_set_n_pages (operation, num_pages);
>
> Then with the draw-page callback I try to take each chunk of the image,
> and this is where I guess I make some mistake:
>
>    cairo_t * cr = gtk_print_context_get_cairo_context (context);
>    cairo_set_source_surface (cr, the_surface, 0.0, 0.0);
>    cairo_rectangle (cr, 0.0, (double)page_height*page_nr,
> (double)width, (double)page_height);
>    cairo_fill (cr);
>
> That is, I move the y-coordinate of the cairo_rectangle on by one
> page_height at each call expecting this to take a new page from the
> image surface. However only the value page_nr=0 behaves as expected, the
> second page has just a tiny strip from the bottom of the first page,
> printed at the bottom, and the rest of the pages are blank.
>
> Any help would be appreciated
>
> Richard Shann
>
>
>
>
> --
> cairo mailing list
> cairo at cairographics.org
> http://lists.cairographics.org/mailman/listinfo/cairo
>


More information about the cairo mailing list