Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Text margins and bgColor #584

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/text.coffee.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,15 @@ below.
* `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
* `paragraphGap` - the amount of space between each paragraph of text
* `marginTop` - the amount of space before the text
* `marginBottom` - the amount of space after the text
* `lineGap` - the amount of space between each line of text
* `wordSpacing` - the amount of space between each word in the text
* `characterSpacing` - the amount of space between each character in the text
* `fill` - whether to fill the text (`true` by default)
* `stroke` - whether to stroke the text
* `link` - a URL to link this text to (shortcut to create an annotation)
* `bgColor` - a hex color to set the background of the text
* `underline` - whether to underline the text
* `strike` - whether to strike out the text
* `continued` - whether the text segment will be followed immediately by another segment. Useful for changing styling in the middle of a paragraph.
Expand Down
3 changes: 2 additions & 1 deletion lib/line_wrapper.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class LineWrapper extends EventEmitter
# we're continuing where we left off, indent that much
# otherwise use the user specified indent option
indent = @continuedX or @indent
@document.y += options.marginTop || 0;
@document.x += indent
@lineWidth -= indent

Expand All @@ -47,7 +48,7 @@ class LineWrapper extends EventEmitter
@lastLine = true

@once 'line', =>
@document.y += options.paragraphGap or 0
@document.y += options.paragraphGap or options.marginTop or 0
options.align = align
@lastLine = false

Expand Down
7 changes: 7 additions & 0 deletions lib/mixins/text.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,13 @@ module.exports =

# calculate the actual rendered width of the string after word and character spacing
renderedWidth = options.textWidth + (wordSpacing * (options.wordCount - 1)) + (characterSpacing * (text.length - 1))
# create bgColor annotations if the bgColor option is given
if options.bgColor
textWidth = @widthOfString(text.replace(/\s+$/, ''), options);
@save();
@rect(@x, @y, textWidth, @currentLineHeight());
@fill(options.bgColor)
@restore();

# create link annotations if the link option is given
if options.link
Expand Down