Kozea / Kozea/CairoSVG

Support bounding box transformations

Open
#132 0 comments 1 reaction 0 assignees View on GitHub
bug
Dominant language
Python
Stars
951
Forks
166
PR merge metrics
No merged PRs in 30d

Description

The bounding box computation of a group by the function [`cairo.bounding_box.bounding_box_group`](https://github.com/Kozea/CairoSVG/blob/eed51eee190285effb275af91e5b72fb175edcef/cairosvg/bounding_box.py#L353) 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`](https://inkscape.org/en/doc/inkscape-man.html):

"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:
```python
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.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in cairosvg/bounding_box.py at bounding_box_group and trace the calculate_bounding_box call shown in the report. Reproduce the case with foo.svg and compare the computed boxes with inkscape --query-all --without-gui; done means individual rotations and skews are reflected in bounding boxes, with any cropping behavior clearly defined.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
computer-graphics
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.