From 28c01cfe65cd87796fb061fe3ede7c6f59d0e1f6 Mon Sep 17 00:00:00 2001 From: Bogdan Chadkin Date: Sat, 6 Mar 2021 13:39:31 +0300 Subject: [PATCH] Preverve viewBox in nested --- plugins/removeViewBox.js | 37 ++++++++++++++++--------------- test/plugins/removeViewBox.05.svg | 29 ++++++++++++++++++++++++ test/regression.js | 4 ++-- 3 files changed, 50 insertions(+), 20 deletions(-) create mode 100644 test/plugins/removeViewBox.05.svg diff --git a/plugins/removeViewBox.js b/plugins/removeViewBox.js index 052642f4a..c062617a9 100644 --- a/plugins/removeViewBox.js +++ b/plugins/removeViewBox.js @@ -23,26 +23,27 @@ var viewBoxElems = ['svg', 'pattern', 'symbol']; * * @author Kir Belevich */ -exports.fn = function(item) { +exports.fn = function (item) { + if ( + item.isElem(viewBoxElems) && + item.hasAttr('viewBox') && + item.hasAttr('width') && + item.hasAttr('height') + ) { + // TODO remove width/height for such case instead + if (item.isElem('svg') && item.closestElem('svg')) { + return; + } + + var nums = item.attr('viewBox').value.split(/[ ,]+/g); if ( - item.isElem(viewBoxElems) && - item.hasAttr('viewBox') && - item.hasAttr('width') && - item.hasAttr('height') + nums[0] === '0' && + nums[1] === '0' && + item.attr('width').value.replace(/px$/, '') === nums[2] && // could use parseFloat too + item.attr('height').value.replace(/px$/, '') === nums[3] ) { - - var nums = item.attr('viewBox').value.split(/[ ,]+/g); - - if ( - nums[0] === '0' && - nums[1] === '0' && - item.attr('width').value.replace(/px$/, '') === nums[2] && // could use parseFloat too - item.attr('height').value.replace(/px$/, '') === nums[3] - ) { - item.removeAttr('viewBox'); - } - + item.removeAttr('viewBox'); } - + } }; diff --git a/test/plugins/removeViewBox.05.svg b/test/plugins/removeViewBox.05.svg new file mode 100644 index 000000000..798f5a3ab --- /dev/null +++ b/test/plugins/removeViewBox.05.svg @@ -0,0 +1,29 @@ +ViewBox in nested should be preserved to not break scale + +=== + + + + + + + + + + + + + +@@@ + + + + + + + + + + + + diff --git a/test/regression.js b/test/regression.js index 61ea0f29f..34e3de6cc 100644 --- a/test/regression.js +++ b/test/regression.js @@ -115,8 +115,8 @@ const runTests = async ({ svgFiles }) => { name === 'styling-css-01-b' || name === 'styling-css-03-b' || name === 'styling-css-04-f' || - // mismatched draft cases - name === 'struct-use-07-b' + // strange artifact breaks inconsistently breaks regression tests + name === 'filters-conv-05-f' ) { console.info(`${name} is skipped`); skipped += 1;