@@ -171,17 +171,27 @@ import { jsPDF } from "../jspdf.js";
171171 } ;
172172
173173 /**
174+ * Gets height and width of text
174175 * @name getTextDimensions
175176 * @function
176177 * @param {string } txt
177- * @returns {Object } dimensions
178+ * @param {object } [options]
179+ * @param {string } [options.font] Font name or family. Example: "times"
180+ * @param {number } [options.fontSize] Font size in points
181+ * @param {number } [options.lineHeightFactor=1.15] The lineheight of each line
182+ * @param {number } [options.maxWidth=0] Split the text by given width, 0 = no split
183+ * @param {number } [options.scaleFactor] Defaults to value determined by unit declared at inception of PDF document
184+ * @returns {object } `{ w: ${width}, h: ${height} }` (in units declared at inception of PDF document)
178185 */
179186 jsPDFAPI . getTextDimensions = function ( text , options ) {
180187 _initialize . call ( this ) ;
181188 options = options || { } ;
182189 var fontSize = options . fontSize || this . getFontSize ( ) ;
183190 var font = options . font || this . getFont ( ) ;
184191 var scaleFactor = options . scaleFactor || this . internal . scaleFactor ;
192+ var lineHeightFactor =
193+ options . lineHeightFactor || this . internal . getLineHeightFactor ( ) ;
194+ const maxWidth = options . maxWidth || 0 ;
185195 var width = 0 ;
186196 var amountOfLines = 0 ;
187197 var height = 0 ;
@@ -198,7 +208,6 @@ import { jsPDF } from "../jspdf.js";
198208 }
199209 }
200210
201- const maxWidth = options . maxWidth ;
202211 if ( maxWidth > 0 ) {
203212 if ( typeof text === "string" ) {
204213 text = this . splitTextToSize ( text , maxWidth ) ;
@@ -225,8 +234,8 @@ import { jsPDF } from "../jspdf.js";
225234
226235 width = width / scaleFactor ;
227236 height = Math . max (
228- ( amountOfLines * fontSize * this . getLineHeightFactor ( ) -
229- fontSize * ( this . getLineHeightFactor ( ) - 1 ) ) /
237+ ( amountOfLines * fontSize * lineHeightFactor -
238+ fontSize * ( lineHeightFactor - 1 ) ) /
230239 scaleFactor ,
231240 0
232241 ) ;
0 commit comments