Skip to content

Commit 4c63905

Browse files
committed
Avoid to create an array when setting the text matrix
1 parent 9217d25 commit 4c63905

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

src/core/evaluator.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2237,6 +2237,9 @@ class PartialEvaluator {
22372237
}
22382238
continue;
22392239
}
2240+
case OPS.setTextMatrix:
2241+
operatorList.addOp(fn, [new Float32Array(args)]);
2242+
continue;
22402243
case OPS.markPoint:
22412244
case OPS.markPointProps:
22422245
case OPS.beginCompat:

src/core/operator_list.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,9 @@ class OperatorList {
787787
transfers.push(bbox.buffer);
788788
}
789789
break;
790+
case OPS.setTextMatrix:
791+
transfers.push(argsArray[i][0].buffer);
792+
break;
790793
}
791794
}
792795
return transfers;

src/display/canvas.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import {
1717
DrawOPS,
1818
FeatureTest,
1919
FONT_IDENTITY_MATRIX,
20-
IDENTITY_MATRIX,
2120
ImageKind,
2221
info,
2322
OPS,
@@ -311,7 +310,7 @@ class CanvasExtraState {
311310

312311
fontSizeScale = 1;
313312

314-
textMatrix = IDENTITY_MATRIX;
313+
textMatrix = null;
315314

316315
textMatrixScale = 1;
317316

@@ -1611,7 +1610,7 @@ class CanvasGraphics {
16111610

16121611
// Text
16131612
beginText() {
1614-
this.current.textMatrix = IDENTITY_MATRIX;
1613+
this.current.textMatrix = null;
16151614
this.current.textMatrixScale = 1;
16161615
this.current.x = this.current.lineX = 0;
16171616
this.current.y = this.current.lineY = 0;
@@ -1732,12 +1731,13 @@ class CanvasGraphics {
17321731
this.moveText(x, y);
17331732
}
17341733

1735-
setTextMatrix(a, b, c, d, e, f) {
1736-
this.current.textMatrix = [a, b, c, d, e, f];
1737-
this.current.textMatrixScale = Math.hypot(a, b);
1734+
setTextMatrix(matrix) {
1735+
const { current } = this;
1736+
current.textMatrix = matrix;
1737+
current.textMatrixScale = Math.hypot(matrix[0], matrix[1]);
17381738

1739-
this.current.x = this.current.lineX = 0;
1740-
this.current.y = this.current.lineY = 0;
1739+
current.x = current.lineX = 0;
1740+
current.y = current.lineY = 0;
17411741
}
17421742

17431743
nextLine() {
@@ -1904,7 +1904,9 @@ class CanvasGraphics {
19041904
!current.patternFill;
19051905

19061906
ctx.save();
1907-
ctx.transform(...current.textMatrix);
1907+
if (current.textMatrix) {
1908+
ctx.transform(...current.textMatrix);
1909+
}
19081910
ctx.translate(current.x, current.y + current.textRise);
19091911

19101912
if (fontDirection > 0) {
@@ -2099,7 +2101,9 @@ class CanvasGraphics {
20992101
this._cachedGetSinglePixelWidth = null;
21002102

21012103
ctx.save();
2102-
ctx.transform(...current.textMatrix);
2104+
if (current.textMatrix) {
2105+
ctx.transform(...current.textMatrix);
2106+
}
21032107
ctx.translate(current.x, current.y + current.textRise);
21042108

21052109
ctx.scale(textHScale, fontDirection);

0 commit comments

Comments
 (0)