Kozea / CairoSVG

Convert your vector images
https://courtbouillon.org/cairosvg
GNU Lesser General Public License v3.0
773 stars 151 forks source link

`text` property `shape-inside` not respected #404

Open TheNextGuy32 opened 11 months ago

TheNextGuy32 commented 11 months ago

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): image

What occurred

The text is not inside the rect and bleeds off the page. image

Repro:

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`:
![assetsCaps-diplomat](https://github.com/Kozea/CairoSVG/assets/3976080/692bcfb8-e7dd-4fa5-be4f-41cf17163153)

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:
![image](https://github.com/Kozea/CairoSVG/assets/3976080/c2b3eec2-f226-45a3-befa-120fbfe0d3ee)

# 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.
liZe commented 11 months ago

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.