From 47682985d34c0edc79a8a4a37597e9a0ed51530c Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Wed, 23 Nov 2022 12:58:00 +0100 Subject: [PATCH] Add support for Optional Content in TilingPatterns (issue 15716) This can't be a particularly common feature, since we've supported Optional Content for over two years and this is the very first TilingPattern-case we've seen. --- src/display/api.js | 2 +- src/display/canvas.js | 10 ++- test/pdfs/.gitignore | 1 + test/pdfs/issue15716.pdf | 132 +++++++++++++++++++++++++++++++++++++++ test/test_manifest.json | 15 +++++ 5 files changed, 156 insertions(+), 4 deletions(-) create mode 100644 test/pdfs/issue15716.pdf diff --git a/src/display/api.js b/src/display/api.js index 9ab632bfa..32d870f52 100644 --- a/src/display/api.js +++ b/src/display/api.js @@ -3245,7 +3245,7 @@ class InternalRenderTask { this.commonObjs, this.objs, this.canvasFactory, - optionalContentConfig, + { optionalContentConfig }, this.annotationCanvasMap, this.pageColors ); diff --git a/src/display/canvas.js b/src/display/canvas.js index 61db15ef1..d447cf7a9 100644 --- a/src/display/canvas.js +++ b/src/display/canvas.js @@ -1022,7 +1022,7 @@ class CanvasGraphics { commonObjs, objs, canvasFactory, - optionalContentConfig, + { optionalContentConfig, markedContentStack = null }, annotationCanvasMap, pageColors ) { @@ -1051,7 +1051,7 @@ class CanvasGraphics { this.tempSMask = null; this.suspendedCtx = null; this.contentVisible = true; - this.markedContentStack = []; + this.markedContentStack = markedContentStack || []; this.optionalContentConfig = optionalContentConfig; this.cachedCanvases = new CachedCanvases(this.canvasFactory); this.cachedPatterns = new Map(); @@ -2471,7 +2471,11 @@ class CanvasGraphics { ctx, this.commonObjs, this.objs, - this.canvasFactory + this.canvasFactory, + { + optionalContentConfig: this.optionalContentConfig, + markedContentStack: this.markedContentStack, + } ); }, }; diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index 2a1db6fe9..a2f82e23b 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -440,6 +440,7 @@ !issue6889.pdf !issue11473.pdf !bug1001080.pdf +!issue15716.pdf !bug1671312_reduced.pdf !bug1671312_ArialNarrow.pdf !issue6108.pdf diff --git a/test/pdfs/issue15716.pdf b/test/pdfs/issue15716.pdf new file mode 100644 index 000000000..4414485e2 --- /dev/null +++ b/test/pdfs/issue15716.pdf @@ -0,0 +1,132 @@ +%PDF-1.7 + +1 0 obj +<< + /Type /Catalog + /Pages 2 0 R + /OCProperties + << + /OCGs [1000 0 R 1001 0 R] + /D << /Order [1000 0 R 1001 0 R] >> + >> +>> +endobj + +2 0 obj +<< /Type /Pages /Count 1 /Kids [ 10 0 R ] >> +endobj + + +% PAGE 1 + +10 0 obj +<< + /Type /Page + /Parent 2 0 R + /MediaBox [ 0 0 200 200 ] + /Contents 11 0 R + /Resources + << + /Pattern << /P1 12 0 R >> + >> +>> +endobj + +11 0 obj +<< /Length 146 >> +stream + /Pattern cs % Set pattern color space + /P1 scn % Set pattern as nonstroking color + 0 200 200 -200 re % Construct rectangular path + f % Fill path +endstream +endobj + +12 0 obj +<< + /Type /Pattern + /PatternType 1 + /PaintType 1 + /TilingType 2 + /BBox [0 0 100 100] + /XStep 100 + /YStep 100 + /Resources + << + /Font << /F1 13 0 R >> + /Properties << /L1 1000 0 R /L2 1001 0 R >> + >> + /Length 788 +>> +stream + BT % Begin text object + /F1 1 Tf % Set text font and size + 64 0 0 64 7.1771 2.4414 Tm % Set text matrix + 0 Tc % Set character spacing + 0 Tw % Set word spacing + /OC /L1 BDC % Begin layer + 0.0 0.0 0.0 rg % Set nonstroking color to black + (\001) Tj % Show spade glyph + EMC % End layer + 0.7478 -0.007 TD % Move text position + /OC /L2 BDC % Begin layer + 1.0 0.0 0.0 rg % Set nonstroking color to red + (\002) Tj % Show heart glyph + EMC % End layer + -0.7323 0.7813 TD % Move text position + /OC /L2 BDC % Begin layer + 1.0 0.0 0.0 rg % Set nonstroking color to red + (\003) Tj % Show diamond glyph + EMC % End layer + 0.6913 0.007 TD % Move text position + /OC /L1 BDC % Begin layer + 0.0 0.0 0.0 rg % Set nonstroking color to black + (\004) Tj % Show club glyph + EMC % End layer + ET % End text object +endstream +endobj + +13 0 obj +<< + /Type /Font + /Subtype /Type1 + /BaseFont /ZapfDingbats + /Encoding + << + /Type /Encoding /Differences [1 /a109 /a110 /a111 /a112] + >> +>> +endobj + + +% SHARED OBJECTS + +1000 0 obj +<< /Type /OCG /Name (Black) >> +endobj + +1001 0 obj +<< /Type /OCG /Name (Red) >> +endobj + + +xref +0 3 +0000000000 65535 f +0000000010 00000 n +0000000151 00000 n +10 4 +0000000223 00000 n +0000000367 00000 n +0000000565 00000 n +0000001603 00000 n +1000 2 +0000001778 00000 n +0000001828 00000 n + +trailer +<< /Size 8 /Root 1 0 R >> +startxref +1877 +%%EOF diff --git a/test/test_manifest.json b/test/test_manifest.json index ad74e9133..96ab0d82b 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -4562,6 +4562,21 @@ "rounds": 1, "type": "text" }, + { "id": "issue15716", + "file": "pdfs/issue15716.pdf", + "md5": "4d89aabeb97fcb181662406f092bbeb0", + "rounds": 1, + "type": "eq" + }, + { "id": "issue15716-no-red-oc", + "file": "pdfs/issue15716.pdf", + "md5": "4d89aabeb97fcb181662406f092bbeb0", + "rounds": 1, + "type": "eq", + "optionalContent": { + "1001R": false + } + }, { "id": "issue845", "file": "pdfs/issue845r.pdf", "md5": "b5f8fe4005cf3fb685fdb4a4c44ee4a2",