From c378d199b5b4d8f58a37e1a90c0a7c3974ddd1d2 Mon Sep 17 00:00:00 2001 From: Eric Shull Date: Wed, 6 Feb 2019 19:28:23 -0500 Subject: [PATCH] Fix background style being overridden. --- index.html | 5 +++++ index.js | 1 + package.json | 2 +- src/saveSvgAsPng.js | 3 +-- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/index.html b/index.html index 4c51338..ce2b42f 100644 --- a/index.html +++ b/index.html @@ -310,6 +310,11 @@

Preview

+
  • + + +
  • +
  • Custom Fonts diff --git a/index.js b/index.js index 1bb311c..67902b8 100644 --- a/index.js +++ b/index.js @@ -82,6 +82,7 @@ inlineTest('When setting xmlns on foreign object children', $('#xmlns-override') inlineTest('When using HTML entites', $('#entities')); inlineTest('Transformed text', $('#transformed-text')); inlineTest('With marker-end', $('#marker-end')); +inlineTest('SVG style attribute', $('#style-background')); inlineTest('With custom fonts', $('#custom-font')); const $sandbox = $('#sandbox'); diff --git a/package.json b/package.json index 591a2ac..a7ed945 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "save-svg-as-png", - "version": "1.4.6", + "version": "1.4.8", "description": "Convert a browser SVG to PNG or dataUri", "main": "lib/saveSvgAsPng.js", "scripts": { diff --git a/src/saveSvgAsPng.js b/src/saveSvgAsPng.js index d0b061e..620af07 100644 --- a/src/saveSvgAsPng.js +++ b/src/saveSvgAsPng.js @@ -222,8 +222,7 @@ return inlineImages(el).then(() => { let clone = el.cloneNode(true); - const {backgroundColor = 'transparent'} = options || {}; - clone.style.backgroundColor = backgroundColor; + clone.style.backgroundColor = (options || {}).backgroundColor || el.style.backgroundColor; const {width, height} = getDimensions(el, clone, w, h); if (el.tagName !== 'svg') {