Use the Util.getAxialAlignedBoundingBox helper function more

There's a couple of spots in the code-base that effectively re-implement this helper function, which seems like unnecessary repetition.
This commit is contained in:
Jonas Jenwald 2023-05-31 09:32:19 +02:00
parent 071e6bc7e7
commit d3c0928121
3 changed files with 14 additions and 27 deletions

View File

@ -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 {

View File

@ -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);

View File

@ -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]),