From 87459726ad2dc41506929e83fe4158ad7783416e Mon Sep 17 00:00:00 2001 From: Dennis Laupman Date: Sat, 19 Nov 2016 08:14:48 +0100 Subject: [PATCH 1/4] Text margins Added margin before and after text block option --- docs/text.coffee.md | 2 ++ lib/line_wrapper.coffee | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/text.coffee.md b/docs/text.coffee.md index dbc6886b3..75264c760 100644 --- a/docs/text.coffee.md +++ b/docs/text.coffee.md @@ -82,6 +82,8 @@ 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 +* `marginBefore` - the amount of space before the text +* `marginAfter` - 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 diff --git a/lib/line_wrapper.coffee b/lib/line_wrapper.coffee index a64aa0287..584ac5527 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.marginBefore || 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.marginAfter or 0 options.align = align @lastLine = false From cbf19851d18e05da9c0463849758b32bf1f43b29 Mon Sep 17 00:00:00 2001 From: Dennis Laupman Date: Wed, 23 Nov 2016 14:18:15 +0100 Subject: [PATCH 2/4] Added bgColor option add a hex background color for text --- docs/text.coffee.md | 1 + lib/mixins/text.coffee | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/docs/text.coffee.md b/docs/text.coffee.md index 75264c760..b0ac15f89 100644 --- a/docs/text.coffee.md +++ b/docs/text.coffee.md @@ -90,6 +90,7 @@ below. * `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/mixins/text.coffee b/lib/mixins/text.coffee index 4d83df5a5..b9ecc70a2 100644 --- a/lib/mixins/text.coffee +++ b/lib/mixins/text.coffee @@ -189,7 +189,15 @@ 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 @link x, y, renderedWidth, @currentLineHeight(), options.link From 2f35cf6222279ac5ccccb30e306a3e07412b2485 Mon Sep 17 00:00:00 2001 From: Dennis Laupman Date: Tue, 18 Jul 2017 15:20:30 +0200 Subject: [PATCH 3/4] Update text.coffee.md --- docs/text.coffee.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/text.coffee.md b/docs/text.coffee.md index 046f1707d..642bde355 100644 --- a/docs/text.coffee.md +++ b/docs/text.coffee.md @@ -83,8 +83,8 @@ 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 -* `marginBefore` - the amount of space before the text -* `marginAfter` - the amount of space after the 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 From ffca4bc937bd70e2842b71d2f9d4a07c48b666ed Mon Sep 17 00:00:00 2001 From: Dennis Laupman Date: Tue, 18 Jul 2017 15:22:14 +0200 Subject: [PATCH 4/4] Update line_wrapper.coffee --- lib/line_wrapper.coffee | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/line_wrapper.coffee b/lib/line_wrapper.coffee index 584ac5527..11075c576 100644 --- a/lib/line_wrapper.coffee +++ b/lib/line_wrapper.coffee @@ -30,7 +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.marginBefore || 0; + @document.y += options.marginTop || 0; @document.x += indent @lineWidth -= indent @@ -48,7 +48,7 @@ class LineWrapper extends EventEmitter @lastLine = true @once 'line', => - @document.y += options.paragraphGap or options.marginAfter or 0 + @document.y += options.paragraphGap or options.marginTop or 0 options.align = align @lastLine = false