[cairo] cropping an SVG image

Emmanuel Pacaud emmanuel.pacaud at lapp.in2p3.fr
Tue May 8 00:23:30 PDT 2007


Le lundi 07 mai 2007 à 17:40 +0100, jan aerts (RI) a écrit :
> Daniel,
> 
> Looks like I got it working, but I don't entirely understand why... The
> code looks like this (using the ruby bindings):
> 
> <BEGIN CODE SNIPPET>
> big_surface = Cairo::SVGSurface.new('big.svg', 200, 500)
> big_context = Cairo::Context.new(big_surface)
> # Draw 2 rectangles
> big_context.set_source_rgb(1,1,0)
> big_context.rectangle(20,20,50,50).fill
> big_context.rectangle(50,50,80,80).fill
> # big_context.show_page
> # big_surface.finish
> 
> small_surface = Cairo::SVGSurface.new('small.svg', 100,100)
> small_context = Cairo::Context.new(small_surface)
> small_context.set_source(big_surface,0,0)
> small_context.rectangle(0,0,100,100).fill
> small_context.show_page
> small_surface.finish
> <END CODE SNIPPET>

You can't paint a svg surface created for one document onto another one
created for another document. That's because a surface may have
references to objects in the svg <defs> sections, which are not shared
across documents. 

In your case, you should use cairo_surface_create_similar for creating
big surface.

	Emmanuel.



More information about the cairo mailing list