mirror of
https://github.com/foliojs/pdfkit.git
synced 2025-12-08 20:15:54 +00:00
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:
parent
c9431d6c9f
commit
6338314daf
@ -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
|
||||
|
||||
@ -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 |
@ -30,6 +30,10 @@ describe('text', function() {
|
||||
doc.text('Strike', 100, 130, {
|
||||
strike: true
|
||||
});
|
||||
doc.text('Strike', 100, 160, {
|
||||
underline:true,
|
||||
strike: true
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user