Skip to content

Commit d79651e

Browse files
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`.
1 parent 3eca607 commit d79651e

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

src/display/canvas.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1843,7 +1843,9 @@ class CanvasGraphics {
18431843
}
18441844

18451845
setTextMatrix(opIdx, matrix) {
1846-
this.dependencyTracker?.recordSimpleData("textMatrix", opIdx);
1846+
this.dependencyTracker
1847+
?.resetIncrementalData("sameLineText")
1848+
.recordSimpleData("textMatrix", opIdx);
18471849
const { current } = this;
18481850
current.textMatrix = matrix;
18491851
current.textMatrixScale = Math.hypot(matrix[0], matrix[1]);

0 commit comments

Comments
 (0)