Even if we want to write same contents to different serfaces, we must make cairo_t for each cairo_surface_t. For example, if we wants to output PS and PDF with same contents, we write the following code: static void render(cairo_surface_t *surface) { cairo_t *cr; cr = cairo_create(surface); ... cairo_rectangle(cr, ...); cairo_fill(cr); ... cairo_show_page(cr); ... cairo_surface_finish(cairo_get_target(cr)); } static void output(void) { cairo_surface_t *ps_surface, *pdf_surface; ... render(ps_surface); render(pdf_surface); } There is some problems: * If render() loads a image each time, the image is loaded twice. * We must define a function to render. (Yes, we can use "copy and paste" but this is a bad manner.) * ... To solve those problems, I suggeste that cairo provides a surface can combine some surfaces and show those surfaces as a surface to cairo_t. And then, we can write the above code as the following: static void output(void) { cairo_t *cr; cairo_surface_t *ps_surface, *pdf_surface, *combined_surface; ... combined_surface = cairo_combined_surface(ps_surface, pdf_surface, NULL); cr = cairo_create(combined_surface); ... cairo_rectangle(cr, ...); cairo_fill(cr); ... cairo_show_page(cr); ... cairo_surface_finish(cairo_get_target(cr)); }
Created attachment 5764 [details] [review] An implementation of this idea.
Moved to todo.
Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.