1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-26 10:08:06 +02:00

Simplify min/max computations in constructPath (bug 1135277)

- most of the time the current transform is a scaling one (modulo translation),
  hence it's possible to avoid to apply the transform on each bbox and then apply
  it a posteriori;
- compute the bbox when it's possible in the worker.
This commit is contained in:
Calixte Denizet 2022-04-17 15:35:07 +02:00
parent 379125c37f
commit 4b7691baf6
3 changed files with 130 additions and 13 deletions

View file

@ -1352,6 +1352,7 @@ class PartialEvaluator {
if (!args) {
args = [];
}
let minMax;
if (
lastIndex < 0 ||
operatorList.fnArray[lastIndex] !== OPS.constructPath
@ -1368,7 +1369,8 @@ class PartialEvaluator {
operatorList.addOp(OPS.save, null);
}
operatorList.addOp(OPS.constructPath, [[fn], args]);
minMax = [Infinity, -Infinity, Infinity, -Infinity];
operatorList.addOp(OPS.constructPath, [[fn], args, minMax]);
if (parsingText) {
operatorList.addOp(OPS.restore, null);
@ -1377,6 +1379,28 @@ class PartialEvaluator {
const opArgs = operatorList.argsArray[lastIndex];
opArgs[0].push(fn);
Array.prototype.push.apply(opArgs[1], args);
minMax = opArgs[2];
}
// Compute min/max in the worker instead of the main thread.
// If the current matrix (when drawing) is a scaling one
// then min/max can be easily computed in using those values.
// Only rectangle, lineTo and moveTo are handled here since
// Bezier stuff requires to have the starting point.
switch (fn) {
case OPS.rectangle:
minMax[0] = Math.min(minMax[0], args[0], args[0] + args[2]);
minMax[1] = Math.max(minMax[1], args[0], args[0] + args[2]);
minMax[2] = Math.min(minMax[2], args[1], args[1] + args[3]);
minMax[3] = Math.max(minMax[3], args[1], args[1] + args[3]);
break;
case OPS.moveTo:
case OPS.lineTo:
minMax[0] = Math.min(minMax[0], args[0]);
minMax[1] = Math.max(minMax[1], args[0]);
minMax[2] = Math.min(minMax[2], args[1]);
minMax[3] = Math.max(minMax[3], args[1]);
break;
}
}