Open neopheus opened 2 years ago
the eraser uses mask is definitely better
do you have a sample code for this usage?
Referenc
Thx
can we add shapes (rectangles for example) instead of using brushes?
I don't understand Ahh to the eraser Yes A brush brcomes a path Look into the code
I don't understand Ahh to the eraser Yes A brush brcomes a path Look into the code
ok
i try
a proposition : https://jsfiddle.net/avdigital/uw74h10y/180/
fabric.Object.prototype._createBaseSVGMarkup = function(objectMarkup, options) {
options = options || {};
var noStyle = options.noStyle,
reviver = options.reviver,
styleInfo = noStyle ? '' : 'style="' + this.getSvgStyles() + '" ',
shadowInfo = options.withShadow ? 'style="' + this.getSvgFilter() + '" ' : '',
clipPath = this.clipPath,
vectorEffect = this.strokeUniform ? 'vector-effect="non-scaling-stroke" ' : '',
absoluteClipPath = clipPath && clipPath.absolutePositioned,
stroke = this.stroke,
fill = this.fill,
shadow = this.shadow,
commonPieces, markup = [],
clipPathMarkup,
// insert commons in the markup, style and svgCommons
index = objectMarkup.indexOf('COMMON_PARTS'),
additionalTransform = options.additionalTransform;
if (clipPath) {
if (clipPath.inverted) {
clipPath.clipPathId = 'CLIPPATH_' + fabric.Object.__uid++;
console.log(this.width);
clipPathMarkup = '<mask id="' + clipPath.clipPathId + '" >\n';
clipPathMarkup += '<rect ' +
' fill="white"' +
' x="' +
fabric.util.toFixed(-this.width / 2, 2) +
'" y="' +
fabric.util.toFixed(-this.height / 2, 2) +
'" width="' +
fabric.util.toFixed(this.width, 2) +
'" height="' +
fabric.util.toFixed(this.height, 2) +
'"></rect>\n';
clipPathMarkup += clipPath.toClipPathSVG(reviver) +
'</mask>\n';
} else {
clipPath.clipPathId = 'CLIPPATH_' + fabric.Object.__uid++;
clipPathMarkup = '<clipPath id="' + clipPath.clipPathId + '" >\n' +
clipPath.toClipPathSVG(reviver) +
'</clipPath>\n';
}
}
if (absoluteClipPath) {
markup.push('<g ', shadowInfo, this.getSvgCommons(), ' >\n');
}
markup.push('<g ', this.getSvgTransform(false), !absoluteClipPath ? shadowInfo + this.getSvgCommons() : '', ' >\n');
commonPieces = [
styleInfo,
vectorEffect,
noStyle ? '' : this.addPaintOrder(), ' ',
additionalTransform ? 'transform="' + additionalTransform + '" ' : '',
].join('');
objectMarkup[index] = commonPieces;
if (fill && fill.toLive) {
markup.push(fill.toSVG(this));
}
if (stroke && stroke.toLive) {
markup.push(stroke.toSVG(this));
}
if (shadow) {
markup.push(shadow.toSVG(this));
}
if (clipPath) {
markup.push(clipPathMarkup);
}
markup.push(objectMarkup.join(''));
markup.push('</g>\n');
absoluteClipPath && markup.push('</g>\n');
return reviver ? reviver(markup.join('')) : markup.join('');
};
fabric.Object.prototype.getSvgCommons = function() {
var typeClipPath = this.clipPath;
if (typeClipPath) typeClipPath = this.clipPath.inverted ? 'mask="url(#' : 'clip-path="url(#';
return [
this.id ? 'id="' + this.id + '" ' : '',
typeClipPath ? typeClipPath + this.clipPath.clipPathId + ')" ' : '',
].join('');
};
Version
5.2.1
Test Case
Information about environment
Nodejs or browser? Browser Which browsers? Chrome 104.0.5112.79 (Build officiel) (arm64)
Steps To Reproduce
Error Message & Stack Trace
```txt ```
Expected Behavior
Actual Behavior
Code :
SVG generated :
I modified from Inkscape the clip to obtain the desired result
Here is the new SVG :
With mask :