commit
1930c09285
|
@ -56,13 +56,23 @@ export default class Paint {
|
||||||
this.type = 'linearGradient';
|
this.type = 'linearGradient';
|
||||||
this.solidColor = null;
|
this.solidColor = null;
|
||||||
this.radialGradient = null;
|
this.radialGradient = null;
|
||||||
|
if(options.linearGradient.hasAttribute('xlink:href')) {
|
||||||
|
const xhref = document.getElementById(options.linearGradient.getAttribute('xlink:href').substr(1));
|
||||||
|
this.linearGradient = xhref.cloneNode(true);
|
||||||
|
} else {
|
||||||
this.linearGradient = options.linearGradient.cloneNode(true);
|
this.linearGradient = options.linearGradient.cloneNode(true);
|
||||||
|
}
|
||||||
// create linear gradient paint
|
// create linear gradient paint
|
||||||
} else if (options.radialGradient) {
|
} else if (options.radialGradient) {
|
||||||
this.type = 'radialGradient';
|
this.type = 'radialGradient';
|
||||||
this.solidColor = null;
|
this.solidColor = null;
|
||||||
this.linearGradient = null;
|
this.linearGradient = null;
|
||||||
|
if(options.radialGradient.hasAttribute('xlink:href')) {
|
||||||
|
const xhref = document.getElementById(options.radialGradient.getAttribute('xlink:href').substr(1));
|
||||||
|
this.radialGradient = xhref.cloneNode(true);
|
||||||
|
} else {
|
||||||
this.radialGradient = options.radialGradient.cloneNode(true);
|
this.radialGradient = options.radialGradient.cloneNode(true);
|
||||||
|
}
|
||||||
// create solid color paint
|
// create solid color paint
|
||||||
} else if (options.solidColor) {
|
} else if (options.solidColor) {
|
||||||
this.type = 'solidColor';
|
this.type = 'solidColor';
|
||||||
|
|
|
@ -1051,21 +1051,29 @@ export const convertGradientsMethod = function (elem) {
|
||||||
return (curThis.tagName.includes('Gradient'));
|
return (curThis.tagName.includes('Gradient'));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Array.prototype.forEach.call(elems, function (grad) {
|
Array.prototype.forEach.call(elems, function (grad) {
|
||||||
if (grad.getAttribute('gradientUnits') === 'userSpaceOnUse') {
|
if (grad.getAttribute('gradientUnits') === 'userSpaceOnUse') {
|
||||||
const svgcontent = svgContext_.getSVGContent();
|
const svgcontent = svgContext_.getSVGContent();
|
||||||
// TODO: Support more than one element with this ref by duplicating parent grad
|
// TODO: Support more than one element with this ref by duplicating parent grad
|
||||||
const fillStrokeElems = svgcontent.querySelectorAll('[fill="url(#' + grad.id + ')"],[stroke="url(#' + grad.id + ')"]');
|
let fillStrokeElems = svgcontent.querySelectorAll('[fill="url(#' + grad.id + ')"],[stroke="url(#' + grad.id + ')"]');
|
||||||
if (!fillStrokeElems.length) { return; }
|
if (!fillStrokeElems.length) {
|
||||||
|
const tmpFillStrokeElems = svgcontent.querySelectorAll('[*|href="#' + grad.id + '"]');
|
||||||
|
if (!tmpFillStrokeElems.length) {
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
if((tmpFillStrokeElems[0].tagName === "linearGradient" || tmpFillStrokeElems[0].tagName === "radialGradient") && tmpFillStrokeElems[0].getAttribute('gradientUnits') === 'userSpaceOnUse') {
|
||||||
|
fillStrokeElems = svgcontent.querySelectorAll('[fill="url(#' + tmpFillStrokeElems[0].id + ')"],[stroke="url(#' + tmpFillStrokeElems[0].id + ')"]');
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
// get object's bounding box
|
// get object's bounding box
|
||||||
const bb = utilsGetBBox(fillStrokeElems[0]);
|
const bb = utilsGetBBox(fillStrokeElems[0]);
|
||||||
|
|
||||||
// This will occur if the element is inside a <defs> or a <symbol>,
|
// This will occur if the element is inside a <defs> or a <symbol>,
|
||||||
// in which we shouldn't need to convert anyway.
|
// in which we shouldn't need to convert anyway.
|
||||||
if (!bb) { return; }
|
if (!bb) { return; }
|
||||||
|
|
||||||
if (grad.tagName === 'linearGradient') {
|
if (grad.tagName === 'linearGradient') {
|
||||||
const gCoords = {
|
const gCoords = {
|
||||||
x1: grad.getAttribute('x1'),
|
x1: grad.getAttribute('x1'),
|
||||||
|
|
Loading…
Reference in New Issue