diff --git a/bin/renderers/shared.js b/bin/renderers/shared.js index 3e26c4f3..ce77c18f 100644 --- a/bin/renderers/shared.js +++ b/bin/renderers/shared.js @@ -76,13 +76,20 @@ function messureText(string, options, context) { } else if (typeof document !== "undefined") { ctx = document.createElement("canvas").getContext("2d"); } else { - // If the text cannot be messured we will return 0. + // If the text cannot be measured we will return 0. // This will make some barcode with big text render incorrectly return 0; } ctx.font = options.fontOptions + " " + options.fontSize + "px " + options.font; // Calculate the width of the encoding + var measureTextResult = ctx.measureText(string); + if (!measureTextResult) { + // Some implementations don't implement measureText and return undefined. + // If the text cannot be measured we will return 0. + // This will make some barcode with big text render incorrectly + return 0; + } var size = ctx.measureText(string).width; return size;