sammycage / lunasvg

SVG rendering and manipulation library in C++
MIT License
899 stars 125 forks source link

How to use lunasvg as a parser #112

Closed floppyhammer closed 10 months ago

floppyhammer commented 2 years ago

Is there any example showing how to use it for parsing, in case I want to do rendering myself?

sammycage commented 2 years ago

It will be very difficult to remove the renderer... You can use otfsvg which is designed specifically for this purpose.

Useful Links

Example : https://github.com/sammycage/otfsvg/blob/main/otfsvg-dump.c Issues : https://github.com/sammycage/otfsvg/issues

m-carrasco commented 1 year ago

@sammycage thanks for your previous answer. I want to ask you the following.

In this example, the Document::loadFromFile method is used as a parser for the input SVG file. Then, the document is rendered by calling document->renderToBitmap().

    // Example in README
    auto document = Document::loadFromFile("tiger.svg");
    auto bitmap = document->renderToBitmap();

I am also interested in just parsing SVG files. I was assuming that Document::loadFromFile only performs parsing. Is this wrong? Ideally, I'd like to have a function that only checks whether the input SVG file is valid.

Thanks in advance! Manuel

felipepiovezan commented 1 year ago

A similar question to this: my understanding of the codebase is that currently it is not possible to materialize Layout objects back to SVG?

igagis commented 1 year ago

since lunasvg doesn't allow accessing parsed model, I suggest to have a look at another lib for parsing svg: https://github.com/cppfw/svgdom