Skip to content
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

Multi Action's ColorSeparation.py doesn't support colors from pallette #325

Open
devingfx opened this issue Jan 21, 2025 · 1 comment
Open

Comments

@devingfx
Copy link
Contributor

devingfx commented Jan 21, 2025

We can't use inkscape"s color palette to set custom colors to strokes.

ColorSeparation.py assumes each element's stroke of fill are plain color convertible to RGB, what may not be the case especially when dealing with color palette which use gradients even for plain colors. Even worse: inkscape uses sub-gradient for each elements even if the same color swatch is used (for a matter of gradient positioning):

<svg:defs
     id="defs996">
    <svg:linearGradient
       id="black"
       gradientTransform="matrix(0.249958,0,0,0.249958,56.5965,53.6683)"
       inkscape:swatch="solid">
      <svg:stop
         offset="0"
         id="stop8279"
         style="stop-color:black;stop-opacity:1" />
    </svg:linearGradient>
    <svg:linearGradient
       inkscape:collect="always"
       xlink:href="#black"
       id="linearGradient8283"
       x1="1334.48"
       y1="60.9108"
       x2="1386.38"
       y2="60.9108"
       gradientUnits="userSpaceOnUse"
       gradientTransform="scale(0.264583)" />
    <svg:linearGradient
       inkscape:collect="always"
       xlink:href="#black"
       id="linearGradient8295"
       x1="352.187"
       y1="-8.61656"
       x2="363.218"
       y2="-8.61656"
       gradientUnits="userSpaceOnUse" />
  </svg:defs>
  ...
  <svg:path
         inkscape:connector-curvature="0"
         id="path1952"
         d="..."
         style="display:inline;fill:url(#linearGradient8283);fill-opacity:1;stroke-width:0.352778" />
  <svg:path
         sodipodi:nodetypes="cccscccccccccccac"
         inkscape:connector-curvature="0"
         id="path1954"
         d="..."
         style="display:inline;fill:url(#linearGradient8295);fill-opacity:1;stroke-width:0.352778" />
silhouette_multi.py was called via: ['silhouette_multi.py', '--dry_run=true', '--register_once=true', '--block=true', '--verbose=true', '/tmp/ink_ext_XXXXXX.svgPGC8Z2']
Traceback (most recent call last):
  File "silhouette_multi.py", line 316, in <module>
    e.run()
  File "/usr/share/inkscape/extensions/inkex/base.py", line 250, in run
    self.save_raw(self.effect())
  File "silhouette_multi.py", line 145, in effect
    self.split_objects_by_color()
  File "silhouette_multi.py", line 136, in split_objects_by_color
    color = self.get_color(obj)
  File "silhouette_multi.py", line 99, in get_color
    color = Color(color).to_rgb()
  File "/usr/share/inkscape/extensions/inkex/colors.py", line 248, in __init__
    space, color = self.parse_str(color.strip())
  File "/usr/share/inkscape/extensions/inkex/colors.py", line 325, in parse_str
    raise ColorIdError("Color references other element id, e.g. a gradient")
inkex.colors.ColorIdError: 'Color references other element id, e.g. a gradient'

Of course the color module can not convert to RGB the string url(#linearGradient8295).
The colors have to be identified by authored string instead, but this leads to a new issue: duplicate color items for each gradient url even the underlaying sub-gradient is the same color swatch... :(

@devingfx
Copy link
Contributor Author

Maybe the solution is to search for the last gradient of the chain (the one with no xlink:href attribute and some color stops) to get an ID identifier for the color...

Exemple with SVG fragment above:

  • path1952 have fill: url(#linearGradient8283) > get linearGradient8283, it have a xlink:href=#black > get #black, it have no xlink >>> use this string as color ID, and extract 1st color stop's color to get the RGB
  • the second path1954 will lead to the same #black gradient...

@devingfx devingfx changed the title Multi Action's ColorSeparation.py doen's support colors from pallette Multi Action's ColorSeparation.py doesn't support colors from pallette Jan 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant