mirror of
https://github.com/foliojs/pdfkit.git
synced 2025-12-08 20:15:54 +00:00
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:
commit
deeffd559c
@ -1,6 +1,7 @@
|
||||
## pdfkit changelog
|
||||
|
||||
### Unreleased
|
||||
- Fix infinite loop when text is positioned after page right margin
|
||||
|
||||
### [v0.10.0] - 2019-06-06
|
||||
|
||||
|
||||
@ -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
79
tests/unit/text.spec.js
Normal 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`
|
||||
]);
|
||||
});
|
||||
});
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user