[cairo] New surface: cairo_combined_surface_t

Kouhei Sutou kou at cozmixng.org
Wed May 31 18:20:52 PDT 2006


Hi,

I filed this idea into Bugzilla as #7079 but I send this idea to ML to ask for
comments.

--
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));
}
--

Thanks,
--
kou
-------------- next part --------------
A non-text attachment was scrubbed...
Name: cairo-combined-surface.diff
Type: text/x-patch
Size: 30655 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/cairo/attachments/20060601/4ae49271/cairo-combined-surface-0001.bin


More information about the cairo mailing list