Internal PDF Import causes proliferation of clipping paths
Summary:
Importing a PDF creates a clipping path for each path definition. In extreme cases, this causes considerable file size increase and affects performance. I believe this may be a part of the cause of issue #5153, as the sample file from this issue generates 1120 clipping paths, many of which are duplicates.
Steps to reproduce:
The attached file is a very simple PDF with a single page as follows:
% page size [0, 0, 612, 792]
100 100 300 300 re
W % define clipping path
s % also stroke it to see what's happening
0 0 m
200 200 l % a clipped line
s
50 150 m
150 150 l % another clipped line
s
1 0 0 RG % red stroke to show shifted stuff
1 0 0 1 150 50 cm % shift the origin
100 100 300 300 re % redraw the same rectangle
s
To see the issue, do the following:
- Convert the attached file to svg:
inkscape -o clipping_shift.svg clipping_shift.pdf - Open the resulting file in a text editor
What happened?
Each path created from the PDF is accompanied by a clipping path, effectively doubling the number of path elements in the resulting SVG. For this simple example, the first two clipping paths are identical, while the third is translated in the opposite direction from the stroking path.
What should have happened?
I expected only one clipping path, as with the PDF definition.
For the second clipped line in the same coordinate space, it seems like it might work to check if the clipping state has changed, and if not, refer to the first path. The transformed situation is trickier, but is actually a significant effect in some cases (I have a proprietary document that spawns over 25,000 clipping paths, each translated by about 2 units!). A naive solution might be to provide an option to destructively transform the paths on import, but there's probably a reason this is a bad idea.
Sample attachments:
Minimal example: clipping_shift.pdf
Version info
Inkscape 1.3.2 (091e20ef0f, 2023-11-25)
GLib version: 2.80.3
GTK version: 3.24.43
glibmm version: 2.66.7
gtkmm version: 3.24.9
libxml2 version: 2.12.8
libxslt version: 1.1.41
Cairo version: 1.18.0
Pango version: 1.54.0
HarfBuzz version: 8.5.0
OS version: Fedora Linux 40 (Workstation Edition)