From 29d883fb5aaed5ef007af432df2e2963afa2eb46 Mon Sep 17 00:00:00 2001 From: Calixte Denizet Date: Sun, 15 Nov 2026 20:49:46 +0100 Subject: [PATCH] Save and restore the state of hidden form XObjects Their operators still change the transform and the clip. --- src/display/canvas.js | 8 ++----- test/pdfs/.gitignore | 1 + test/pdfs/hidden_oc_form_cm.pdf | 40 +++++++++++++++++++++++++++++++++ test/test_manifest.json | 8 +++++++ 4 files changed, 51 insertions(+), 6 deletions(-) create mode 100644 test/pdfs/hidden_oc_form_cm.pdf diff --git a/src/display/canvas.js b/src/display/canvas.js index cf5d5272c..5f936cdac 100644 --- a/src/display/canvas.js +++ b/src/display/canvas.js @@ -3352,9 +3352,8 @@ class CanvasGraphics { } paintFormXObjectBegin(opIdx, matrix, bbox) { - if (!this.contentVisible) { - return; - } + // Hidden forms still need their own state, since their transforms and + // clips are applied. this.save(opIdx); this.baseTransformStack.push(this.baseTransform); @@ -3379,9 +3378,6 @@ class CanvasGraphics { } paintFormXObjectEnd(opIdx) { - if (!this.contentVisible) { - return; - } this.restore(opIdx); this.baseTransform = this.baseTransformStack.pop(); } diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index 765830916..1c47e4daa 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -1074,3 +1074,4 @@ !issue16880.pdf !issue16754.pdf !scripting_user_activation.pdf +!hidden_oc_form_cm.pdf diff --git a/test/pdfs/hidden_oc_form_cm.pdf b/test/pdfs/hidden_oc_form_cm.pdf new file mode 100644 index 000000000..bc2382fc9 --- /dev/null +++ b/test/pdfs/hidden_oc_form_cm.pdf @@ -0,0 +1,40 @@ +%PDF-1.7 +%âãÏÓ +1 0 obj +<< /Type /Catalog /Pages 2 0 R /OCProperties << /OCGs [5 0 R] /D << /OFF [5 0 R] >> >> >> +endobj +2 0 obj +<< /Type /Pages /Kids [3 0 R] /Count 1 >> +endobj +3 0 obj +<< /Type /Page /Parent 2 0 R /MediaBox [0 0 200 200] /Resources << /Properties << /oc1 5 0 R >> /XObject << /Fm0 6 0 R >> >> /Contents 4 0 R >> +endobj +4 0 obj +<< /Length 50 >> +stream +/OC /oc1 BDC /Fm0 Do EMC 1 0 0 rg 10 10 40 40 re f +endstream +endobj +5 0 obj +<< /Type /OCG /Name (Hidden) >> +endobj +6 0 obj +<< /Type /XObject /Subtype /Form /BBox [0 0 200 200] /Length 42 >> +stream +1 0 0 1 100 100 cm 0 0 1 rg 0 0 50 50 re f +endstream +endobj +xref +0 7 +0000000000 65535 f +0000000015 00000 n +0000000120 00000 n +0000000177 00000 n +0000000337 00000 n +0000000438 00000 n +0000000485 00000 n +trailer +<< /Size 7 /Root 1 0 R >> +startxref +627 +%%EOF diff --git a/test/test_manifest.json b/test/test_manifest.json index c527ed6f8..5d46ed9b2 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -15381,5 +15381,13 @@ "rounds": 1, "type": "eq", "about": "Duplicate .notdef glyphs in a CFF font; char code 0 uses the last." + }, + { + "id": "hidden_oc_form_cm", + "file": "pdfs/hidden_oc_form_cm.pdf", + "md5": "578897c16495b96ce9997be1ec481f6e", + "rounds": 1, + "type": "eq", + "about": "The transform of a form in hidden optional content doesn't leak." } ]