From 473b53fe3cd02f0aca8efd88aab34f9cd1c672ec Mon Sep 17 00:00:00 2001 From: Calixte Denizet Date: Mon, 8 Jun 2026 19:09:39 +0200 Subject: [PATCH] Handle TR2 with /Default entry It fixes #21406. --- src/core/evaluator.js | 16 ++++++++++++++-- test/pdfs/issue21406.pdf.link | 2 ++ test/test_manifest.json | 8 ++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 test/pdfs/issue21406.pdf.link diff --git a/src/core/evaluator.js b/src/core/evaluator.js index 6787040ca..ca5b702b3 100644 --- a/src/core/evaluator.js +++ b/src/core/evaluator.js @@ -1205,9 +1205,22 @@ class PartialEvaluator { } break; case "TR": + case "TR2": { + // TR2 takes precedence over TR (see PDF 32000-1:2008, Table 58), so + // ignore TR when a TR2 entry is present in the same dictionary. + if (key === "TR" && gState.has("TR2")) { + break; + } + // For TR2 the name /Default denotes "the transfer function that was + // in effect at the start of the page" (PDF 32000-1:2008, Table 58). + // A page always starts with the identity transfer function, hence + // /Default (and /Identity) means "no transfer function" here, which + // clears any filter previously set on the display side (issue 21406). + // `handleTransferFunction` returns `null` for those names. const transferMaps = this.handleTransferFunction(value); - gStateObj.push([key, transferMaps]); + gStateObj.push(["TR", transferMaps]); break; + } // Only generate info log messages for the following since // they are unlikely to have a big impact on the rendering. case "OP": @@ -1217,7 +1230,6 @@ class PartialEvaluator { case "BG2": case "UCR": case "UCR2": - case "TR2": case "HT": case "SM": case "SA": diff --git a/test/pdfs/issue21406.pdf.link b/test/pdfs/issue21406.pdf.link new file mode 100644 index 000000000..2d49528a6 --- /dev/null +++ b/test/pdfs/issue21406.pdf.link @@ -0,0 +1,2 @@ +https://github.com/user-attachments/files/28716910/emptyPage.pdf + diff --git a/test/test_manifest.json b/test/test_manifest.json index e64216b03..f44db6344 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -14364,5 +14364,13 @@ "md5": "702be2459f9bdbe93338ab3a584babc4", "rounds": 1, "type": "eq" + }, + { + "id": "issue21406", + "file": "pdfs/issue21406.pdf", + "md5": "d8042e1ee1213e8b0f1f9383d218277f", + "rounds": 1, + "link": true, + "type": "eq" } ]