Closed YishiMichael closed 1 year ago
This has been noticed before. If the use
is defined in a defs
at the time everything is good. But, the would-be look ahead parts where the use in defs uses the thing not yet defined is a problem. Specifically #160 is intended to address this based on #156. The only thing to do is pre-parse the tree and have access to the entire shadow-dom tree before attaching the use elements.
It's on the agenda but is a bit of a rarer use case. It does happen and use objects referencing future objects just like css sheets affecting objects in the past, isn't quite there because of the ordering of the parsing.
This was fixed in #160.
Specifically it should handle your case. Even when that ordering worked it would get the element with the get by id
and have used the same use id. Now it should play back the relevant portions of the xml within a use object correctly.
Many thanks for your help! I tried with the svg above and found all use
elements are mapped to their corresponding elements. However, I noticed that the transform
attributes of these elements are wierdly identity matrices, making these shapes completely overlapping with each other, rather than arranged horizontally as the x
and y
attributes suggest.
Parsing result:
Expected result:
I wonder if I've missed any method to properly obtain transformed positions, or any bug occurs somewhere.
It appears that I missed a spot. The x, y values are supposed to override the other values. So if you set x, y values, it's supposed to compound them in a particular way that is currently wrong. I'll check into correcting that.
When briefly scanning the code, I came up with two little suggestions.
pi
in function RoundShape._ramanujan_length
, but is not imported definitely. It should be changed to tau / 2
.Use
class can inherit Group
directly, as Use
is itself a container. This would also help when using SVG.elements
method to expand elements contained inside Use
instances.I did expand the Use instances a bit to include the x, y, height, and width specifically because I needed those to not propagate per spec.
This should be fixed in https://github.com/meerk40t/svgelements/pull/193
Okay, should be fixed in 1.8.1
Thanks a lot! Now the result is as expected.
Summary Description
There are some problems when parsing elements which refer to other elements defined later, as well as elements with a transform parameter which are reused for multiple times. The latter of them may have been mentioned in #169.
Additional Details
When trying to deal with https://github.com/3b1b/manim/issues/1760, I notice that svgelements fails to handle the following svg file:
There're two issues popping out. Firstly, the id
g6-65
uses glyphg3-65
, which is defined after it, making svgelements cannot recognize the element and returnsSVGElement
instances instead ofPath
s. Secondly, if I switch these two lines, from the result of parsing it can be noticed that theg6-65
elements are really far apart, and are even not aligned horizontally given they
attributes are equal. The latter of them may have been mentioned in #169.