Reset sameLineText dependencies data on setTextMatrix

The position of the text rendered by `showText` is affected
incrementally by the preceding `showText` operations "on the same line".
For this reason, we keep track of all of them (with their dependencies)
in `sameLineText`.

`sameLineText` can be reset whenever we explicitly position the text
somewhere else. We were previously only doing it for `moveText`, and
this patch updates the code to also do it on `setTextMatrix` (which
resets `this.current.x/y` in `CanvasGraphics` to 0).

The complexity of subsequent `sameLineText` operations dependency
tracking grows quadratically with the number of operations on the same
line, so this patch fixes the performance problem when there are whole
pages of text that only use `setTextMatrix` and not `moveText`.
This commit is contained in:
Nicolò Ribaudo 2025-10-14 16:57:38 +02:00
parent 3eca60735b
commit d79651e797
No known key found for this signature in database
GPG Key ID: AAFDA9101C58F338

View File

@ -1843,7 +1843,9 @@ class CanvasGraphics {
}
setTextMatrix(opIdx, matrix) {
this.dependencyTracker?.recordSimpleData("textMatrix", opIdx);
this.dependencyTracker
?.resetIncrementalData("sameLineText")
.recordSimpleData("textMatrix", opIdx);
const { current } = this;
current.textMatrix = matrix;
current.textMatrixScale = Math.hypot(matrix[0], matrix[1]);