From c6e3fc4fe688165bd9f7d6223d3ef55d935f78c1 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sun, 8 Dec 2024 14:45:54 +0100 Subject: [PATCH] Take the `userUnit` into account in the `PageViewport` class (issue 19176) --- src/display/api.js | 1 + src/display/display_utils.js | 19 ++++++++++++++----- test/pdfs/.gitignore | 1 + test/pdfs/issue19176.pdf | Bin 0 -> 466 bytes test/test_manifest.json | 7 +++++++ test/unit/api_spec.js | 34 +++++++++++++++++++++++++++++++++- 6 files changed, 56 insertions(+), 6 deletions(-) create mode 100644 test/pdfs/issue19176.pdf diff --git a/src/display/api.js b/src/display/api.js index 91cf928d1586a..e3cb683f7c94c 100644 --- a/src/display/api.js +++ b/src/display/api.js @@ -1408,6 +1408,7 @@ class PDFPageProxy { } = {}) { return new PageViewport({ viewBox: this.view, + userUnit: this.userUnit, scale, rotation, offsetX, diff --git a/src/display/display_utils.js b/src/display/display_utils.js index 3a0b653b7e793..5d40e23498d83 100644 --- a/src/display/display_utils.js +++ b/src/display/display_utils.js @@ -83,6 +83,7 @@ async function fetchData(url, type = "text") { * @typedef {Object} PageViewportParameters * @property {Array} viewBox - The xMin, yMin, xMax and * yMax coordinates. + * @property {number} userUnit - The size of units. * @property {number} scale - The scale of the viewport. * @property {number} rotation - The rotation, in degrees, of the viewport. * @property {number} [offsetX] - The horizontal, i.e. x-axis, offset. The @@ -116,6 +117,7 @@ class PageViewport { */ constructor({ viewBox, + userUnit, scale, rotation, offsetX = 0, @@ -123,11 +125,14 @@ class PageViewport { dontFlip = false, }) { this.viewBox = viewBox; + this.userUnit = userUnit; this.scale = scale; this.rotation = rotation; this.offsetX = offsetX; this.offsetY = offsetY; + scale *= userUnit; // Take the userUnit into account. + // creating transform to convert pdf coordinate system to the normal // canvas like coordinates taking in account scale and rotation const centerX = (viewBox[2] + viewBox[0]) / 2; @@ -208,12 +213,14 @@ class PageViewport { * @type {Object} */ get rawDims() { - const { viewBox } = this; + const { userUnit, viewBox } = this; + const dims = viewBox.map(x => x * userUnit); + return shadow(this, "rawDims", { - pageWidth: viewBox[2] - viewBox[0], - pageHeight: viewBox[3] - viewBox[1], - pageX: viewBox[0], - pageY: viewBox[1], + pageWidth: dims[2] - dims[0], + pageHeight: dims[3] - dims[1], + pageX: dims[0], + pageY: dims[1], }); } @@ -231,6 +238,7 @@ class PageViewport { } = {}) { return new PageViewport({ viewBox: this.viewBox.slice(), + userUnit: this.userUnit, scale, rotation, offsetX, @@ -514,6 +522,7 @@ function getXfaPageViewport(xfaPage, { scale = 1, rotation = 0 }) { return new PageViewport({ viewBox, + userUnit: 1, scale, rotation, }); diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index fc38de944c38c..5608e0df93620 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -553,6 +553,7 @@ !poppler-67295-0.pdf !poppler-85140-0.pdf !issue15012.pdf +!issue19176.pdf !issue15150.pdf !poppler-395-0-fuzzed.pdf !issue14165.pdf diff --git a/test/pdfs/issue19176.pdf b/test/pdfs/issue19176.pdf new file mode 100644 index 0000000000000000000000000000000000000000..7bf465aeed5bf6979da70a183b93e1d6f4beecdd GIT binary patch literal 466 zcmZ8eyH3L}6y5z5XURwtCnQj*%0QtDAgVy8s)HdnA*jU2cBR7S@FRQ{8{#@m8iY5W z>+`w}mY0i@coK==>-+OZNJP+&FJd-BxKuS+#EcXOAKu>x;aoYj)iv^5P+R(kemoH7 zde=Hggx5`Ju}0ESHv{>gH&Xq0pdRG?3-4=)b$a81tlpU?PQsb;9N{gMjk?f#tRogU zpQMnIJyw>?s%;$3V$P{s#~K!=U4+ro-v`edYHRllnff}`8B(v@Um|14DGZ_VCHp~N zcW