diff --git a/lib/htmlToTextObjects.js b/lib/htmlToTextObjects.js index d4c32fb..415cc70 100644 --- a/lib/htmlToTextObjects.js +++ b/lib/htmlToTextObjects.js @@ -85,6 +85,7 @@ function parseNode(node) { isBold: isBoldTag(node.tagName), isItalic: isItalicTag(node.tagName), underline: (node.tagName == 'u'), + strikeOut: (node.tagName == 'del'), attributes, styles, needsLineBreaker: needsLineBreaker(node.tagName), diff --git a/lib/text.js b/lib/text.js index 799b647..21687df 100644 --- a/lib/text.js +++ b/lib/text.js @@ -334,14 +334,25 @@ exports.text = function text(text = '', x, y, options = {}) { // console.log(textWidth, lineWidth, currentLineWidth) const underlineY = y - options.textHeight * 0.1; // TODO: fix the line with calculation - const width = currentLineWidth - ((isHTML || toWriteTextObject.text.endsWith(' ')) ? spaceWidth : 0); + // const width = currentLineWidth - ((isHTML || toWriteTextObject.text.endsWith(' ')) ? spaceWidth : 0); ctx .q() - .drawPath(x, underlineY, x + width, underlineY, options) + .drawPath(x, underlineY, x + options.lineWidth, underlineY, options) .Q(); } }; + const addStrikeOut = (x, y, ctx, options) => { + // strikethrough implementation + if (options.strikeOut) { + const strikeOutY = y + options.textHeight * 0.2; + ctx + .q() + .drawPath(x, strikeOutY, x + options.lineWidth, strikeOutY, options) + .Q(); + } + } + const addTextTraits = (ctx, options) => { ctx.Tf(options.font, options.size); ctx.Tc(options.charSpace); @@ -364,6 +375,7 @@ exports.text = function text(text = '', x, y, options = {}) { ctx.ET(); addUnderline(x, y, ctx, options); + addStrikeOut(x, y, ctx, options); }; const justifyText = (left, x, wto, textBox, ctx, options, callback) => { @@ -393,6 +405,10 @@ exports.text = function text(text = '', x, y, options = {}) { return next_x; } + if (options.underline || options.strikeOut) { + options.lineWidth = wto.lineWidth; + } + // Produce a hilite under words? if (options.hilite) { const bgColor = options.hilite.color || '#ffff00'; @@ -720,6 +736,7 @@ exports._layoutText = function _layoutText(textObjects, textBox, pathOptions) { child.isBold = (textObject.isBold) ? textObject.isBold : child.isBold; child.isItalic = (textObject.isItalic) ? textObject.isItalic : child.isItalic; child.underline = (textObject.underline) ? textObject.underline : child.underline; + child.strikeOut = (textObject.strikeOut) ? textObject.strikeOut : child.strikeOut; child.lineID = textObject.lineID; writeValue(child); @@ -968,6 +985,7 @@ function makeTextObjects(self, textObject = {}, pathOptions, textBox = {}) { color: textObject.styles.color, opacity: parseFloat(textObject.styles.opacity || pathOptions.opacity || 1), underline: textObject.underline || pathOptions.underline, + strikeOut: textObject.strikeOut || pathOptions.strikeOut, size: textObject.size, alignHorizontal: alignHorizontal, alignVertical: alignVertical,