From 0cffb5de7371b80b351113d20876b3721fdfcac3 Mon Sep 17 00:00:00 2001 From: Pavel Gribovsky Date: Mon, 19 Feb 2024 17:38:04 +0300 Subject: [PATCH] Remove mcid overriding --- src/core/bounding_boxes.js | 18 ++++++++++++++++++ src/core/catalog.js | 2 ++ 2 files changed, 20 insertions(+) diff --git a/src/core/bounding_boxes.js b/src/core/bounding_boxes.js index 82390bb447694..df8c3719662b9 100644 --- a/src/core/bounding_boxes.js +++ b/src/core/bounding_boxes.js @@ -16,6 +16,8 @@ var BoundingBoxesCalculator = (function PartialEvaluatorClosure() { this.boundingBoxes = {}; this.ignoreCalculations = ignoreCalculations; this.operationArray = []; + this.mcidArray = []; + this.sameMcidDepth = 0; this.operationIndex = -1; } @@ -410,6 +412,22 @@ var BoundingBoxesCalculator = (function PartialEvaluatorClosure() { this.boundingBoxesStack.inc(); } + // Prevent parsing of Marked content with same MCIDs + if (fn === OPS.beginMarkedContentProps && isDict(args[1]) && args[1].has('MCID')) { + const mcid = args[1].get('MCID'); + if (this.mcidArray.includes(mcid)) { + this.sameMcidDepth++; + return; + } else { + this.mcidArray.push(mcid); + } + } + + if (fn === OPS.endMarkedContent && this.sameMcidDepth !== 0) { + this.sameMcidDepth--; + return; + } + switch (fn | 0) { case OPS.restore: this.graphicsStateManager.restore(); diff --git a/src/core/catalog.js b/src/core/catalog.js index 7319ef35da534..44788ef6d5dc1 100644 --- a/src/core/catalog.js +++ b/src/core/catalog.js @@ -1637,6 +1637,7 @@ class ExtendedCatalog extends Catalog { name: name ? stringToUTF8String(name) : null, roleName: roleName ? stringToUTF8String(roleName) : null, children: this.getTreeElement(el.get('K'), page, el.getRaw('K')), + pageIndex: page, ref: ref }; } @@ -1695,6 +1696,7 @@ class ExtendedCatalog extends Catalog { name: name ? stringToUTF8String(name) : null, roleName: roleName ? stringToUTF8String(roleName) : null, children: [], + pageIndex: page, ref: ref }; }