[cairo] cairo_surface_create_similar / create_similar for SVGSurface

Steve stevech1097 at yahoo.com.au
Mon Sep 1 07:33:37 PDT 2008


On Wed, 2008-07-02 at 09:47 +0800, Steve wrote:
> On Tue, 2008-07-01 at 04:20 -0700, cairo-request at cairographics.org
> wrote:
> > I'm using multiple surfaces to render some diagrams to an SVG, but the
> > SVG
> > surface doesn't seem to support the create_similar method for the
> > CONTENT_COLOR
> > or CONTENT_COLOR_ALPHA options.  Is there an option that I'm missing?
> > 
> > Thanks,
> > 
> > Eric
> You don't show which error message you get, or which cairo and pycairo
> version you use, so your problem description is a bit vague.
> 
> It was discussed before
> http://www.nabble.com/How-should-bindings-deal-with-surfaces-of-unknown-type--tp13082710p13082710.html
> A solution was proposed for inclusion in cairo 1.6, but AFAIK it has not
> been implemented yet. I suggest opening a cairo bug report to remind the
> developers it still needs fixing.
> 
> Regards,
> Steve
> 
> > # this works fine
> > s = cairo.ImageSurface(cairo.FORMAT_ARGB32, 400, 400)
> > 
> > # this fails when I tried to call the create_similar
> > s = cairo.SVGSurface(strFileName, 400, 400)
> > 
> > ctx = cairo.Context(s)
> > 
> > target  = ctx.get_target()
> > layer0 = target.create_similar(cairo.CONTENT_COLOR_ALPHA, 400, 400)
> > layer1 = target.create_similar(cairo.CONTENT_COLOR_ALPHA, 400, 400)
> > 
> > # render layers
> > # ...
> > 
> > # Add the layers back to the original surface
> > ctx.set_operator(cairo.OPERATOR_OVER)
> > ctx.set_source_surface(layer0, 0, 0)
> > ctx.paint()
> > 
> > ctx.set_operator(cairo.OPERATOR_OVER)
> > ctx.set_source_surface(layer1, 0, 0)
> > ctx.paint()

Eric,
I've just applied a patch to pycairo which works around this problem, so
the test code you gave will work OK with the next version of pycairo.
create_similar() will create a cairo.Surface (not a cairo.SVGSurface)
instance which can be used to render layers.

(The problem within cairo still exists, so other bindings will still
have the same problem, unless they apply a similar work around)

Regards,
Steve



More information about the cairo mailing list