Fix printing

The plugins expect an image surface but the target of the print context might
not be one.
This commit is contained in:
Sebastian Ramacher 2012-12-06 21:43:21 +01:00
parent 48d12f49be
commit 23649bc0bc

32
print.c
View file

@ -103,10 +103,40 @@ cb_print_draw_page(GtkPrintOperation* UNUSED(print_operation), GtkPrintContext*
return;
}
/* we need a temporary cairo object since the cairo object from the print
* context doesn't have a width or height */
const gdouble width = gtk_print_context_get_width(context);
const gdouble height = gtk_print_context_get_height(context);
cairo_surface_t* surface = cairo_image_surface_create(CAIRO_FORMAT_RGB24, width, height);
if (surface == NULL) {
return;
}
cairo_t* temp_cairo = cairo_create(surface);
if (cairo == NULL) {
cairo_surface_destroy(surface);
return;
}
/* white background */
cairo_save(cairo);
cairo_set_source_rgb(cairo, 1, 1, 1);
cairo_rectangle(cairo, 0, 0, width, height);
cairo_fill(cairo);
cairo_restore(cairo);
/* render the page to the temporary surface */
girara_debug("printing page %d ...", page_number);
render_lock(zathura->sync.render_thread);
zathura_page_render(page, cairo, true);
zathura_page_render(page, temp_cairo, true);
render_unlock(zathura->sync.render_thread);
/* copy temporary surface */
cairo_set_source_surface(cairo, surface, 0.0, 0.0);
cairo_paint(cairo);
cairo_destroy(temp_cairo);
cairo_surface_destroy(surface);
}
static void