Add color support to DXF12 export; minor refactor to dxf12 export extension
What does the merge request do?
- Updates the code for exporting the DXF12 format so that it preserves color information
- Updates test fixtures with the colored DXF12 outputs
- Adds type hints, removes unnecessary
__future__imports, and simplifies regex use to.endswith
Note
The type hints and other cleanup are (of course) not necessary in order to support color in DXF12. If it’s preferable to change as little as possible in this changeset, let me know and I'll apply only the necessary changes.
Implementation notes
Where a color in the original SVG matches one of the 249 distinct1 DXF12-supported colors, we default to using that color; otherwise, we choose the closest color by Cartesian distance. To that end, I represented the colors as RGB-tuples, but in case there’s an existing utility function built in to find the closest color in a set, I’d be happy to change the code and use that instead.
This change also goes from walking svg.iterdescendants() once to twice, using the first pass to collect (stroke) color data and the second to actually serialize the data to DXF12. I couldn’t think of another way to do this that would actually preserve color fidelity, but again there may be some utility function I’m unaware of that could help here.
Summary for release notes
Colors are now included when saving DXF12 files.
Checklist
-
Add unit tests (if applicable) - updated unit test fixtures, but no changes were needed to the unit tests themselves
-
Changes to inkex/are well documented- no changes made to
inkex/
- no changes made to
-
Clean merge request history
-
DXF12 has 255 color codes, but 6 colors show up twice. ↩