-
Notifications
You must be signed in to change notification settings - Fork 459
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
Parse error on valid SVG #552
Comments
You didn't include the SVG itself, but this is almost certainly a duplicate of #102 - this library expects references to be declared before use, which is not exactly what the spec requires but allows for less memory usage/faster parsing. |
Yes, I did attach it. It's the markdown thing at the end that refers to https://github.com/dnfield/flutter_svg/files/6463564/anglo.svg.zip - github forced me to put it in a zip file. Any thoughts as to when the full SVG spec will be implemented? |
As in the readme, this does not intend to conform to the full SVG spec, which would require (among other things) full support for CSS, JavaScript, and foreign object elements. That said, the smaller ask here of out of order references is trickier than it seems at first. I have no active plans to implement it, but would be willing to review a PR that implemented it efficiently :) |
Well, I think the mainline description of this over at pub.dev should mention that it only parses a subset of SVG, in the first sentence. That's much, much too important to bury ten paragraphs down, under a fairly innocuous heading - "Check SVG compatibility" sounds like you're validating the SVG for correctness, and not like you're checking if it's in the subset implemented by this library. Anyway, the standard technique for dealing with this sort of thing is to put forward reference objects in the tree, and then do a pass over the tree dereferencing them. The technique is well covered in the Dinosaur book. It would be a fair bit of surgery to the code you have now, but a generic On a lark, I hacked enough of this to run into some other areas where the incomplete nature of the SVG support convinced me that there's a lot more to do here than just forward references, in order to render typical SVG files (including the ones I have). So I won't be pursuing this, but it helps illustrate the technique. Like I suggested earlier, to do this well you'd want to put it up at the Drawable level, and probably go through a pass over the tree to dereference all the forward references in one go - I won't repeat the whole Dinosaur book here, though :-)
|
Documenting that higher up is completely fair. At one point, the README was significantly shorter and as its grown some of that has gotten spread out further down :) My largest customers are very sensitive to startup/parsing time and need to run efficiently in relatively low memory environments. My main concern has been that it's better to fail on a feature that would be slow than to silently support it and just be slow. I suppose the library could print out a warning, but this is something that should be pretty easy to preprocess - tools like The problem is both in the parsing and the modeling. Your suggestion wouldn't pass analysis, because it has mutable fields and its base class is One of my difficulties with this is that it's easily preprocessed away with existing tools. |
Your suggestion wouldn't pass analysis, because it has mutable fields and its base class is @immutableLike I said, the code you're looking at was a quick hack, to see what other obstacles there were. Blowing off @immutable for a ten-minute test hack was entirely intentional. The full solution I outlined would result in an immutable end product. ... there are paths where you end up with several levels of forwarding going on that has to get merged and resolvedYes. Standard solutions apply here. I don't want to recapitulate the whole compiler construction textbook here (the Dragon book, ISBN 0-321-48681 -- I may have said "Dinosaur" before; it's been a while since undergrad!), but in short, what you do is defer resolution of everything that can't immediately be resolved, then do a depth-first pass over the tree. That way, you in effect start from the leaves, and work your way up - it's a simple recursive algorithm that deals with the multi-level referencing you describe. If your tree is set up right, this part is a line or two of code. Compared to the overhead of lexing, this kind of semantic tree traversal has a time complexity that is completely insignificant. Perhaps two orders of magnitude faster, typically? In terms of memory usage, it temporarily adds a small amount of memory, of the kind that's extremely efficiently swept away by modern GC implementations. |
The attached SVG validated as a correctly-formatted UTF-8 encoded SVG 1.1 document according to https://validator.w3.org/check , but it generates the following error:
Reproduced with:
FWIW, this is on macos desktop...
flutter_svg version is 0.22.0
The text was updated successfully, but these errors were encountered: