Skip to content

Commit

Permalink
Indent after linebreak (#879)
Browse files Browse the repository at this point in the history
* 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. <[email protected]>
  • Loading branch information
kevinhend and liborm85 authored Dec 27, 2024
1 parent 133a321 commit 1b678c3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions docs/text.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions lib/line_wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 1b678c3

Please sign in to comment.