Skip to content

Commit

Permalink
ignore SVG default colors
Browse files Browse the repository at this point in the history
  • Loading branch information
xerc committed Feb 25, 2024
1 parent 0de7076 commit 8841aa4
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/renderers/svg.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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){
Expand Down

0 comments on commit 8841aa4

Please sign in to comment.