[cairo] Python SVG Surface redux

Donn donn.ingle at gmail.com
Fri Dec 14 04:41:48 PST 2007


Hello again,
 Some code, question afterwards:

#! /usr/bin/env python
import cairo
import rsvg

s1 = cairo.SVGSurface("newsvg.svg",400,400)
cr = cairo.Context( s1 )

cr.rectangle(0,0,20,20)
cr.fill()

#Draw a red triangle under a group - p
cr.push_group()
cr.translate(100,100)
cr.set_source_rgb(1,0,0)
cr.move_to(0,0);cr.line_to(50,50);cr.line_to(50,0);cr.close_path()
cr.fill()
p = cr.pop_group()
cr.set_source(p)
cr.paint()

## this produces an image within the SVG output....
s2 = cairo.SVGSurface("outputs_an_image_within_the_svg.svg",400,400)
cr2 = cairo.Context(s2)
cr2.set_source_surface(s1)
cr2.paint()
s2.finish()

## Ah, this one worked. It outputs an SVG file.
s3 = cairo.SVGSurface("outputs_proper_SVG.svg",400,400)
cr3 = cairo.Context(s3)
cr3.set_source(p) # let's use the pattern from cr/s1
cr3.paint()
s3.finish()

s1.finish()

Okay - 
1. so why does the surface s2 produce an SVG file with an embedded image?

\d


More information about the cairo mailing list