-
Notifications
You must be signed in to change notification settings - Fork 236
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
Add support for context-fill
and context-stroke
#665
Conversation
For marker tests, let's use triangle and not a line for the base shape. This way we would be able to test |
Looks ok overall. The feature itself is somewhat convoluted and niche. Even Chrome and Safari doesn't support it yet. Nested |
No worries, I can do the tests! Might need a bit help with figuring out how to properly deal with paint servers, but I'll have a look at it myself later / in the next few days. |
I used the star instead to make it more consistent with other tests, I hope that is okay. |
Sure, it's fine. |
I looked a bit more into the source code, and I just had two (somewhat) related questions:
|
Probably not.
Ugh... were do I even begin. I plan to write a whole chapter for Notes on SVG parsing about |
Okay, I'll open a separate PR for this!
Ah, that's unfortunate. :( |
It is... I've tried multiple times to get rid of |
So after doing some more digging into the source code, I'm honestly a bit clueless about how to implement support for properly resolved gradients/patterns without introducing too much "ugly" code. Two approaches I could think of are:
So yeah, I think for now I will attempt to implement the first approach and see how far I can get. |
Ideally,
Welcome to SVG, where everything is 10x more complicated than it should be. The goal of |
No worries, I'll also give it some more thought! |
So I think implementing proper support for gradients/patterns will be really tricky and probably require some bigger changes. Would it be okay for you if we merge this now (so that it at least works properly for solid colors) and create an issue so that we don't forget about adding support for gradients/patterns as well later on? I think for now I will try working on some other "low-hanging fruits" (i.e. some other SVG2 features) before getting back to this. But if not, I it's fine as well, but not sure when I will revisit this PR. I need to gain some more familiarity with the library by working on some other easier issues before proceeding with this. It would also fix typst/typst#2359, which is the main reason why I made this PR. |
I would be able to work on it maybe next month. I don't want to merge a half-backed solution. It's not very As for |
I totally understand, let's leave it open then. :) |
I asked here if Chrome has any plans to support gradients. |
Ah, then we definitely should look into that... Sorry for the delay from my side, I will try to make some time for it in the next few days. |
@RazrFalcon context in |
Aren't marker context is the current path fill/stroke? And we already resolved it. |
I think I figured it out. :D Will clean up a bit and mark the PR as ready to review once I'm done. |
I hope it's okay! |
/// A fill style. | ||
#[derive(Clone, Debug)] | ||
pub struct Fill { | ||
pub(crate) paint: Paint, | ||
pub(crate) opacity: Opacity, | ||
pub(crate) rule: FillRule, | ||
// Whether the current fill needs to be resolved relative | ||
// to a context element. | ||
pub(crate) context_element: Option<ContextElement>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only reason we have to store it is because of paint bbox resolver?
I think we can avoid it for markers, since we already know the bbox beforehand, unlike with text.
But I guess I will try figuring it out by myself, since it would be a bit tricky.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we mainly need it as a "marker" so that when iterating over all paint servers we know which strokes/fills need to be converted.
Paint resolver code looks a bit too complicated. Will see if I would be able to simplify it. |
Yes, it does! All of them.
You mean I know the code isn't great. :( But it's also a tricky feature to implement... |
Thanks again for looking into this! I will look if it can be simplified a bit and will publish a new release probably on weekends. |
Thanks, I'm glad this feature is implemented now! |
Here is the corresponding specification.
This is still a WIP, in particular, the following I still haven't looked into more deeply (as I'm still unfamiliar with the codebase) and I think might be a bit tricky to implement:
But I'm opening this as a draft PR so that people know that someone is working on it. 😄
I also had to temporarily switch to my own version of
svgtypes
since it's not included in this repository.