#546 feGaussianBlur element iterate from filter issue fixes

master
Agriya Dev5 2021-05-26 20:02:32 +05:30
parent 8af30cde8c
commit f1cca77962
3 changed files with 32 additions and 5 deletions

View File

@ -12,7 +12,7 @@ import * as hstry from './history.js';
import * as pathModule from './path.js';
import {
isNullish, getStrokedBBoxDefaultVisible, setHref, getElem, getHref, getVisibleElements,
findDefs, getRotationAngle, getRefElem, getBBox as utilsGetBBox, walkTreePost, assignAttributes
findDefs, getRotationAngle, getRefElem, getBBox as utilsGetBBox, walkTreePost, assignAttributes, getFeGaussianBlur
} from './utilities.js';
import {
transformPoint, matrixMultiply, transformListToTransform
@ -576,15 +576,16 @@ export const pushGroupProperty = function (g, undoable) {
} else {
gfilter = getRefElem(elem.getAttribute('filter'));
}
// const filterElem = getRefElem(gfilter);
const blurElem = getFeGaussianBlur(gfilter);
// Change this in future for different filters
const suffix = (gfilter.firstChild.tagName === 'feGaussianBlur') ? 'blur' : 'filter';
const suffix = (blurElem?.tagName === 'feGaussianBlur') ? 'blur' : 'filter';
gfilter.id = elem.id + '_' + suffix;
elementContext_.changeSelectedAttribute('filter', 'url(#' + gfilter.id + ')', [ elem ]);
// Update blur value
if (cblur) {
elementContext_.changeSelectedAttribute('stdDeviation', cblur, [ gfilter.firstChild ]);
elementContext_.changeSelectedAttribute('stdDeviation', cblur, [ blurElem ]);
elementContext_.getCanvas().setBlurOffsets(gfilter, cblur);
}
}

View File

@ -71,7 +71,7 @@ import {
preventClickDefault, walkTree, getBBoxOfElementAsPath, convertToPath, encode64, decode64,
getVisibleElements, dropXMLInternalSubset, init as utilsInit,
getBBox as utilsGetBBox, getStrokedBBoxDefaultVisible, isNullish, blankPageObjectURL,
$id, $qa, $qq
$id, $qa, $qq, getFeGaussianBlur
} from './utilities.js';
import {
transformPoint, matrixMultiply, hasMatrixTransform, transformListToTransform,
@ -2177,6 +2177,12 @@ class SvgCanvas {
const blur = getElem(elem.id + '_blur');
if (blur) {
val = blur.firstChild.getAttribute('stdDeviation');
} else {
const filterElem = getRefElem(filterUrl);
const blurElem = getFeGaussianBlur(filterElem);
if (blurElem !== null) {
val = blurElem.getAttribute('stdDeviation');
}
}
}
}

View File

@ -1203,6 +1203,26 @@ export let getRotationAngle = function (elem, toRad) {
export const getRefElem = function (attrVal) {
return getElem(getUrlFromAttr(attrVal).substr(1));
};
/**
* Get the reference element associated with the given attribute value.
* @function module:utilities.getFeGaussianBlur
* @param {any} Element
* @returns {any} Reference element
*/
export const getFeGaussianBlur = function (ele) {
if (ele?.firstChild?.tagName === 'feGaussianBlur') {
return ele.firstChild;
} else {
const childrens = ele.children;
// eslint-disable-next-line no-unused-vars
for (const [ _, value ] of Object.entries(childrens)) {
if (value.tagName === 'feGaussianBlur') {
return value;
}
}
}
return null;
};
/**
* Get a DOM element by ID within the SVG root element.