abey79 / vpype

The Swiss-Army-knife command-line tool for plotter vector graphics.
https://vpype.readthedocs.io/
MIT License
703 stars 62 forks source link

Consider preserving stroke color #145

Closed lostPixels closed 2 years ago

lostPixels commented 3 years ago

Title says it all. I got vpype working and was hoping to use the crop feature, but my plots are multi-color and vpype crops fine, but blows away my colors. Is this a challenging feature to add?

abey79 commented 3 years ago

Thanks for your feedback @lostPixels.

Short answer is yes, it wouldn't be a small endeavour to preserve all paths attributes. The main reason is that paths are constantly deleted/modified/recreated by most commands (e.g. linemerge) and it would be rather difficult to track attributes in this process (what colour should I use when two paths of different colour are merged?). I don't see that happening any time soon.

What may be happening (and is already on the roadmap) is per-layer attributes (mainly colour and pen-width), possibly when addressing #35. This would not address the general case where each path might have a different colour but will work well when layering is done by colour (which is the goal of #35). When layering is done with top-level <g> (as is the case now), this could also be made to work if the colour is defined at the group level (and would ignore any colour set in the paths themselves). This may or may not address your need, depending on how your SVG is structured.

abey79 commented 3 years ago

One more thing: vpype being rather destructive in a way (all curves are sliced into small segments), it's really meant as the last stop before plotting. Is this what you intended to do? If so, what is the reason for the colour fidelity requirement? (To be clear, I'm not trying to imply there is none, I'm just trying to understand better your workflow and needs.)

NelsonMinar commented 3 years ago

I came to request this feature too. Your proposal to try to preserve per-layer colors if they exist would work just fine for me.

I generate layers with Python svgwrite like this:

<g inkscape:groupmode="layer" inkscape:label="1 star lines" stroke="purple">

I'm writing multi-layer SVGs, one layer per pen color. The colors I'm writing roughly match the pens I intend to use so the preview looks close to the final print.

I could make the case for pen width too although I don't currently use it. If you choose to support that be aware of non-scaling-stroke; a necessity if you are using SVG to scale line drawings.

abey79 commented 3 years ago

@NelsonMinar thanks for your comment. I'm aware that this feature is one of the top requested and is high up in my priority list.

As for the pen width comment, it's definitely on the list but let's clarify that there won't be par-path metadata in the foreseeable future. It's going to be a per-layer attribute and so it will remain "destructive" w.r.t the original SVG. I'll have to put in place some kind of heuristic to decide on the layer color/pen-width/etc. when they contain heterogenous paths.

For the same reason, "non-scaling-stroke" will mostly likely be implied and forced. This makes sense because the pen width should model the actual, physical pen width to be used on the given layer, which is obviously not going to scale with whatever operation the user inserts in the pipeline.

abey79 commented 2 years ago

This will be addressed in #359 and when #35 is implemented (which is high on the priority list once metadata is merged)