PDF import ignores OCGs/layers within form XObject

Summary:

Any OCGs within Form XObjects on a PDF are not converted to groups. Instead, all the content within the form is grouped in a single group.

Originally reported as a Pattern Projector issue here.

Steps to reproduce:

  • Created a layered SVG in inkscape (attached)
  • Exported to PDF using new CapyPDF exporter, which creates nested groups (attached)
  • Open the PDF in inkscape
  • Look at the Layers and Objects tab

What happened?

Groups are created based on PDF objects, OCGs are ignored image

What should have happened?

The OCGs should be interpreted as SVG layers (e.g. in Evince):

image

Sample attachments: Original SVG: test-layers.svg

Exported PDF: test-layers.pdf

Note: I think this is more an importer issue than exporter, as it is not unique to Inkscape's PDF exporter.

Version info

Inkscape 1.5-dev (755fd8734f, 2025-05-05)

                      Compile  (Run)
    GLib version:     2.84.1
    GTK version:      4.18.4 (4.18.4)
    glibmm version:   2.83.1
    gtkmm version:    4.18.0
    libxml2 version:  2.12.10
    libxslt version:  1.1.43
    Cairo version:    1.18.2 (1.18.2)
    Pango version:    1.56.3 (1.56.3)
    HarfBuzz version: 10.4.0 (10.4.0)
    Poppler version:  25.02.0

    OS version:       Fedora Linux 42 (Workstation Edition)

I think I know why this issue may be happening and have poked around in the PDF import code before, so I can take a crack at fixing it.

Edited by Charlotte Curtis