Merge pull request #987 from blikblum/master

Fix infinite loop when text is positioned after page right margin. Based on #986
This commit is contained in:
Luiz Américo 2019-06-11 21:37:24 -03:00 committed by GitHub
commit deeffd559c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 81 additions and 0 deletions

View File

@ -1,6 +1,7 @@
## pdfkit changelog
### Unreleased
- Fix infinite loop when text is positioned after page right margin
### [v0.10.0] - 2019-06-06

View File

@ -220,6 +220,7 @@ export default {
if (result.width == null) {
result.width = this.page.width - this.x - this.page.margins.right;
}
result.width = Math.max(result.width, 0);
}
if (!result.columns) {

79
tests/unit/text.spec.js Normal file
View File

@ -0,0 +1,79 @@
import PDFDocument from '../../lib/document';
import { logData } from './helpers';
describe('Text', () => {
let document;
beforeEach(() => {
document = new PDFDocument({
info: { CreationDate: new Date(Date.UTC(2018, 1, 1)) },
compress: false
});
});
describe('text', () => {
test('with simple content', () => {
const docData = logData(document);
const textStream = new Buffer(
`1 0 0 -1 0 792 cm
q
1 0 0 -1 0 792 cm
BT
1 0 0 1 72 711.384 Tm
/F1 12 Tf
[<73696d706c65207465> 30 <7874> 0] TJ
ET
Q
`,
'binary'
);
document.text('simple text');
document.end();
expect(docData).toContainChunk([
`5 0 obj`,
`<<
/Length 116
>>`,
`stream`,
textStream,
`\nendstream`,
`endobj`
]);
});
test('with content ending after page right margin', () => {
const docData = logData(document);
const textStream = new Buffer(
`1 0 0 -1 0 792 cm
q
1 0 0 -1 0 792 cm
BT
1 0 0 1 600 763.384 Tm
/F1 12 Tf
[<73696d706c65207465> 30 <7874> 0] TJ
ET
Q
`,
'binary'
);
document.text('simple text', 600, 20);
document.end();
expect(docData).toContainChunk([
`5 0 obj`,
`<<
/Length 117
>>`,
`stream`,
textStream,
`\nendstream`,
`endobj`
]);
});
});
});