RazrFalcon / resvg

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

Dynamically create own SVG tree. #746

Closed spirali closed 5 months ago

spirali commented 5 months ago

Hi,

I am using usvg as an intermediate representation of an image data. In version 0.39, I was able to dynamically create a tree and then render it. Is it still possible to do this with the current API? It seems that now I cannot now create own of tree nodes outside of usvg crate.

LaurenzV commented 5 months ago

It's not possible anymore. See #710.

spirali commented 5 months ago

Thank you.

RazrFalcon commented 5 months ago

You're suppose to use tiny-skia directly. Creating usvg::Tree by hand and passing it to resvg would be way slower.

spirali commented 5 months ago

I actually used this mainly for creating PDF; I built a usvg tree and then render it via svg2pdf. Therefore, the correct way for me is to probably directly use pdf-writer. Now I will need two renderers, one via tiny skia and one trough pdf-writer, but I understand your decision.

LaurenzV commented 5 months ago

Writing a renderer from scratch with pdf-writer will be a pain... You will probably have an easier time if you instead construct an SVG string and convert that. This is still more inconvenient than constructing the tree directly, but definitely less inconvenient then maintaining two rendering backends.

spirali commented 5 months ago

I am going to use serialization to SVG string as a baseline, but I am afraid that it will not be sufficient for me as sometimes my pages contains large raster images and serialization them to base64 and back would be a non-negligible step. My usage of usvg API was mainly because I could directly put png/jpg images into SVG without this serialization/deserialization step.

Nevertheless, I was planning to write own PDF backend mainly because of raster image reuse. AFAIK, in the current version of svg2pdf, if more SVG embeds the same raster image, then it is serialized several times into PDF