[cairo] How should bindings deal with surfaces of unknown type?

Torsten Schoenfeld kaffeetisch at gmx.de
Thu Jan 3 08:54:56 PST 2008


On Sat, 2007-12-29 at 20:03 -0500, Behdad Esfahbod wrote:

> Currently the Python bindings have the same problem.  There are three
> solutions at this time:
> 
>   1) Document that create_similar may create private surface types.
> Those types should be treated as anonymous subclasses of
> cairo_surface_t.  I think all language bindings can easily handle this,
> but either making cairo.Surface instantiable or (better?), make a
> cairo.UnknownSurface subclass for all those cases.
> 
>   2) Make create_similar always return a public surface type.  That is,
> PS/PDF/SVG for PS/PDF/SVG.  Then we really have to make sure all the
> backend methods work on the returned surface, and work correctly.  One
> way would be to make create_similar actually return a real PS/PDF/SVG
> surface, one with the file argument NULL, and make file argument NULL
> work.  That's probably suboptimal, but should keep things much more
> clear and even remove some code.
> 
>   3) Make meta-surface public for 1.6.  We can always add methods to it
> later.  We just need to fix the constructor right now.  Unfortunately
> that's in fact the trickiest part so far.

>From a language binding's point of view, it's important that the type
returned by cairo_surface_get_type() corresponds to the surface'
capabilities.  So if get_type() returns PDF, it must be legal to call
PDF specific surface functions on that surface.

So, yes, I think all three of your suggestions would fix this problem
for language bindings.  I think I'd prefer solution 2, however, since it
seems cleanest from an outside point of view.

-- 
Bye,
-Torsten



More information about the cairo mailing list