Skip to content

Avoid to create any subarrays when optimizing 'save, transform, constructPath, restore' (bug 1961107) #19825

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions src/core/font_renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -745,12 +745,9 @@ class Commands {

add(cmd, args) {
if (args) {
const [a, b, c, d, e, f] = this.currentTransform;
const { currentTransform } = this;
for (let i = 0, ii = args.length; i < ii; i += 2) {
const x = args[i];
const y = args[i + 1];
args[i] = a * x + c * y + e;
args[i + 1] = b * x + d * y + f;
Util.applyTransform(args, currentTransform, i);
}
this.cmds.push(`${cmd}${args.join(" ")}`);
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/core/operator_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -524,11 +524,11 @@ addState(
switch (buffer[k++]) {
case DrawOPS.moveTo:
case DrawOPS.lineTo:
Util.applyTransform(buffer.subarray(k), transform);
Util.applyTransform(buffer, transform, k);
k += 2;
break;
case DrawOPS.curveTo:
Util.applyTransformToBezier(buffer.subarray(k), transform);
Util.applyTransformToBezier(buffer, transform, k);
k += 6;
break;
}
Expand Down
21 changes: 10 additions & 11 deletions src/shared/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -730,26 +730,25 @@ class Util {
}

// For 2d affine transforms
static applyTransform(p, m) {
const p0 = p[0];
const p1 = p[1];
p[0] = p0 * m[0] + p1 * m[2] + m[4];
p[1] = p0 * m[1] + p1 * m[3] + m[5];
static applyTransform(p, m, pos = 0) {
const p0 = p[pos];
const p1 = p[pos + 1];
p[pos] = p0 * m[0] + p1 * m[2] + m[4];
p[pos + 1] = p0 * m[1] + p1 * m[3] + m[5];
}

// For 2d affine transforms
static applyTransformToBezier(p, transform) {
static applyTransformToBezier(p, transform, pos = 0) {
const m0 = transform[0];
const m1 = transform[1];
const m2 = transform[2];
const m3 = transform[3];
const m4 = transform[4];
const m5 = transform[5];
for (let i = 0; i < 6; i += 2) {
const pI = p[i];
const pI1 = p[i + 1];
p[i] = pI * m0 + pI1 * m2 + m4;
p[i + 1] = pI * m1 + pI1 * m3 + m5;
const pI = p[pos + i];
const pI1 = p[pos + i + 1];
p[pos + i] = pI * m0 + pI1 * m2 + m4;
p[pos + i + 1] = pI * m1 + pI1 * m3 + m5;
}
}

Expand Down