chiark / gitweb /
svg processing: Put through usvg before inkscape as well as after
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 10 Jan 2021 22:04:47 +0000 (22:04 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 10 Jan 2021 23:19:44 +0000 (23:19 +0000)
Our copy of library/wikimedia/chess-_c-commoner.svg from
  https://upload.wikimedia.org/wikipedia/commons/7/7d/Commoner_Transparent.svg
generates this error from inkscape's color_replace extension:

  $ /usr/share/inkscape/extensions/color_replace.py -f 'ffffff' -t 'abcbfb' library/wikimedia/chess-_c-commoner.svg >library/wikimedia/chess-b-commoner.coloured.svg.0.tmp
  Traceback (most recent call last):
    File "/usr/share/inkscape/extensions/color_replace.py", line 25, in <module>
      c.affect()
    File "/usr/share/inkscape/extensions/inkex.py", line 283, in affect
      self.effect()
    File "/usr/share/inkscape/extensions/coloreffect.py", line 37, in effect
      self.getAttribs(self.document.getroot())
    File "/usr/share/inkscape/extensions/coloreffect.py", line 45, in getAttribs
      self.getAttribs(child)
    File "/usr/share/inkscape/extensions/coloreffect.py", line 45, in getAttribs
      self.getAttribs(child)
    File "/usr/share/inkscape/extensions/coloreffect.py", line 45, in getAttribs
      self.getAttribs(child)
    File "/usr/share/inkscape/extensions/coloreffect.py", line 45, in getAttribs
      self.getAttribs(child)
    File "/usr/share/inkscape/extensions/coloreffect.py", line 43, in getAttribs
      self.changeStyle(node)
    File "/usr/share/inkscape/extensions/coloreffect.py", line 55, in changeStyle
      if node.attrib.has_key('style'):
  AttributeError: '_ImmutableMapping' object has no attribute 'has_key'
  $

This is reproducible by hand via the inkscape GUI.

Emprically, running the file through usvg first fixes it.  *shrug*

We need to do this before we can start relying on the recolouring
support.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
media-scraper

index cbd8e68f6098c74216e2465063a5bf302f63d0be..88a15d2b9f55dd52c28f0e6e9cae22cf71281828 100755 (executable)
@@ -229,18 +229,22 @@ END
        my $coloured = $lupstream;
 
        my $ci = 0;
-       my $cfp = '$<';
+       my $cfp;
        my $emitmap = sub {
          my ($from, $to) = @_;
          confess if $from =~ m/\W/ || $to =~ m/\W/;
 
-         my $nfp = "\$@.$ci.tmp";
          $coloured = $ncoloured;
-         print $makefile <<END or die $! if $ci == 0;
+         if (!defined $cfp) {
+           $cfp ="\$@.$ci.tmp";
+           print $makefile <<END or die $!;
 LIBRARY_CLEAN += $ncoloured
 $ncoloured: $lupstream Makefile $makepath
+       \$(USVG_CMD) -c - <\$< >$cfp
 END
+         }
          $ci++;
+         my $nfp = "\$@.$ci.tmp";
          print $makefile <<END or die $!;
        \$(RECOLOUR_SVG) -f '$from' -t '$to' $cfp >$nfp
 END