mirror of
https://github.com/Hopiu/fabric.js.git
synced 2026-04-18 21:20:59 +00:00
Update group.class.js
This commit is contained in:
parent
fcaecc8cf5
commit
0edd147b0e
9 changed files with 58 additions and 42 deletions
|
|
@ -23,7 +23,7 @@ fabric.util.object.extend(fabric.Object.prototype, /** @lends fabric.Object.prot
|
|||
opacity = typeof this.opacity !== 'undefined' ? this.opacity : '1',
|
||||
|
||||
visibility = this.visible ? '' : ' visibility: hidden;',
|
||||
filter = this.shadow ? 'filter: url(#SVGID_' + this.shadow.id + ');' : '';
|
||||
filter = this.getSvgFilter();
|
||||
|
||||
return [
|
||||
'stroke: ', stroke, '; ',
|
||||
|
|
@ -40,6 +40,14 @@ fabric.util.object.extend(fabric.Object.prototype, /** @lends fabric.Object.prot
|
|||
].join('');
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns filter for svg shadow
|
||||
* @return {String}
|
||||
*/
|
||||
getSvgFilter: function() {
|
||||
return this.shadow ? 'filter: url(#SVGID_' + this.shadow.id + ');' : '';
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns transform-string for svg-export
|
||||
* @return {String}
|
||||
|
|
|
|||
|
|
@ -647,15 +647,15 @@
|
|||
function _createSVGPattern(markup, canvas, property) {
|
||||
if (canvas[property] && canvas[property].toSVG) {
|
||||
markup.push(
|
||||
'<pattern x="0" y="0" id="', property, 'Pattern" ',
|
||||
'\t<pattern x="0" y="0" id="', property, 'Pattern" ',
|
||||
'width="', canvas[property].source.width,
|
||||
'" height="', canvas[property].source.height,
|
||||
'" patternUnits="userSpaceOnUse">',
|
||||
'<image x="0" y="0" ',
|
||||
'" patternUnits="userSpaceOnUse">\n',
|
||||
'\t\t<image x="0" y="0" ',
|
||||
'width="', canvas[property].source.width,
|
||||
'" height="', canvas[property].source.height,
|
||||
'" xlink:href="', canvas[property].source.src,
|
||||
'"></image></pattern>'
|
||||
'"></image>\n\t</pattern>\n'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -1018,7 +1018,7 @@
|
|||
'@font-face {',
|
||||
'font-family: ', objects[i].fontFamily, '; ',
|
||||
'src: url(\'', objects[i].path, '\')',
|
||||
'}'
|
||||
'}\n'
|
||||
//jscs:enable validateIndentation
|
||||
].join('');
|
||||
}
|
||||
|
|
@ -1026,11 +1026,11 @@
|
|||
if (markup) {
|
||||
markup = [
|
||||
//jscs:disable validateIndentation
|
||||
'<style type="text/css">',
|
||||
'\t<style type="text/css">',
|
||||
'<![CDATA[',
|
||||
markup,
|
||||
']]>',
|
||||
'</style>'
|
||||
'</style>\n'
|
||||
//jscs:enable validateIndentation
|
||||
].join('');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -266,6 +266,7 @@
|
|||
ctx.transform.apply(ctx, this.transformMatrix);
|
||||
}
|
||||
this.transform(ctx);
|
||||
this._setShadow(ctx);
|
||||
this.clipTo && fabric.util.clipContext(this, ctx);
|
||||
// the array is now sorted in order of highest first, so start from end
|
||||
for (var i = 0, len = this._objects.length; i < len; i++) {
|
||||
|
|
@ -531,16 +532,19 @@
|
|||
* @return {String} svg representation of an instance
|
||||
*/
|
||||
toSVG: function(reviver) {
|
||||
var markup = [
|
||||
//jscs:disable validateIndentation
|
||||
'<g ',
|
||||
'transform="', this.getSvgTransform(),
|
||||
var markup = this._createBaseSVGMarkup();
|
||||
markup.push(
|
||||
'<g transform="',
|
||||
/* avoiding styles intentionally */
|
||||
this.getSvgTransform(),
|
||||
this.getSvgTransformMatrix(),
|
||||
'" style="',
|
||||
this.getSvgFilter(),
|
||||
'">\n'
|
||||
//jscs:enable validateIndentation
|
||||
];
|
||||
);
|
||||
|
||||
for (var i = 0, len = this._objects.length; i < len; i++) {
|
||||
markup.push(this._objects[i].toSVG(reviver));
|
||||
markup.push('\t', this._objects[i].toSVG(reviver));
|
||||
}
|
||||
|
||||
markup.push('</g>\n');
|
||||
|
|
|
|||
|
|
@ -227,7 +227,7 @@
|
|||
* @return {String} svg representation of an instance
|
||||
*/
|
||||
toSVG: function(reviver) {
|
||||
var markup = [], x = -this.width / 2, y = -this.height / 2,
|
||||
var markup = this._createBaseSVGMarkup(), x = -this.width / 2, y = -this.height / 2,
|
||||
preserveAspectRatio = 'none';
|
||||
if (this.group && this.group.type === 'path-group') {
|
||||
x = this.left;
|
||||
|
|
|
|||
|
|
@ -175,17 +175,16 @@
|
|||
var objects = this.getObjects(),
|
||||
p = this.getPointByOrigin('left', 'top'),
|
||||
translatePart = 'translate(' + p.x + ' ' + p.y + ')',
|
||||
markup = [
|
||||
//jscs:disable validateIndentation
|
||||
'<g ',
|
||||
'style="', this.getSvgStyles(), '" ',
|
||||
'transform="', this.getSvgTransformMatrix(), translatePart, this.getSvgTransform(), '" ',
|
||||
'>\n'
|
||||
//jscs:enable validateIndentation
|
||||
];
|
||||
markup = this._createBaseSVGMarkup();
|
||||
markup.push(
|
||||
'<g ',
|
||||
'style="', this.getSvgStyles(), '" ',
|
||||
'transform="', this.getSvgTransformMatrix(), translatePart, this.getSvgTransform(), '" ',
|
||||
'>\n'
|
||||
);
|
||||
|
||||
for (var i = 0, len = objects.length; i < len; i++) {
|
||||
markup.push(objects[i].toSVG(reviver));
|
||||
markup.push('\t', objects[i].toSVG(reviver));
|
||||
}
|
||||
markup.push('</g>\n');
|
||||
|
||||
|
|
@ -207,9 +206,14 @@
|
|||
* @return {Boolean} true if all paths are of the same color (`fill`)
|
||||
*/
|
||||
isSameColor: function() {
|
||||
var firstPathFill = (this.getObjects()[0].get('fill') || '').toLowerCase();
|
||||
var firstPathFill = this.getObjects()[0].get('fill') || '';
|
||||
if (typeof firstPathFill !== 'string') {
|
||||
return false;
|
||||
}
|
||||
firstPathFill = firstPathFill.toLowerCase();
|
||||
return this.getObjects().every(function(path) {
|
||||
return (path.get('fill') || '').toLowerCase() === firstPathFill;
|
||||
var pathFill = path.get('fill') || '';
|
||||
return typeof pathFill === 'string' && (pathFill).toLowerCase() === firstPathFill;
|
||||
});
|
||||
},
|
||||
|
||||
|
|
|
|||
|
|
@ -1280,7 +1280,7 @@
|
|||
_setSVGPreamble: function(markup, options) {
|
||||
if (!options.suppressPreamble) {
|
||||
markup.push(
|
||||
'<?xml version="1.0" encoding="', (options.encoding || 'UTF-8'), '" standalone="no" ?>',
|
||||
'<?xml version="1.0" encoding="', (options.encoding || 'UTF-8'), '" standalone="no" ?>\n',
|
||||
'<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" ',
|
||||
'"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n'
|
||||
);
|
||||
|
|
@ -1324,12 +1324,12 @@
|
|||
options.viewBox.width + ' ' +
|
||||
options.viewBox.height + '" '
|
||||
: null),
|
||||
'xml:space="preserve">',
|
||||
'<desc>Created with Fabric.js ', fabric.version, '</desc>',
|
||||
'xml:space="preserve">\n',
|
||||
'<desc>Created with Fabric.js ', fabric.version, '</desc>\n',
|
||||
'<defs>',
|
||||
fabric.createSVGFontFacesMarkup(this.getObjects()),
|
||||
fabric.createSVGRefElementsMarkup(this),
|
||||
'</defs>'
|
||||
'</defs>\n'
|
||||
);
|
||||
},
|
||||
|
||||
|
|
@ -1372,7 +1372,7 @@
|
|||
? this[property].source.height
|
||||
: this.height),
|
||||
'" fill="url(#' + property + 'Pattern)"',
|
||||
'></rect>'
|
||||
'></rect>\n'
|
||||
);
|
||||
}
|
||||
else if (this[property] && property === 'overlayColor') {
|
||||
|
|
@ -1381,7 +1381,7 @@
|
|||
'width="', this.width,
|
||||
'" height="', this.height,
|
||||
'" fill="', this[property], '"',
|
||||
'></rect>'
|
||||
'></rect>\n'
|
||||
);
|
||||
}
|
||||
},
|
||||
|
|
|
|||
|
|
@ -2,11 +2,11 @@
|
|||
|
||||
// var emptyImageCanvasData = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAfQAAAH0CAYAAADL1t+KAAAH7ElEQVR4nO3VMQ0AMAzAsPInvYHoMS2yEeTLHADge/M6AADYM3QACDB0AAgwdAAIMHQACDB0AAgwdAAIMHQACDB0AAgwdAAIMHQACDB0AAgw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DB0AAgwdAAIMHQACDB0AAgwdAAIMHQACDB0AAgwdAAIMHQACDB0AAgwdAAIMHQACDB0AAgwdAAIMHQACDB0AAgwdAAIMHQACDB0AAgwdAAIMHQACDB0AAgwdAAIMHQACDB0AAgwdAAIMHQACDB0AAgwdAAIMHQACDB0AAgwdAAIMHQACDB0AAgwdAAIMHQACDB0AAgwdAAIMHQACDB0AAgwdAAIMHQACDB0AAgwdAAIMHQACDB0AAgwdAAIMHQACDB0AAgwdAAIMHQACDB0AAgwdAAIMHQACDB0AAgwdAAIMHQACDB0AAgwdAAIMHQACDB0AAgwdAAIMHQACDB0AAgwdAAIMHQACDB0AAgwdAAIMHQACDB0AAgwdAAIMHQACDB0AAgwdAAIMHQACDB0AAgwdAAIuMjH4b7osLFBAAAAAElFTkSuQmCC";
|
||||
|
||||
var CANVAS_SVG = '<?xml version="1.0" encoding="UTF-8" standalone="no" ?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n'+
|
||||
'<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="600" height="600" xml:space="preserve"><desc>Created with Fabric.js ' + fabric.version + '</desc><defs></defs></svg>';
|
||||
var CANVAS_SVG = '<?xml version="1.0" encoding="UTF-8" standalone="no" ?>\n<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n'+
|
||||
'<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="600" height="600" xml:space="preserve">\n<desc>Created with Fabric.js ' + fabric.version + '</desc>\n<defs></defs>\n</svg>';
|
||||
|
||||
var CANVAS_SVG_VIEWBOX = '<?xml version="1.0" encoding="UTF-8" standalone="no" ?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n'+
|
||||
'<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="300" height="300" viewBox="100 100 300 300" xml:space="preserve"><desc>Created with Fabric.js ' + fabric.version + '</desc><defs></defs></svg>';
|
||||
var CANVAS_SVG_VIEWBOX = '<?xml version="1.0" encoding="UTF-8" standalone="no" ?>\n<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n'+
|
||||
'<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="300" height="300" viewBox="100 100 300 300" xml:space="preserve">\n<desc>Created with Fabric.js ' + fabric.version + '</desc>\n<defs></defs>\n</svg>';
|
||||
|
||||
var PATH_JSON = '{"objects": [{"type": "path", "originX": "left", "originY": "top", "left": 268, "top": 266, "width": 51, "height": 49,'+
|
||||
' "fill": "rgb(0,0,0)", "stroke": null, "strokeWidth": 1, "scaleX": 1, "scaleY": 1, '+
|
||||
|
|
|
|||
|
|
@ -400,7 +400,7 @@ test('toObject without default values', function() {
|
|||
var group = makeGroupWith2Objects();
|
||||
ok(typeof group.toSVG == 'function');
|
||||
|
||||
var expectedSVG = '<g transform="translate(90 130)">\n<rect x="-15" y="-5" rx="0" ry="0" width="30" height="10" style="stroke: none; stroke-width: 0; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: rgb(0,0,0); fill-rule: nonzero; opacity: 1;" transform="translate(25 -25)"/>\n<rect x="-5" y="-20" rx="0" ry="0" width="10" height="40" style="stroke: none; stroke-width: 0; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: rgb(0,0,0); fill-rule: nonzero; opacity: 1;" transform="translate(-35 10)"/>\n</g>\n';
|
||||
var expectedSVG = '<g transform="translate(90 130)" style="">\n\t<rect x="-15" y="-5" rx="0" ry="0" width="30" height="10" style="stroke: none; stroke-width: 0; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: rgb(0,0,0); fill-rule: nonzero; opacity: 1;" transform="translate(25 -25)"/>\n\t<rect x="-5" y="-20" rx="0" ry="0" width="10" height="40" style="stroke: none; stroke-width: 0; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: rgb(0,0,0); fill-rule: nonzero; opacity: 1;" transform="translate(-35 10)"/>\n</g>\n';
|
||||
equal(group.toSVG(), expectedSVG);
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -32,13 +32,13 @@
|
|||
};
|
||||
|
||||
var REFERENCE_PATH_GROUP_SVG = '<g style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: none; fill-rule: nonzero; opacity: 1;" transform="translate(0 0)" >\n' +
|
||||
'<path d="M 100 100 L 300 100 L 200 300 z" style="stroke: blue; stroke-width: 3; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: rgb(255,0,0); fill-rule: nonzero; opacity: 1;" transform="" stroke-linecap="round" />\n' +
|
||||
'<path d="M 200 200 L 100 200 L 400 50 z" style="stroke: blue; stroke-width: 3; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: rgb(255,0,0); fill-rule: nonzero; opacity: 1;" transform="" stroke-linecap="round" />\n' +
|
||||
'\t<path d="M 100 100 L 300 100 L 200 300 z" style="stroke: blue; stroke-width: 3; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: rgb(255,0,0); fill-rule: nonzero; opacity: 1;" transform="" stroke-linecap="round" />\n' +
|
||||
'\t<path d="M 200 200 L 100 200 L 400 50 z" style="stroke: blue; stroke-width: 3; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: rgb(255,0,0); fill-rule: nonzero; opacity: 1;" transform="" stroke-linecap="round" />\n' +
|
||||
'</g>\n';
|
||||
|
||||
var REFERENCE_PATH_GROUP_SVG_WITH_MATRIX = '<g style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: none; fill-rule: nonzero; opacity: 1;" transform=" matrix(1 2 3 4 5 6) translate(0 0)" >\n' +
|
||||
'<path d="M 100 100 L 300 100 L 200 300 z" style="stroke: blue; stroke-width: 3; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: rgb(255,0,0); fill-rule: nonzero; opacity: 1;" transform="" stroke-linecap="round" />\n' +
|
||||
'<path d="M 200 200 L 100 200 L 400 50 z" style="stroke: blue; stroke-width: 3; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: rgb(255,0,0); fill-rule: nonzero; opacity: 1;" transform="" stroke-linecap="round" />\n' +
|
||||
'\t<path d="M 100 100 L 300 100 L 200 300 z" style="stroke: blue; stroke-width: 3; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: rgb(255,0,0); fill-rule: nonzero; opacity: 1;" transform="" stroke-linecap="round" />\n' +
|
||||
'\t<path d="M 200 200 L 100 200 L 400 50 z" style="stroke: blue; stroke-width: 3; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: rgb(255,0,0); fill-rule: nonzero; opacity: 1;" transform="" stroke-linecap="round" />\n' +
|
||||
'</g>\n';
|
||||
|
||||
function getPathElement(path) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue