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:
parent
071e6bc7e7
commit
d3c0928121
@ -2439,19 +2439,11 @@ class CanvasGraphics {
|
|||||||
|
|
||||||
const inv = getCurrentTransformInverse(ctx);
|
const inv = getCurrentTransformInverse(ctx);
|
||||||
if (inv) {
|
if (inv) {
|
||||||
const canvas = ctx.canvas;
|
const { width, height } = ctx.canvas;
|
||||||
const width = canvas.width;
|
const [x0, y0, x1, y1] = Util.getAxialAlignedBoundingBox(
|
||||||
const height = canvas.height;
|
[0, 0, width, height],
|
||||||
|
inv
|
||||||
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]);
|
|
||||||
|
|
||||||
this.ctx.fillRect(x0, y0, x1 - x0, y1 - y0);
|
this.ctx.fillRect(x0, y0, x1 - x0, y1 - y0);
|
||||||
} else {
|
} else {
|
||||||
|
@ -1103,17 +1103,12 @@ if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
shadingFill(args) {
|
shadingFill(args) {
|
||||||
const width = this.viewport.width;
|
const { width, height } = this.viewport;
|
||||||
const height = this.viewport.height;
|
|
||||||
const inv = Util.inverseTransform(this.transformMatrix);
|
const inv = Util.inverseTransform(this.transformMatrix);
|
||||||
const bl = Util.applyTransform([0, 0], inv);
|
const [x0, y0, x1, y1] = Util.getAxialAlignedBoundingBox(
|
||||||
const br = Util.applyTransform([0, height], inv);
|
[0, 0, width, height],
|
||||||
const ul = Util.applyTransform([width, 0], inv);
|
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 rect = this.svgFactory.createElement("svg:rect");
|
const rect = this.svgFactory.createElement("svg:rect");
|
||||||
rect.setAttributeNS(null, "x", x0);
|
rect.setAttributeNS(null, "x", x0);
|
||||||
|
@ -730,10 +730,10 @@ class Util {
|
|||||||
// Applies the transform to the rectangle and finds the minimum axially
|
// Applies the transform to the rectangle and finds the minimum axially
|
||||||
// aligned bounding box.
|
// aligned bounding box.
|
||||||
static getAxialAlignedBoundingBox(r, m) {
|
static getAxialAlignedBoundingBox(r, m) {
|
||||||
const p1 = Util.applyTransform(r, m);
|
const p1 = this.applyTransform(r, m);
|
||||||
const p2 = Util.applyTransform(r.slice(2, 4), m);
|
const p2 = this.applyTransform(r.slice(2, 4), m);
|
||||||
const p3 = Util.applyTransform([r[0], r[3]], m);
|
const p3 = this.applyTransform([r[0], r[3]], m);
|
||||||
const p4 = Util.applyTransform([r[2], r[1]], m);
|
const p4 = this.applyTransform([r[2], r[1]], m);
|
||||||
return [
|
return [
|
||||||
Math.min(p1[0], p2[0], p3[0], p4[0]),
|
Math.min(p1[0], p2[0], p3[0], p4[0]),
|
||||||
Math.min(p1[1], p2[1], p3[1], p4[1]),
|
Math.min(p1[1], p2[1], p3[1], p4[1]),
|
||||||
|
Loading…
Reference in New Issue
Block a user