Skip to content

Commit 1e7d313

Browse files
committed
ignore SVG default colors
1 parent aef10b2 commit 1e7d313

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/renderers/svg.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,21 @@ class SVGRenderer{
1515
var currentX = this.options.marginLeft;
1616

1717
this.prepareSVG();
18+
19+
// Create Background
20+
if(!this.options.background.match(/transparent|#[a-f\d]{3}(?:[a-f\d]{3})?0/i)){
21+
this.drawRect(0, 0, "100%", "100%", this.svg).setAttribute("fill", this.options.background);
22+
}
23+
1824
for(let i = 0; i < this.encodings.length; i++){
1925
var encoding = this.encodings[i];
2026
var encodingOptions = merge(this.options, encoding.options);
2127

2228
var group = this.createGroup(currentX, encodingOptions.marginTop, this.svg);
23-
group.setAttribute("fill", encodingOptions.lineColor);
29+
30+
if(!encodingOptions.lineColor.match(/black|#000(?:000)?f?/i)){
31+
group.setAttribute("fill", encodingOptions.lineColor);
32+
}
2433

2534
this.drawSvgBarcode(group, encodingOptions, encoding);
2635
this.drawSVGText(group, encodingOptions, encoding);
@@ -41,10 +50,6 @@ class SVGRenderer{
4150

4251
var width = totalWidth + this.options.marginLeft + this.options.marginRight;
4352
this.setSvgAttributes(width, maxHeight);
44-
45-
if(this.options.background){
46-
this.drawRect(0, 0, "100%", "100%", this.svg).setAttribute("fill", this.options.background);
47-
}
4853
}
4954

5055
drawSvgBarcode(parent, options, encoding){

0 commit comments

Comments
 (0)