diff --git a/CHANGELOG.md b/CHANGELOG.md index 9926fc6..e12a683 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ### Unreleased - Fix infinite loop when text is positioned after page right margin + - Allow links in continued text to be stopped by setting link to null ### [v0.10.0] - 2019-06-06 diff --git a/docs/guide.pdf b/docs/guide.pdf index dd3c0a6..13bb41c 100644 Binary files a/docs/guide.pdf and b/docs/guide.pdf differ diff --git a/docs/text.md b/docs/text.md index 134c702..ed442c5 100644 --- a/docs/text.md +++ b/docs/text.md @@ -166,6 +166,27 @@ Here is the output: ![4]() +To cancel a link in rich text set the `link` option to `null`. + + doc.fillColor('red') + .text(lorem.slice(0, 199), { + width: 465, + continued: true + }) + .fillColor('blue') + .text(lorem.slice(199, 282), { + link: 'http://www.example.com', + continued: true + }) + .fillColor('green') + .text(lorem.slice(182, 400), { + link: null + }); + +Here is the output: + +![5]() + ## Fonts The PDF format defines 14 standard fonts that can be used in PDF documents. PDFKit supports each of them out of the box. @@ -219,7 +240,7 @@ Here is an example showing how to set the font in each case. The output of this example looks like this: -![5](images/fonts.png) +![6](images/fonts.png) Another nice feature of the PDFKit font support, is the ability to register a font file under a name for use later rather than entering the path to the font diff --git a/lib/mixins/text.js b/lib/mixins/text.js index 8c449b0..43903ab 100644 --- a/lib/mixins/text.js +++ b/lib/mixins/text.js @@ -200,7 +200,7 @@ export default { for (let key in this._textOptions) { const val = this._textOptions[key]; if (key !== 'continued') { - if (result[key] == null) { + if (result[key] === undefined) { result[key] = val; } } diff --git a/tests/unit/annotations.spec.js b/tests/unit/annotations.spec.js index 25906aa..c73bf6b 100644 --- a/tests/unit/annotations.spec.js +++ b/tests/unit/annotations.spec.js @@ -32,5 +32,69 @@ describe('Annotations', () => { >>` ]); }); + + test('using url', () => { + document.addPage(); + + const docData = logData(document); + + document.text('Go to url', { link: 'http://www.example.com' }); + + expect(docData).toContainChunk([ + `11 0 obj`, + `<< +/S /URI +/URI (http://www.example.com) +>>` + ]); + }); + + test('using url on continue', () => { + document.addPage(); + + const docData = logData(document); + + document.text('Go to url', { link: 'http://www.example.com', continued: true }); + document.text('continued link'); + + expect(docData).toContainChunk([ + `11 0 obj`, + `<< +/S /URI +/URI (http://www.example.com) +>>` + ]); + + expect(docData).toContainChunk([ + `14 0 obj`, + `<< +/S /URI +/URI (http://www.example.com) +>>` + ]); + }); + + test('using url on continue', () => { + document.addPage(); + + const docData = logData(document); + + document.text('Go to url', { link: 'http://www.example.com', continued: true }); + document.text('no continued link', { link: null }); + + // console.log(docData); + expect(docData).toContainChunk([ + `11 0 obj`, + `<< +/S /URI +/URI (http://www.example.com) +>>` + ]); + + expect(docData).not.toContainChunk([ + `14 0 obj` + ]); + }); + }); });