diff --git a/HOTFIX_README.md b/HOTFIX_README.md index 9f9f3a7b9..deb5c6cae 100644 --- a/HOTFIX_README.md +++ b/HOTFIX_README.md @@ -12,31 +12,30 @@ where the pdf.hotfix field is the name of the hotfix. var pdf new jsPDF(...); pdf.hotfix.fill_close = true; -#Active Hotfixes +# Active Hotfixes +There are currently no active hotfixes. + +#Accepted Hotfixes +## scale_text -##fill_close ###Applies To context2d plugin ### Affects -Filling paths +Drawing and Filling Text when a scale transformation is active. ### Description -In certain cases, closing a fill would result in a path resolving to an incorrect point. -The was most likely fixed when we refactored matrix logic. Enabling this hotfix will ignore a most-likely unneeded workaround. +jsPDF currently has no way to draw scaled text. +This hotfix scales the current font size by the x-axis scale factor. - -##scale_text - -###Applies To +## fill_close +### Applies To context2d plugin ### Affects -Drawing and Filling Text when a scale transformation is active. +Filling paths ### Description -jsPDF currently has no way to draw scaled text. -This hotfix scales the current font size by the x-axis scale factor. +In certain cases, closing a fill would result in a path resolving to an incorrect point. +The was most likely fixed when we refactored matrix logic. Enabling this hotfix will ignore a most-likely unneeded workaround. -#Accepted Hotfixes -There a currently no accepted hotfixes. \ No newline at end of file diff --git a/plugins/context2d.js b/plugins/context2d.js index 918626e00..cf8549e5a 100644 --- a/plugins/context2d.js +++ b/plugins/context2d.js @@ -299,14 +299,14 @@ this.path = origPath; } - var scale; - if (this.pdf.hotfix && this.pdf.hotfix.scale_text) { - // We only use X axis as scale hint + // We only use X axis as scale hint + var scale = 1; + try { scale = this._matrix_decompose(this._getTransform()).scale[0]; + } catch (e) { + console.warn(e); } - else { - scale = 1; - } + // In some cases the transform was very small (5.715760606202283e-17). Most likely a canvg rounding error. if (scale < .01) { this.pdf.text(text, x, this._getBaseline(y), null, degs); @@ -354,14 +354,15 @@ this.path = origPath; } - var scale; - if (this.pdf.hotfix && this.pdf.hotfix.scale_text) { - // We only use the X axis as scale hint + + var scale = 1; + // We only use the X axis as scale hint + try { scale = this._matrix_decompose(this._getTransform()).scale[0]; + } catch (e) { + console.warn(e); } - else { - scale = 1; - } + if (scale === 1) { this.pdf.text(text, x, this._getBaseline(y), { stroke: true