diff --git a/src/display/canvas.js b/src/display/canvas.js index 8bf1a2de1..ba93deefc 100644 --- a/src/display/canvas.js +++ b/src/display/canvas.js @@ -2439,19 +2439,11 @@ class CanvasGraphics { const inv = getCurrentTransformInverse(ctx); if (inv) { - const canvas = ctx.canvas; - const width = canvas.width; - const height = canvas.height; - - const bl = Util.applyTransform([0, 0], inv); - const br = Util.applyTransform([0, height], inv); - const ul = Util.applyTransform([width, 0], inv); - const ur = Util.applyTransform([width, height], inv); - - const x0 = Math.min(bl[0], br[0], ul[0], ur[0]); - const y0 = Math.min(bl[1], br[1], ul[1], ur[1]); - const x1 = Math.max(bl[0], br[0], ul[0], ur[0]); - const y1 = Math.max(bl[1], br[1], ul[1], ur[1]); + const { width, height } = ctx.canvas; + const [x0, y0, x1, y1] = Util.getAxialAlignedBoundingBox( + [0, 0, width, height], + inv + ); this.ctx.fillRect(x0, y0, x1 - x0, y1 - y0); } else { diff --git a/src/display/svg.js b/src/display/svg.js index b61855676..e62dd5cb6 100644 --- a/src/display/svg.js +++ b/src/display/svg.js @@ -1103,17 +1103,12 @@ if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) { } shadingFill(args) { - const width = this.viewport.width; - const height = this.viewport.height; + const { width, height } = this.viewport; const inv = Util.inverseTransform(this.transformMatrix); - const bl = Util.applyTransform([0, 0], inv); - const br = Util.applyTransform([0, height], inv); - const ul = Util.applyTransform([width, 0], inv); - const ur = Util.applyTransform([width, height], inv); - const x0 = Math.min(bl[0], br[0], ul[0], ur[0]); - const y0 = Math.min(bl[1], br[1], ul[1], ur[1]); - const x1 = Math.max(bl[0], br[0], ul[0], ur[0]); - const y1 = Math.max(bl[1], br[1], ul[1], ur[1]); + const [x0, y0, x1, y1] = Util.getAxialAlignedBoundingBox( + [0, 0, width, height], + inv + ); const rect = this.svgFactory.createElement("svg:rect"); rect.setAttributeNS(null, "x", x0); diff --git a/src/shared/util.js b/src/shared/util.js index b6cafbdca..f4ae48232 100644 --- a/src/shared/util.js +++ b/src/shared/util.js @@ -730,10 +730,10 @@ class Util { // Applies the transform to the rectangle and finds the minimum axially // aligned bounding box. static getAxialAlignedBoundingBox(r, m) { - const p1 = Util.applyTransform(r, m); - const p2 = Util.applyTransform(r.slice(2, 4), m); - const p3 = Util.applyTransform([r[0], r[3]], m); - const p4 = Util.applyTransform([r[2], r[1]], m); + const p1 = this.applyTransform(r, m); + const p2 = this.applyTransform(r.slice(2, 4), m); + const p3 = this.applyTransform([r[0], r[3]], m); + const p4 = this.applyTransform([r[2], r[1]], m); return [ Math.min(p1[0], p2[0], p3[0], p4[0]), Math.min(p1[1], p2[1], p3[1], p4[1]),