@@ -15,12 +15,22 @@ class SVGRenderer{
1515 var currentX = this . options . marginLeft ;
1616
1717 this . prepareSVG ( ) ;
18+
19+ // Create Background IF not (SVG default) `transparent`
20+ if ( ! this . options . background . match ( / t r a n s p a r e n t | # [ a - f \d ] { 3 } 0 | # [ a - f \d ] { 6 } 0 { 2 } / 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+ // Set color IF not (SVG default) `black`
31+ if ( ! encodingOptions . lineColor . match ( / b l a c k | # 0 { 3 } f ? | # 0 { 6 } (?: f { 2 } ) ? / i) ) {
32+ group . setAttribute ( "fill" , encodingOptions . lineColor ) ;
33+ }
2434
2535 this . drawSvgBarcode ( group , encodingOptions , encoding ) ;
2636 this . drawSVGText ( group , encodingOptions , encoding ) ;
@@ -31,20 +41,14 @@ class SVGRenderer{
3141
3242 prepareSVG ( ) {
3343 // Clear the SVG
34- while ( this . svg . firstChild ) {
35- this . svg . removeChild ( this . svg . firstChild ) ;
36- }
44+ this . svg . replaceChildren ( ) ;
3745
3846 calculateEncodingAttributes ( this . encodings , this . options ) ;
3947 var totalWidth = getTotalWidthOfEncodings ( this . encodings ) ;
4048 var maxHeight = getMaximumHeightOfEncodings ( this . encodings ) ;
4149
4250 var width = totalWidth + this . options . marginLeft + this . options . marginRight ;
4351 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- }
4852 }
4953
5054 drawSvgBarcode ( parent , options , encoding ) {
0 commit comments