Open JoKalliauer opened 6 years ago
This and #210 have the same underlying cause, namely that removeUnusedAttributesOnParent
prunes the relevant attribute causing the bug. Looking at that function, it seems like it is only concerned about whether the attribute is overwritten later and not whether the current node make use of the attribute itself.
@Ede123 Do you have any input for how this should be corrected? I note that removeUnusedAttributesOnParent
operations on a lot of attributes and some of them have broader scope than just text.
Yeah, that function seems dangerous...
I'm afraid we won't be able to fix this easily as long as we don't add proper inheritance rules for all attributes to Scour (i.e. we actually know which attributes apply to which elements).
We might be able to get away with treating text elements special as a workaround (i.e. check if there are non-empty text-nodes before removing styles from the parent text element) but I'm afraid this could become ugly code-wise while potentially leading to missed optimizations.
P.S. One more odd thing I also noticed in removeUnusedAttributesOnParent
:
There's a if len(childElements) <= 1:
in there that I don't understand - why would we want to not optimize parents with one child?
Is there an option to dissable removeUnusedAttributesOnParent
?
E.g. https://tools.wmflabs.org/svgworkaroundbot/ uses scour to make workarounds for librsvg, this script is used for SVGWorkaroundBot on Commons. So the Bot ideally should be able to process files without human review, therefore it needs a save option, with "minimal file-changes".
Yeah, that function seems dangerous...
I'm afraid we won't be able to fix this easily as long as we don't add proper inheritance rules for all attributes to Scour (i.e. we actually know which attributes apply to which elements).
[...]
What would this take? Looking at the attribute for all elements above the current one until a match is found (or we reach the document root)?
P.S. One more odd thing I also noticed in
removeUnusedAttributesOnParent
: There's aif len(childElements) <= 1:
in there that I don't understand - why would we want to not optimize parents with one child?
No clue; I think this is the first time I am working with this function, but it does seem weird glance and would do well with a comment if there is a valid reason.
Processiong File:Envelope_string_art.svg with
removes
font-size="2em"
input.svg.txt
The output is: output.svg.txt
so
font-size="2em"
is removed in both<text>
-tagsCopyright
License: [{{self|cc-by-sa-3.0,2.5,2.0,1.0|GFDL}}](https://creativecommons.org/licenses/by-sa/3.0/deed) Author: [{{Ut|QFA7301}}](https://commons.wikimedia.org/wiki/User_talk:QFA7301), [{{Uc|Daniel129}}](https://commons.wikimedia.org/wiki/User_talk:Daniel129) Source: https://upload.wikimedia.org/wikipedia/commons/6/61/2016SongjiangTram.svg Details: [File:2016SongjiangTram.svg](https://commons.wikimedia.org/wiki/File:2016SongjiangTram.svg