[cairo] rsvg and cairo alpha puzzle

Donn donn.ingle at gmail.com
Fri Nov 30 04:47:52 PST 2007


Hi again,
 I realize that rsvg is not your problem, but I thought there may be some 
advice or clever hackery to be had.
 I include the script at end. The basic problem is the cairo_render ( ctx) 
command in pyRsvg in combination with paint_with_alpha.

O/S: Kubuntu 7.10
Cairo version: Version: 1.4.10-1ubuntu4
RSVG: Version: 2.18.2-1

Description:
When one tries to translate the SVG *while* it's within the push_group scope 
it ignores it. When you removes the alpha code, it will translate. 

The code:

#! /usr/bin/env python
from math import pi
import pygtk
pygtk.require('2.0')
import gtk, gobject, cairo
import rsvg

class Screen(gtk.DrawingArea):
    __gsignals__ = { "expose-event": "override" }
    def do_expose_event(self, event):
        # Create the cairo context
        cr = self.window.cairo_create()
        self.draw(cr, *self.window.get_size())
def run ( Widget, w, h):
    window = gtk.Window()
    window.connect("delete-event", gtk.main_quit)
    window.set_size_request ( w, h )
    widget = Widget()
    widget.show()
    window.add(widget)
    window.present()
    gtk.main()

class Shapes ( Screen ):
    def draw(self, cr, width, height):
        ## Do cairo stuff here
        
        #Now try to render SVG with alpha.
        cr.translate ( 100, 10 ) # when there's alpha, this does not work.

        #Just to see where I am:
        cr.rectangle ( 0, 0, 10, 10 )
        cr.set_source_rgb ( 1, 0, 0 )
        cr.fill ( )
        
        cr.push_group ( )
        obj.render_cairo ( cr )
        cr.pop_group_to_source ( )
        cr.paint_with_alpha ( 0.5 ) # this works, but translate does not.
        
        
obj = rsvg.Handle ( "cube.svg" )

run ( Shapes, 400, 400 )

I hope it's something simple -- like me :)
\d


More information about the cairo mailing list