Skip to content
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

Prevent adding identity transforms to the document #1493

Merged
merged 1 commit into from
Jan 23, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Add subset for PDF/UA
- Fix for line breaks in list items (#1486)
- Fix for soft hyphen not being replaced by visible hyphen if necessary (#457)
- Optimize output files by ignoring identity transforms

### [v0.14.0] - 2023-11-09

Expand Down
4 changes: 4 additions & 0 deletions lib/mixins/vector.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,10 @@ export default {

transform(m11, m12, m21, m22, dx, dy) {
// keep track of the current transformation matrix
if (m11 === 1 && m12 === 0 && m21 === 0 && m22 === 1 && dx === 0 && dy === 0) {
// Ignore identity transforms
return this;
}
const m = this._ctm;
const [m0, m1, m2, m3, m4, m5] = m;
m[0] = m0 * m11 + m2 * m12;
Expand Down
22 changes: 22 additions & 0 deletions tests/unit/vector.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,26 @@ describe('Vector Graphics', () => {
});
});
});

describe('translate', () => {
test('identity transform is ignored', () => {
const docData = logData(document);
const vectorStream = Buffer.from(`1 0 0 -1 0 792 cm\n1 0 0 1 0 0 cm\n`, 'binary');

document
.translate(0, 0);
document.end();

expect(docData).not.toContainChunk([
`5 0 obj`,
`<<
/Length 33
>>`,
`stream`,
vectorStream,
`\nendstream`,
`endobj`
]);
});
});
});
Loading