[Cairo] Color transforms

Bill Spitzak spitzak at d2.com
Thu Jul 17 12:40:25 PDT 2003


On Thursday 17 July 2003 12:18 pm, David Forster wrote:
> On Thu, Jul 17, 2003 at 04:29:49PM +0100, Michael Meeks wrote:
> > 	Presumably for .png there are a load of strange compression options
> > which would work well at device surface creation, but for .pdf are there
> > not all manner of web-linking / even more exotic bits that people may
> > want emitted ?
> >
> > 	It's not at all obvious to me how to support that sort of thing short
> > of exposing the internals of the backend rendering method somehow.
>
> Think of Xlib; Cairo doesn't replace it, it just sits over it's
> drawing functionality.  Likewise, you would have a libpdf that the
> Cairo backend sits over.  When you crate a `PDF surface' you just hand
> over what ever data types libpdf made, just as you do with Xlib (or
> you could have a convenience surface creator that handles everything).
> Ditto with PNG.
>
> A backend, of course, could do everything but that design will be
> understandably limited.

Even without exposing the pdf implementation, you could still provide a lot 
of pdf-specific functionality:

cairo_surface* surface = cairo_pdf_create( pdf-specific-arguments );

cairo_set_surface(cairo_state, surface);
cairo_lineto(cairo_state, x,y); // device-independent call
// here is an example of a pdf-specific call:
cairo_pdf_start_link(cairo_state, "http://www.foo.bar");

If written this way, only the existence of special functions, in the same 
header file as the one that creates the pdf surface, need to be revealed. The 
actual implmentation of the pdf driver does not have to be public, and can 
easily be changed.

The pdf-specific calls should just ignore stuff if the surface is not of the 
type known about. This could be checked by seeing if one of the virtual 
functions in the surface points at the expected function:

void cairo_pdf_start_link(cairo_state* s, ...) {
  if (s->surface->moveto != my_moveto) return;
  do_pdf_stuff...
}

This would avoid having to put "if" statements in the calling code if you 
want to reuse it for drawing on different devices.

-- 
                   ,~,~,~,~ ~ ~ ~ ~
     /\_       _|_========___         Bill Spitzak
 ~~~/\/\\~~~~~~\____________/~~~~~~~~ spitzak at d2.com




More information about the cairo mailing list