Rewrite HP-GL import using Pyparsing (+ HP-GL/2 support)

What does the merge request do?

Rewrite the HP-GL import based on the "PCL 5 Printer Language Technical Refence Manual Part II (1999)" and "The HP-GL/2 and HP RTL Reference Guide (1996)".

Fixes #501 (closed)

The following HP-GL commands are supported:

Group fully supported partially supported not supported
The Configuration and Status Group CO, DF, IN, IP, IR, IW, SC RO (subsequent IP / PR commands don't work as specified) RP, PG (only make sense for physical printers)
The Vector Group AA, AR, AT, BR, BZ, CI, PA, PD, PE, PR, PU, RT - -
The Polygon Group EA, ER, EW, FP, PM, RA, RR, WG - -
The Line and Fill Attributes Group PW, WU, UL, TR, SP FT (only solid fills)
LA (Triangle line ends don't exist in SVG)
LT (adaptive line types not implemented, and for corner dots I started hitting Inkscape bugs)
RF (Raster pattern)
SM (Marker-ish)
SV (what even is that?)
The Character Group - - all (Text not implemented)

For the majority of HP-GL files that I found on the internet, that's more than sufficient. (Actually they often use a small subset of those commands, since they are autogenerated, such as by the Inkscape export. But even more complex examples like the ones bundled with PloViewMini and HpglView are rendered mostly correct.) Anyway, I wanted to stop at 1000 lines of state machine code.

Implementation notes

The unit test output contains the same path data as the old hpgl import.

This adds the dependency pyparsing, I'll make sure to create MRs for the Inkscape packaging scripts.

I've found pyparsing to be very performant, and to scale about linearly with the number of resulting SVG paths. For a 100KB hpgl file (400 KB SVG with 1500 paths), the entire parsing including processing and construction of the document tree takes about 4 seconds.

Mypy and pylint are happy about my code.

TODO: How to specify more than one file extension? Comma separating doesn't work, and duplicating the ink doesn't work either. HP-GL doesn't have a well-defined extension, but I'd like to support at least *.hpgl and *.plt (that's the file type of most files online). @doctormo do you have a suggestion here?

Summary for release notes

HP-GL/2 import has been rewritten to support more complex HPGL files including fill and line, non-linear draw commands, scaling and rotating of the document.

Checklist

  • Add unit tests (if applicable)
  • Changes to inkex/ are well documented
  • Clean merge request history

PS: Which file format should I do next? :)

Edited by Jonathan Neuhauser

Merge request reports

Loading