CairoSVG
CairoSVG copied to clipboard
`text` property `shape-inside` not respected
Problem
My <text>
element's shape-inside
property is being ignored when I svg2png
using cairosvg
. https://cairosvg.org/svg_support makes no mention of shape-inside
. The shape-inside
feature is described here.
What I expected
The text of the At the end of the Round ... Break ties in your favor if...
text to wrap before it goes off the card, like so (this is what Inkscape renders and exports):
What occurred
The text is not inside the rect and bleeds off the page.
Repro:
- Download the svg file below
-
pip install cairosvg
python package - Create and run the following python code:
from cairosvg import svg2png
svg2png(
url="path/to/svg",
write_to="path/to/desired/png",
dpi=300,
output_width=825,
output_height=1125)
Here is my svg file, you can see that Github/Chrome is observing shape-inside
:
You can right click it and download it.
The text element in question is id="text3173"
and it shape-inside's rect element id="rect1344"
. Here's rect 1344
if it was visible:
XY Problem Considerations
The svg's are programmatically generated, so I cannot add newlines manually. The text input changes frequently and so the newlines would change frequently. The person responsible for creating the card's rules has no idea the width of the text area and ideally never will have to. I would love to avoid baking newlines that aren't related to emphasis into my card rules.
Currently, I call os.system("inkscape input.svg --export-filename=output.png --export-dpi=300")
within my python program in order to render my svgs.
This isn't ideal because this requires my users to have Inkscape installed. I believe an entirely python solution is superior to a python package that requires a separate non-python program. I believe cairosvg
may be a good Inkscape replacement if cairo supports text wrapping. So far, svglib
and wand
have the same issue, but their output has other problems on top of not wrapping text.
Hi,
Thanks for the feature request.
CairoSVG doesn’t support much from SVG2, and text wrapping is a complex topic that requires a lot of work.