[cairo] cropping an SVG image

jan aerts (RI) jan.aerts at bbsrc.ac.uk
Mon May 7 11:36:59 PDT 2007


Daniel,

It looks like the original SVG file ('big.svg') is valid SVG, but the smaller surface ('small.svg') does not include SVG elements but rather an in-file base64 PNG representation of them: '<image width="200" height="500" xlink:href="data:image/png;base64,iVBORw0KGgoAAA.......'

So using the approach as referred to in my previous mail _does_ result in an SVG file, but one that contains just one big base64-encoded PNG.

Any ideas?

jan.


-----Original Message-----
From: jan aerts (RI)
Sent: Mon 07/05/2007 17:40
To: 'Daniel Amelang'
Cc: cairo at cairographics.org
Subject: RE: [cairo] cropping an SVG image
 
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>

The file 'big.svg' shows no rectangles at all unless I uncomment the big_context.show_page line, but it's created even though the big_surface.finish line is commented out...

Where would I find a full-blown explanation (and simple to understand for a novice) of what all the different methods do?

Thanks,
jan.

-----Original Message-----
From: Daniel Amelang [mailto:daniel.amelang at gmail.com] 
Sent: 07 May 2007 06:22
To: jan aerts (RI)
Cc: cairo at cairographics.org
Subject: Re: [cairo] cropping an SVG image

On 5/2/07, jan aerts (RI) <jan.aerts at bbsrc.ac.uk> wrote:
> All,
>
> Is it in any way possible to crop an SVG surface? I've found code in 
> one of Carl's answers to do the very thing for PNGs 
> (http://lists.freedesktop.org/archives/cairo/2007-March/009988.html),
> but I just can't get it to work for an SVG or PDF... The trick seemed 
> to be to create a smaller surface and copy the wanted part from the 
> big surface onto that one.

Hi Jan, yes, that technique should work for SVG and PDF (AFAIK). Can you share some code with us and explain how your expected results and observed results differ?

Dan






More information about the cairo mailing list