`text` property `shape-inside` not respected

Open
#404 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
python

Research direction

Start with CairoSVG's svg2png entry point and the supplied SVG, focusing on text element id="text3173" and rect id="rect1344". Reproduce the rendering with the shown Python call and compare it with the expected Inkscape output. Done means text using shape-inside wraps within the rectangle instead of bleeding off the page.

Written by the indexing model from the issue text.

Description

feature

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:

  • 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:
assetsCaps-diplomat

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

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.

Dominant language
Python
Stars
959
Forks
172
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Kozea/CairoSVG

All issues in Kozea/CairoSVG

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.