April - AI Extension 2023
6 de May de 2023 a las 21:29
To allow the import of Adobe Illustrator files into Inkscape, we develop a Python extension. This post outlines the progress in the 2nd month of the project, April 2023. Work is carried out inside the git repository extension-ai. To read more about the progress in March, read the last blog post.
Initially, we used pyparsing to parse the Adobe Illustrator files. Pyparsing delivers a lot of flexibility at the cost of performance. Adobe Illustrator files however do not need features like backtracking or fine-grained matching to parse them. This is why we opted to create a new parser from scratch for the file format: It is faster and tailored to the specifics of the Adobe Illustrator File Format. A lot of the code that has been written already can be reused though the migration to the new parser: Extraction of the plain text, embedding the extension into Inkscape, tests and examples.
Nicco Kunzmann
Nicco Kunzmann's work is done within a contract with the SFC. This section highlights the work done in the month of April. Since there was the Hackfest in March, a lot of progress was made in March. In April, the development slowed down a bit. Here is a summary of the work done:
- Work with pyparsing and tests to create SVG Rectangles. Rectangles are specified in the .ai files as Live Shapes. See Issue 27.
- For the faster parser:
- Outline of the architecture for the parser. Requirements:
- Fast lookup (line start and line end) with only a few function calls.
- Consistent interface but different parsers for different sections of the .ai file. (headers, Live Shapes, Text Specification)
- Flexible composition of elements of the grammar.
- Lazy parsing of content only if needed.
- The specification of the grammar should be created once only and never again regardless of how many .ai documents are processed.
- Modularization must be possible to structure the code.
- Outline of the architecture for the parser. Requirements:
- The parser implementation was done with the architectural concerns mentioned above, polymorphy and test-driven development.
- An example implementation was the migration of parsing the colors (specified and reverse-engineered ones) from pyparsing to the new, lazy parser.
- Layers were migrated. That they can be recursive (layer and sub-layer) will be part of May's work.
- One of the test files runs through all the example .ai files and records how far we progressed in our implementation:
- Can the file be extracted? 100%
- Can the file be parsed into the new lazy object structure? 100%
- Are there any lines we do not understand? 0% - All files contain unknown lines.
To summarize: After month 2, we have a parser architecture tailored to the .ai files for fast parsing. The progress can be tracked. Sections and elements of the AI files can be flexibly and lazily parsed and documented. This is a solid base to extend the code base in May: We can expect to convert some .ai files to SVG soon.