mirror of
https://github.com/foliojs/pdfkit.git
synced 2025-12-08 20:15:54 +00:00
Prevent adding identity transforms to the document (#1493)
This makes the resulting PDF files smaller. It's cumbersome to filter out all commands that could result in identity transforms in code that's using PDFKit, so it makes sense to have the check in the transform() function.
This commit is contained in:
parent
1f70b450a2
commit
a655194de2
@ -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
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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…
x
Reference in New Issue
Block a user