CairoSVG icon indicating copy to clipboard operation
CairoSVG copied to clipboard

Support bounding box transformations

Open johnyf opened this issue 9 years ago • 0 comments

The bounding box computation of a group by the function cairo.bounding_box.bounding_box_group appears to not be applying any transformation matrices for the individual elements.

My purpose is to achieve the same effect as Inkscape's option --export-area-drawing:

"In PNG, PDF, PS, and EPS export, exported area is the drawing (not page), i.e. the bounding box of all objects of the document (or of the exported object if --export-id is used). With this option, the exported image will display all the visible objects of the document without margins or cropping. This is the default export area for EPS. For PNG, it can be used in combination with --export-use-hints."

Currently, I cannot (yet) get the bounding boxes computed by cairosvg to match those reported by

inkscape --query-all --without-gui foo.svg

I have tried the following:

import cairosvg
import io

t = cairosvg.parser.Tree(url='foo.svg')
g = t.node.getchildren()[3]  # a group
surf = cairosvg.surface.PDFSurface(t, output=io.BytesIO(), dpi=96)
nd = cairosvg.parser.Node(g, 'foo', parent=t)
cairosvg.bounding_box.calculate_bounding_box(surf, nd)

It would be great if cairosvg either provided a function compute the bounding boxes taking into account rotations and skews, or an option to crop the whitespace to the bounding box of the contents when converting to PDF.

johnyf avatar Dec 26 '16 21:12 johnyf