From 1b678c3e3dc383da11a45bac09e5a3f4638b8635 Mon Sep 17 00:00:00 2001 From: Kevin Hendel <36416784+kevinhend@users.noreply.github.com> Date: Fri, 27 Dec 2024 15:52:48 +0100 Subject: [PATCH] Indent after linebreak (#879) * add indentAllLines option to indent all lines of a paragraph instead of only the first one * update comments * Update CHANGELOG.md --------- Co-authored-by: Libor M. --- CHANGELOG.md | 1 + docs/text.md | 1 + lib/line_wrapper.js | 7 +++++++ 3 files changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bcb0ccb7..5983bc2b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - Update linebreak to 1.1 - Add support for spot colors - Add support to scale text horizontally +- Add an option to keep the indentation after a new line starts and allow to indent a whole paragraph/text element - Fix sets tab order to "Structure" when a document is tagged - Fix font cache collision for fonts with missing postscript name or bad TTF metadata - Fix measuring text when OpenType features are passed in to .text() diff --git a/docs/text.md b/docs/text.md index ca40f5b6..f349c86a 100644 --- a/docs/text.md +++ b/docs/text.md @@ -90,6 +90,7 @@ below. * `columns` - the number of columns to flow the text into * `columnGap` - the amount of space between each column (1/4 inch by default) * `indent` - the amount in PDF points (72 per inch) to indent each paragraph of text +* `indentAllLines` - wheter to indent all lines of a paragraph (`false` by default - indents only the first line) * `paragraphGap` - the amount of space between each paragraph of text * `lineGap` - the amount of space between each line of text * `wordSpacing` - the amount of space between each word in the text diff --git a/lib/line_wrapper.js b/lib/line_wrapper.js index cc737360..a64148c0 100644 --- a/lib/line_wrapper.js +++ b/lib/line_wrapper.js @@ -40,6 +40,13 @@ class LineWrapper extends EventEmitter { this.document.x += indent; this.lineWidth -= indent; + // if indentAllLines is set to true + // we're not resetting the indentation for this paragraph after the first line + if (options.indentAllLines) { + return; + } + + // otherwise we start the next line without indent return this.once('line', () => { this.document.x -= indent; this.lineWidth += indent;