Skip to content

WIP: Issue 175: Improved Illustrator file handling

Windell Oskay requested to merge dpi_ai into master

Improving AI SVG file support

Following extensive work to understand the structure of SVG exported by current versions of Adobe Illustrator ( #175 (closed) and several issues linked therein), we came up with a to-do list for Inkscape's ability to work with SVG documents exported from Illustrator:

  • Layer import
    • Any group element that contains a non-empty data-name attribute should be treated as a layer in Inkscape.
    • An import/conversion extension could manage this by checking all groups to see if they have that attribute.
    • For every group that has a non-empty data-name attribute $A, we would add the following two attributes: inkscape:label="$A" and inkscape:groupmode="layer".
  • DPI conversion from 72 dpi to 96 dpi for correct size of the imported document
  • Correct treatment of hidden objects in all cases
  • Write documentation with recommended export procedure* from Illustrator.

This merge request reflects a new approach to the problem that appears to meet all four requirements.

In the extensions menu

Rather than an "import extension," this extension is implemented as a regular "extensions menu" item, residing in the Document submenu.

There are several arguments that I will put forward for this approach:

  1. Import extensions do not appear to run consistently in all situations where one might expect them to. While it may be nice to address this at some point, the proposed implementation works around that issue.
  2. Import extensions that address SVG files may be particularly difficult to work with because there are many other bits of code that assert priority when working with SVG files.
  3. Illustrator has dozens of possible format options for exporting SVG. Trying to detect and handle all of them automatically is (in my view) not currently practical. Implementing automatic conversion when importing Illustrator SVG could easily end up as a frustrating user experience, with false positives and negatives.
  4. As an item in the extensions menu, there is no disruption or change to the default experience that anyone will have working with any SVG file. The user experience is strictly "opt in".
  5. It is reasonable to expect that some users will prefer to work with the SVG "as exported", without any additional processing.
  6. There is precedent for this kind of script in the Extensions > Document submenu. The 90/96 DPI conversion scripts already reside there.
  7. Implementing this as a GUI-bearing "extensions menu" item gives us a solid and consistent place to display the user documentation-- meeting one of our four checkboxes.

A tiny GUI

While there are no options for the user to set, there is a window that displays suggested usage:

Screen_Shot_2020-06-03_at_8.12.35_PM

It appears to work

While tests are included in this MR, attached here is an Illustrator SVG that you can try within Inkscape. When you open this in Inkscape, the document artboard size is incorrect (not 8.5 x 11 inches), and no layers are visible. After running the new extension, the document artboard size is correct, the 1-inch squares are 1-inch squares, and all layers and sublayers actually exported by Illustrator are present and can be manipluated in the Layers panel. (This sample file is a file-size reduced version of the same test document and with the same layer structure used in #175 (closed) .)

Additional work, possible side effects

As part of this work, I have refactored the dpiswitcher routine.

  • The dpiswitcher code now supports arbitrary DPI_A -> DPI_B changes, rather than just 90->96 and 96->90.
  • I found and fixed a bug in the implementation such that the grid now correctly changes with both 90->96 and 96->90 scaling. Because of this bug fix, the output reference files for the tests had to be updated.
  • A breaking change is that the two DPI switch extensions now pass two floating point parameters as arguments (DPI_A, DPI_B), rather than a string ("0" or "1") to indicate what action is to be performed. While this will not affect users making use of Inkscape through the GUI, it is an API change.
  • If it is deemed necessary, I can add a switcher input again for backwards compatibility of the API. (My initial feeling is that this is not necessary.)
  • Slightly better tests and pylint score on the two dpiswitcher extensions.

Code review and consideration requested.

Please consider this set of changes. I think that this represents a potential step forward and I'm happy to further discuss any part of this project.

Possible future step

While it is not included as part of this merge request, if this MR is accepted, I would like to suggest that the old "aisvg" import extension be removed. It is not, as presently implemented, helpful in any way that I can see when dealing with AI SVG files.

Edited by Windell Oskay

Merge request reports