[cairo] Cleaning up the PDF API

Bill Spitzak spitzak at d2.com
Tue May 17 08:26:29 PDT 2005



Kristian Høgsberg wrote:

> 1. Trade the destroy callback for a flush callback.
> 2. Assume non-buffered I/O and add buffering to cairo_output_stream_t
> 3. Decide that a write of 0 bytes means "flush" (just a variant of 1)

None of this seems necessary. The callback should take large buffered 
blocks. Having the callback be called for every character would slow 
down the pdf writing unacceptably, I would think. All that the cairo pdf 
has to do for "flush" is write the remaining partial block. If the 
actual callback does not really do a flush to disk, the caller can do 
this, since the only reason they could possibly want this is so they can 
work directly with the stream, thus they must have a pointer to the 
stream and they can call the real flush on it.

I am also confused about the need for an object-oriented langage needing 
the destroy callback. Here is an implementation that will close the 
stream without needing any cairo support:

class PDFCairo {
   Stream* stream;
   cairo_surface_t *surface;
   PDFCairo(Stream* s) {
     stream = s;
     surface = cairo_create_pdf_surface(...);
   }
   ~PDFCairo() {
      cairo_destroy_surface(surface);
      destroy(stream); // HERE IS WHERE IT IS DONE!
   }
};

All I can guess is that there is some concern about the extra storage 
needed for the surface pointer. If so that could be solved with a call 
to get the "closure" directly from the surface. Or you are concerned 
about having to have a virtual destructor, but it seems the solution is 
to force the overhead of making a virtual destructor into Cairo itself, 
which does not solve anything.



More information about the cairo mailing list