diff --git a/src/renderers/svg.js b/src/renderers/svg.js index f492b43..b6e1cec 100644 --- a/src/renderers/svg.js +++ b/src/renderers/svg.js @@ -15,12 +15,21 @@ class SVGRenderer{ var currentX = this.options.marginLeft; this.prepareSVG(); + + // Create Background + if(!this.options.background.match(/transparent|#[a-f\d]{3}(?:[a-f\d]{3})?0/i)){ + this.drawRect(0, 0, "100%", "100%", this.svg).setAttribute("fill", this.options.background); + } + for(let i = 0; i < this.encodings.length; i++){ var encoding = this.encodings[i]; var encodingOptions = merge(this.options, encoding.options); var group = this.createGroup(currentX, encodingOptions.marginTop, this.svg); - group.setAttribute("fill", encodingOptions.lineColor); + + if(!encodingOptions.lineColor.match(/black|#000(?:000)?f?/i)){ + group.setAttribute("fill", encodingOptions.lineColor); + } this.drawSvgBarcode(group, encodingOptions, encoding); this.drawSVGText(group, encodingOptions, encoding); @@ -41,10 +50,6 @@ class SVGRenderer{ var width = totalWidth + this.options.marginLeft + this.options.marginRight; this.setSvgAttributes(width, maxHeight); - - if(this.options.background){ - this.drawRect(0, 0, "100%", "100%", this.svg).setAttribute("fill", this.options.background); - } } drawSvgBarcode(parent, options, encoding){