Skip to content

Commit

Permalink
Merge pull request #367 from nvdbleek/measure-text-fix-pr
Browse files Browse the repository at this point in the history
Add support for using JsBarcode in implementations that don't implement measureText
  • Loading branch information
lindell authored Apr 25, 2021
2 parents 19cdeea + 6189182 commit b86e391
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/renderers/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,14 @@ function messureText(string, options, context){
ctx.font = options.fontOptions + " " + options.fontSize + "px " + options.font;

// Calculate the width of the encoding
var size = ctx.measureText(string).width;

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 = measureTextResult.width;
return size;
}

Expand Down

0 comments on commit b86e391

Please sign in to comment.