diff --git a/docs/text.coffee.md b/docs/text.coffee.md index f9cecd755..642bde355 100644 --- a/docs/text.coffee.md +++ b/docs/text.coffee.md @@ -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. diff --git a/lib/line_wrapper.coffee b/lib/line_wrapper.coffee index a64aa0287..11075c576 100644 --- a/lib/line_wrapper.coffee +++ b/lib/line_wrapper.coffee @@ -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 @@ -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 diff --git a/lib/mixins/text.coffee b/lib/mixins/text.coffee index a371ac6f0..7cf8fd01a 100644 --- a/lib/mixins/text.coffee +++ b/lib/mixins/text.coffee @@ -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