You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is done to make sure we don't have to maintain a full DOM or traverse the XML more than once.
However, it should be possible to keep an in memory structure of defs (probably a Map of some sort) we expect to see but haven't seen yet, and go back and back-fill them (and then remove them from the structure after we found the def they're looking for) with only a little bit of memory overhead.
I thought I had a way to do this, but all the ways I've been able to come up with are pretty inefficient.
If we defer resolution until drawing time (e.g. a lot of things that are now static properties become functions/getters that may not work during the parse phase), we can avoid reparsing the document but may get into strange situations where we have lots of indirection going on via functions. For example, getting a Drawable's fill might actually be a function that calls a function that calls a function that returns the data by calling a few other functions to resolve its properties.
If, on the other hand, we always parse defs in any order, we have to go to a DOM based model of parsing and do a lot of jumping around the document/tree, which will be very inefficient on particularly large SVGs.
This should be something that could be preprocessed away and avoid these complexities/inefficiencies.
I wonder if you there's a way to add build time pre-processing to avoid inefficiencies.
Something like how built_value.dart (https://github.com/google/built_value.dart) generates Dart files, could you have flutter_svg generating a compressed SVG that matches the format required by the package?
That's definitely doable, and something I've considered exploring but haven't had time to prioritize - or evidence that it would really bump performance enough to be worth it. And unfortunately it wouldn't help with network based images
I suppose a middle road might be having something like that and then allowing for a less efficient parsing algorithm - which would make precompiled images a bit faster but dynamic images even slower.
I thought I had updated this again, but I guess not.
Supporting this introduces a lot of complexity. In particular, references can have other references, which can have other references, etc.
To fully support this would require some substantial reworking - the simplest cases of only one level of nesting aren't too bad, but when those nested references have other nested references, it becomes a big ugly list of closures everywhere to resolve things, and will be much less efficient both time and space wise, not to mention getitng a lot harder to reason about.
I'm really hesitant to support this. But I also understand it's frustrating when you have an SVG you don't control that just comes this way.
Why not just provisionally add support for single level nesting? Once done we can get a better idea if we need multi-level nesting support. Maybe multi-level nesting is very rare compared to single-level nesting.
@IchordeDionysos - you could preprocess the SVG from the server before you pass it to this library.
In fact, maybe that's the right way to handle this - write a preprocessing package to rearrange defs. That way people who want to pay the performance and complexity costs (or have no choice) can, without forcing them on people with more sane SVGs.
FYI, figma exports definitions after so SVGs are not rendered.
Figma has a larger user base than affinity and i think we'll hear more complains on this.
Reacted by Álvaro Agüero, Brian Christensen, Victor Eronmosele, Hilton Pintor, QuocPhi, sj, Suryansh Singh Tomar, Tianli Zhang, Kshitiz Kamal, Yoav Genish and 4 more
I make a quick program for reordering <defs> to the first child, hope It help someone. By the way, I still can't use the svg from designer exported from figma, even If I reorder the svgs.
use flutter_svg_opt as dev dependency, and run flutter pub run flutter_svg_opt:main (will change all svgs under assets by default).
My svg doesn't have a <path> tag but it has <rect> tag
Ohh I haven't worked with <rect> 😅 my be try finding svg which have path in that... Or if possible you can share one of your svg code here I will try see if I can convert it into path like format
this does seems to be svg... this seems to be png image I am not sure if this can be scan be supported.. so, I would suggest to simply use png instead of converting png to svg
I'm working on a new package that supports out of order defs. However, as I expected, doing so resulted in some noticable performance regressions. I'm not sure it'll make sense to ever support in this package, which is already slow enough atparsing the SVGs.
Reacted by Sahhar Youcef, fernandovargascabrera, ChiPhanTlm, Prince Nna, Roman Cinis, Albert Wolszon and Mutoni Denyse
Thank you for your work. From my point of view it would be great if the library was able to render more SVGs, support for the really expensive features could be optional.
To work around this, we preprocess user-supplied SVGs where we move the defs to the beginning and we do a topological sort of the defs which solves the problem when they reference each other but were defined in the wrong order.
I make a quick program for reordering <defs> to the first child, hope It help someone. By the way, I still can't use the svg from designer exported from figma, even If I reorder the svgs.
use flutter_svg_opt as dev dependency, and run flutter pub run flutter_svg_opt:main (will change all svgs under assets by default).
@Tokenyet would you please consider updating your package to use xml v6 ? Thanks.
I'm working on a new package that supports out of order defs. However, as I expected, doing so resulted in some noticable performance regressions. I'm not sure it'll make sense to ever support in this package, which is already slow enough atparsing the SVGs.
Activity
IchordeDionysos commentedon Aug 28, 2019
Would really appreciate if this would be implemented.
We are having way to many/dynamic SVGs to change them all :)
NotThatBowser commentedon Sep 2, 2019
Would be useful. Affinity Designer produces SVGs with defs at the bottom, for example.
dnfield commentedon Oct 21, 2019
I thought I had a way to do this, but all the ways I've been able to come up with are pretty inefficient.
If we defer resolution until drawing time (e.g. a lot of things that are now static properties become functions/getters that may not work during the parse phase), we can avoid reparsing the document but may get into strange situations where we have lots of indirection going on via functions. For example, getting a Drawable's
fillmight actually be a function that calls a function that calls a function that returns the data by calling a few other functions to resolve its properties.If, on the other hand, we always parse defs in any order, we have to go to a DOM based model of parsing and do a lot of jumping around the document/tree, which will be very inefficient on particularly large SVGs.
This should be something that could be preprocessed away and avoid these complexities/inefficiencies.
hash404 commentedon Oct 22, 2019
I wonder if you there's a way to add build time pre-processing to avoid inefficiencies.
Something like how built_value.dart (https://github.com/google/built_value.dart) generates Dart files, could you have flutter_svg generating a compressed SVG that matches the format required by the package?
dnfield commentedon Oct 22, 2019
That's definitely doable, and something I've considered exploring but haven't had time to prioritize - or evidence that it would really bump performance enough to be worth it. And unfortunately it wouldn't help with network based images
I suppose a middle road might be having something like that and then allowing for a less efficient parsing algorithm - which would make precompiled images a bit faster but dynamic images even slower.
dnfield commentedon Jan 28, 2020
I thought I had updated this again, but I guess not.
Supporting this introduces a lot of complexity. In particular, references can have other references, which can have other references, etc.
To fully support this would require some substantial reworking - the simplest cases of only one level of nesting aren't too bad, but when those nested references have other nested references, it becomes a big ugly list of closures everywhere to resolve things, and will be much less efficient both time and space wise, not to mention getitng a lot harder to reason about.
I'm really hesitant to support this. But I also understand it's frustrating when you have an SVG you don't control that just comes this way.
ngaurav commentedon Jan 29, 2020
Why not just provisionally add support for single level nesting? Once done we can get a better idea if we need multi-level nesting support. Maybe multi-level nesting is very rare compared to single-level nesting.
ngaurav commentedon Jan 29, 2020
On second thought, If a file only has single-level nesting then it can programatically preprocessed to rearrange out-of-order declarations.
IchordeDionysos commentedon Jan 29, 2020
And if you can't? @ngaurav
Stored on another server/too many of them.
dnfield commentedon Jan 29, 2020
@IchordeDionysos - you could preprocess the SVG from the server before you pass it to this library.
In fact, maybe that's the right way to handle this - write a preprocessing package to rearrange defs. That way people who want to pay the performance and complexity costs (or have no choice) can, without forcing them on people with more sane SVGs.
willhaslett commentedon May 19, 2021
What's the status on this? I have my
defs up top right after<svg>, but am still getting this error.cihadturhan commentedon Jun 5, 2021
FYI, figma exports definitions after so SVGs are not rendered.
Figma has a larger user base than affinity and i think we'll hear more complains on this.
agueroveraalvaro commentedon Jun 7, 2021
is there a solution please? :)
cesc1802 commentedon Jun 22, 2021
i facing with this issue and figma design tool :( anyone can help me?
hpbl commentedon Jul 6, 2021
@willhaslett did you find a solution?
2 remaining items
Tokenyet commentedon Oct 29, 2021
I make a quick program for reordering
<defs>to the first child, hope It help someone. By the way, I still can't use the svg from designer exported from figma, even If I reorder the svgs.use flutter_svg_opt as dev dependency, and run
flutter pub run flutter_svg_opt:main(will change all svgs underassetsby default).Vedsaga commentedon Dec 25, 2021
Yaap, this actually works...
LearningLeopard commentedon Jan 23, 2022
Is this error solved? The rearrangement of tags didn't solve the issue
Vedsaga commentedon Jan 23, 2022
Ohh for me it did solved... If you put your
<path >tag at the bottomLearningLeopard commentedon Jan 23, 2022
My svg doesn't have a
<path>tag but it has<rect>tagVedsaga commentedon Jan 23, 2022
Ohh I haven't worked with
<rect>😅 my be try finding svg which havepathin that... Or if possible you can share one of your svg code here I will try see if I can convert it intopathlike formatLearningLeopard commentedon Jan 23, 2022
Here is the svg file. You can download it and open it in a code editor since pasting the code of svg seems pretty clumsy here
Vedsaga commentedon Jan 23, 2022
this does seems to be svg... this seems to be
png imageI am not sure if this can be scan be supported.. so, I would suggest to simply use png instead of convertingpng to svgsahharYoucef commentedon May 31, 2022
any updates on this issue ?
dnfield commentedon May 31, 2022
I'm working on a new package that supports out of order defs. However, as I expected, doing so resulted in some noticable performance regressions. I'm not sure it'll make sense to ever support in this package, which is already slow enough atparsing the SVGs.
matejsnoha commentedon May 31, 2022
Thank you for your work. From my point of view it would be great if the library was able to render more SVGs, support for the really expensive features could be optional.
To work around this, we preprocess user-supplied SVGs where we move the defs to the beginning and we do a topological sort of the defs which solves the problem when they reference each other but were defined in the wrong order.
MagnusJohansson commentedon Sep 21, 2022
@Tokenyet would you please consider updating your package to use xml v6 ? Thanks.
binSaed commentedon Dec 15, 2022
@ALL
dmutoni commentedon Mar 28, 2023
Any updates?