diff --git a/CHANGELOG.md b/CHANGELOG.md index ca635b0..6fa63f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ### Unreleased +- Allow applying 'underline' and 'strike' text styling together on a text + ### [v0.12.0] - 2021-04-04 - Add support for Embedded Files and File Attachment Annotations diff --git a/lib/mixins/text.js b/lib/mixins/text.js index 94e711c..a1c7f42 100644 --- a/lib/mixins/text.js +++ b/lib/mixins/text.js @@ -371,8 +371,8 @@ export default { this.addNamedDestination(options.destination, 'XYZ', x, y, null); } - // create underline or strikethrough line - if (options.underline || options.strike) { + // create underline + if (options.underline) { this.save(); if (!options.stroke) { this.strokeColor(...(this._fillColor || [])); @@ -382,12 +382,25 @@ export default { this._fontSize < 10 ? 0.5 : Math.floor(this._fontSize / 10); this.lineWidth(lineWidth); - const d = options.underline ? 1 : 2; - let lineY = y + this.currentLineHeight() / d; - if (options.underline) { - lineY -= lineWidth; + let lineY = (y + this.currentLineHeight()) - lineWidth + this.moveTo(x, lineY); + this.lineTo(x + renderedWidth, lineY); + this.stroke(); + this.restore(); + } + + // create strikethrough line + if (options.strike) { + this.save(); + if (!options.stroke) { + this.strokeColor(...(this._fillColor || [])); } + const lineWidth = + this._fontSize < 10 ? 0.5 : Math.floor(this._fontSize / 10); + this.lineWidth(lineWidth); + + let lineY = y + this.currentLineHeight() / 2; this.moveTo(x, lineY); this.lineTo(x + renderedWidth, lineY); this.stroke(); diff --git a/tests/visual/__snapshots__/text-spec-js-text-decoration-1-9cad8.snap.png b/tests/visual/__snapshots__/text-spec-js-text-decoration-1-9cad8.snap.png index 974f4e1..38e3835 100644 Binary files a/tests/visual/__snapshots__/text-spec-js-text-decoration-1-9cad8.snap.png and b/tests/visual/__snapshots__/text-spec-js-text-decoration-1-9cad8.snap.png differ diff --git a/tests/visual/text.spec.js b/tests/visual/text.spec.js index ce21731..ec6de8e 100644 --- a/tests/visual/text.spec.js +++ b/tests/visual/text.spec.js @@ -30,6 +30,10 @@ describe('text', function() { doc.text('Strike', 100, 130, { strike: true }); + doc.text('Strike', 100, 160, { + underline:true, + strike: true + }); }); });