Skip to content

Commit

Permalink
Hiding invalid barcode output and continuing the SVG rendering process.
Browse files Browse the repository at this point in the history
Maybe I should be adding error messages at the barcode location instead?
  • Loading branch information
Jozo132 committed Dec 17, 2024
1 parent 5783302 commit 51f6665
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions zpl2svg.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
svg.push(`<svg ${custom_class ? `class="${custom_class}"` : ''} width="${width}" height="${height}" xmlns="http://www.w3.org/2000/svg" style="dominant-baseline: hanging;">`)
svg.push(`<rect x="0" y="0" width="100%" height="100%" fill="white"/>`)
svg.push(`<g transform="scale(${scale}) translate(${x_offset}, ${y_offset})">`)


// Track inversion regions
let inversionMasks = []
Expand Down Expand Up @@ -211,7 +211,7 @@
rotate: state.barcode.orientation === 'B' ? 'L' : state.barcode.orientation,
}
if (alttext && state.barcode.print_human_readable) barcode_options.alttext = alttext
if (bcid === 'azteccode') {
if (bcid === 'azteccode') { // @ts-ignore
delete barcode_options.height
barcode_options.scale *= state.barcode.magnification / 4
barcode_options.format = 'full'
Expand All @@ -229,7 +229,15 @@
}

// @ts-ignore
const barcode = bwipjs.toSVG(barcode_options)
let barcode = ''
try {
barcode = bwipjs.toSVG(barcode_options)
} catch (e) {
console.log(`Failed to generate barcode: ${state.barcode.type} with value: ${value}`)
console.log(e)
state.barcode.type = '' // Reset barcode type to prevent drawing barcode on next text field
break
}

// <svg viewBox="0 0 WIDTH HEIGHT" ...
// Extract the width and height from the viewBox attribute
Expand Down

0 comments on commit 51f6665

Please sign in to comment.