Merge pull request #7732 from yurydelendik/svg-cgrp

Removes SVG this.cgrp usages.
This commit is contained in:
Tim van der Meij 2016-10-18 00:57:52 +02:00 committed by GitHub
commit 1783f14511

View File

@ -275,8 +275,8 @@ var SVGExtraState = (function SVGExtraStateClosure() {
this.dependencies = []; this.dependencies = [];
// Clipping // Clipping
this.clipId = ''; this.activeClipUrl = null;
this.pendingClip = false; this.clipGroup = null;
this.maskId = ''; this.maskId = '';
} }
@ -906,26 +906,31 @@ var SVGGraphics = (function SVGGraphicsClosure() {
clip: function SVGGraphics_clip(type) { clip: function SVGGraphics_clip(type) {
var current = this.current; var current = this.current;
// Add current path to clipping path // Add current path to clipping path
current.clipId = 'clippath' + clipCount; var clipId = 'clippath' + clipCount;
clipCount++; clipCount++;
this.clippath = document.createElementNS(NS, 'svg:clipPath'); var clipPath = document.createElementNS(NS, 'svg:clipPath');
this.clippath.setAttributeNS(null, 'id', current.clipId); clipPath.setAttributeNS(null, 'id', clipId);
clipPath.setAttributeNS(null, 'transform', pm(this.transformMatrix));
var clipElement = current.element.cloneNode(); var clipElement = current.element.cloneNode();
if (type === 'evenodd') { if (type === 'evenodd') {
clipElement.setAttributeNS(null, 'clip-rule', 'evenodd'); clipElement.setAttributeNS(null, 'clip-rule', 'evenodd');
} else { } else {
clipElement.setAttributeNS(null, 'clip-rule', 'nonzero'); clipElement.setAttributeNS(null, 'clip-rule', 'nonzero');
} }
this.clippath.setAttributeNS(null, 'transform', pm(this.transformMatrix)); clipPath.appendChild(clipElement);
this.clippath.appendChild(clipElement); this.defs.appendChild(clipPath);
this.defs.appendChild(this.clippath);
// Create a clipping group that references the clipping path. if (current.activeClipUrl) {
current.pendingClip = true; // The previous clipping group content can go out of order -- resetting
this.cgrp = document.createElementNS(NS, 'svg:g'); // cached clipGroup's.
this.cgrp.setAttributeNS(null, 'clip-path', current.clipGroup = null;
'url(#' + current.clipId + ')'); this.extraStack.forEach(function (prev) {
this.svg.appendChild(this.cgrp); prev.clipGroup = null;
});
}
current.activeClipUrl = 'url(#' + clipId + ')';
this.tgrp = null;
}, },
closePath: function SVGGraphics_closePath() { closePath: function SVGGraphics_closePath() {
@ -1164,6 +1169,20 @@ var SVGGraphics = (function SVGGraphicsClosure() {
return svg; return svg;
}, },
/**
* @private
*/
_ensureClipGroup: function SVGGraphics_ensureClipGroup() {
if (!this.current.clipGroup) {
var clipGroup = document.createElementNS(NS, 'svg:g');
clipGroup.setAttributeNS(null, 'clip-path',
this.current.activeClipUrl);
this.svg.appendChild(clipGroup);
this.current.clipGroup = clipGroup;
}
return this.current.clipGroup;
},
/** /**
* @private * @private
*/ */
@ -1171,9 +1190,8 @@ var SVGGraphics = (function SVGGraphicsClosure() {
if (!this.tgrp) { if (!this.tgrp) {
this.tgrp = document.createElementNS(NS, 'svg:g'); this.tgrp = document.createElementNS(NS, 'svg:g');
this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix)); this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
if (this.current.activeClipUrl) {
if (this.current.pendingClip) { this._ensureClipGroup().appendChild(this.tgrp);
this.cgrp.appendChild(this.tgrp);
} else { } else {
this.svg.appendChild(this.tgrp); this.svg.appendChild(this.tgrp);
} }