Skip to content

Commit

Permalink
Allow applying 'underline' and 'strike' text styling together on a te…
Browse files Browse the repository at this point in the history
…xt (#1253)

Co-authored-by: Subhi Al Hasan <subhi.al.hasan@freiheit.com>
  • Loading branch information
jodevsa and Subhi Al Hasan authored May 28, 2021
1 parent c9431d6 commit 6338314
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 19 additions & 6 deletions lib/mixins/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 || []));
Expand All @@ -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();
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions tests/visual/text.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ describe('text', function() {
doc.text('Strike', 100, 130, {
strike: true
});
doc.text('Strike', 100, 160, {
underline:true,
strike: true
});
});
});

Expand Down

0 comments on commit 6338314

Please sign in to comment.