Allow applying 'underline' and 'strike' text styling together on a text (#1253)

Co-authored-by: Subhi Al Hasan <subhi.al.hasan@freiheit.com>
This commit is contained in:
Subhi Al Hasan 2021-05-28 19:51:12 +03:00 committed by GitHub
parent c9431d6c9f
commit 6338314daf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 6 deletions

View File

@ -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

View File

@ -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();

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 16 KiB

View File

@ -30,6 +30,10 @@ describe('text', function() {
doc.text('Strike', 100, 130, {
strike: true
});
doc.text('Strike', 100, 160, {
underline:true,
strike: true
});
});
});