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. <liborm85@gmail.com>
This commit is contained in:
Kevin Hendel 2024-12-27 15:52:48 +01:00 committed by GitHub
parent 133a321a56
commit 1b678c3e3d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 9 additions and 0 deletions

View File

@ -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()

View File

@ -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

View File

@ -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;