-
Notifications
You must be signed in to change notification settings - Fork 231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can not set stylesheet path from c
via the c-api
#870
Comments
Yeah, this could definitely be added. Feel free to open a PR, although I'm not sure I would be able to review it because my C knowledge isn't great, but I'm sure someone else would be able to. |
I'm interested in opening a PR to add this feature (here's the PR #873). In trying to do so, I found something to be a bit confusing. As you can see, the command line argument below requests a path to be provided to inject a stylesheet. Lines 28 to 29 in bda7db0
So, I compiled $ target/debug/resvg --stylesheet test.css some.svg some.png However, I came across some issues when trying to replicate those results when using More detailWhen running `resvg` as a binary, the path provided from the command line is treated as a `PathBuf` and then, the stylesheet's content is read. https://github.com/linebender/resvg/blob/bda7db0d0b2eb32c5f63f90279cec19613945a9d/crates/resvg/src/main.rs#L242 https://github.com/linebender/resvg/blob/bda7db0d0b2eb32c5f63f90279cec19613945a9d/crates/resvg/src/main.rs#L554-L562 On the other hand, the `usvg` parser, used in the minimal example, treats the stylesheet as a `String`. From that point on, it assumes `stylesheet` contains the contents of the stylesheet. https://github.com/linebender/resvg/blob/6df63519f04580bd74e31b25e9ee82d4ace145da/crates/usvg/src/parser/options.rs#L98-L100 I anticipate the difference when using If this is unintentional, how would like to handle this issue? I'm willing to open to creating another issue and creating a PR for it, but I wanted to get your opinion on it before I do that. On the other hand, if it's intentional, are there any plans to add a function or method that can accept the path to a stylesheet? |
This is intentional, resvg as a library should be pure and not have any interaction with the filesystem whatsoever, so I'm afraid we can't change that. Why can't we just ask the user of the C api to just load the file from their side and then pass the contents to resvg? (EDIT: Nevermind, didn't read the whole thing. :p But I'm afraid there really isn't much we can do, reading the file in resvg itself is both, bad from a security standpoint as well as a portability one.) |
Understood. Security and portability are important considerations. I've updated my PR for this issue (#873) to account for this fact. |
Context
Most of the important
usvg
options written inrust
are available in thec
api. Some of the accessible options are setting the language, resource directory, rendering modes, and so on. However, the stylesheet option, which is available in therust
api, is not available in thec
api.resvg/crates/usvg/src/main.rs
Lines 28 to 29 in bda7db0
Question
c-api
? Something like this perhaps?P.S.: Great work on the library!
The text was updated successfully, but these errors were encountered: