From 8841aa4f763575b2cfd76f06a087d06eadc1e1df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcus=20F=C3=B6rster?= Date: Sun, 25 Feb 2024 17:32:03 +0100 Subject: [PATCH] ignore SVG default colors --- src/renderers/svg.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) 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){