RazrFalcon / resvg

An SVG rendering library.
Mozilla Public License 2.0
2.74k stars 221 forks source link

Support shape-based text layout #443

Open RazrFalcon opened 3 years ago

RazrFalcon commented 3 years ago

https://www.w3.org/TR/SVG2/text.html#TextLayoutContentArea

Probably the most complicated feature in SVG2. Requires a lot of work. Not supported by basically anyone. Inkscape has some bare-minimum implementation, but that's about it.

waynr commented 6 months ago

Ah so you do plan to support this -- great! I was just about to write up an issue asking about shape-inside but then thought to look for inline-size first since that seems to be related and ended up finding my way here.

Is this something that's a WIP in any way? Before I came across the shape-inside documentation earlier tonight I was considering just using the cosmic-text crate to break a chunk of text down into individual lines but then when I was checking the dependency tree in my project I noticed usvg already uses cosmic-text (which is what prompted me to look for some kind of wrapping functionality in the SVG spec).

You mention that Inkscape has a bare-minimum implementation, but at least the version I am using won't even render text with a shape-inside style. You also mention it's not supported by many SVG libraries period...which makes me wonder if I should even use it in my generated SVG drawings at all. It might be better for my simple use case to see how far using cosmic-text directly can take me to produce a series of tspans instead.

Sorry that's a lot of rambling. Here are a couple questions:

waynr commented 6 months ago

Hmm, I think https://github.com/RazrFalcon/resvg/issues/643 answers a lot of my questions already (just do it myself) so...nevermind!

RazrFalcon commented 6 months ago

I have no plans on implementing this feature.

usvg already uses cosmic-text

usvg doesn't use cosmic-text. But they both do use rustybuzz.

You also mention it's not supported by many SVG libraries period...which makes me wonder if I should even use it in my generated SVG drawings at all.

If you care about compatibility you should avoid any complex SVG features. In case of text, you should stick to a simple <text x="0" y="0">Text</text>. Nothing more complex would ever work.

Am I missing some kind of debug messages that would otherwise have told me the attribute

usvg silently ignores unsupported elements and attributes.

I know you said this would require a lot of work -- do you think it would be possible for someone comfortable with rust and willing to do some work over time to contribute this?

One could try. But it's a multi-months tasks. I think it would take me at least 3 months full time to finish it. Probably more.

Would I be better off just using cosmic-text directly to break a chunk of text into tspan elements in my library?

I never used cosmic-text. I guess.

waynr commented 6 months ago

usvg doesn't use cosmic-text. But they both do use rustybuzz. I never used cosmic-text. I guess.

Ah my bad, I don't know what I was talking about. Sorry bro.

usvg silently ignores unsupported elements and attributes.

Would you be open to a PR to add some kind of trace level logging? (I suspect probably not, but it's worth a shot since having that could help me when i'm trying to render unsupported stuff)

In case of text, you should stick to a simple Text. Nothing more complex would ever work.

Inkscape seems to make pretty liberal use of tspans though, but maybe even they don't support the tspan relative positioning within the parent bits.

I think it would take me at least 3 months full time to finish it. Probably more.

Dang, and you've probably forgotten more than I'll ever know about SVG. Ah well, I'll give cosmic-text a shot for my text wrapping/manipulation needs. Thanks for your thoughtful and quick responses!

RazrFalcon commented 6 months ago

Would you be open to a PR to add some kind of trace level logging?

Probably not. There would be too much noise. And it's a yet another feature too support.