toSVG now displays flipped objects correctly. Fix #297. Version 0.9.18.

This commit is contained in:
kangax 2012-10-26 15:26:44 +02:00
parent 17fe1a2929
commit 5998dfc1a5
6 changed files with 53 additions and 19 deletions

View file

@ -1,6 +1,6 @@
/*! Fabric.js Copyright 2008-2012, Printio (Juriy Zaytsev, Maxim Chernyak) */
var fabric = fabric || { version: "0.9.17" };
var fabric = fabric || { version: "0.9.18" };
if (typeof exports != 'undefined') {
exports.fabric = fabric;

31
dist/all.js vendored
View file

@ -1,7 +1,7 @@
/* build: `node build.js modules=ALL` */
/*! Fabric.js Copyright 2008-2012, Printio (Juriy Zaytsev, Maxim Chernyak) */
var fabric = fabric || { version: "0.9.17" };
var fabric = fabric || { version: "0.9.18" };
if (typeof exports != 'undefined') {
exports.fabric = fabric;
@ -8074,12 +8074,29 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, {
getSvgTransform: function() {
var angle = this.getAngle();
var NUM_FRACTION_DIGITS = fabric.Object.NUM_FRACTION_DIGITS;
return [
"translate(", toFixed(this.left, NUM_FRACTION_DIGITS), " ", toFixed(this.top, NUM_FRACTION_DIGITS), ")",
angle !== 0 ? (" rotate(" + toFixed(angle, NUM_FRACTION_DIGITS) + ")") : '',
(this.scaleX === 1 && this.scaleY === 1) ? '' : (" scale(" + toFixed(this.scaleX, NUM_FRACTION_DIGITS) +
" " + toFixed(this.scaleY, NUM_FRACTION_DIGITS) + ")")
].join('');
var translatePart = "translate(" +
toFixed(this.left, NUM_FRACTION_DIGITS) +
" " +
toFixed(this.top, NUM_FRACTION_DIGITS) +
")";
var anglePart = angle !== 0
? (" rotate(" + toFixed(angle, NUM_FRACTION_DIGITS) + ")")
: '';
var scalePart = (this.scaleX === 1 && this.scaleY === 1)
? '' :
(" scale(" +
toFixed(this.scaleX, NUM_FRACTION_DIGITS) +
" " +
toFixed(this.scaleY, NUM_FRACTION_DIGITS) +
")");
var flipXPart = this.flipX ? "matrix(-1 0 0 1 0 0) " : "";
var flipYPart = this.flipY ? "matrix(1 0 0 -1 0 0)" : "";
return [ translatePart, anglePart, scalePart, flipXPart, flipYPart ].join('');
},
/**

8
dist/all.min.js vendored

File diff suppressed because one or more lines are too long

BIN
dist/all.min.js.gz vendored

Binary file not shown.

View file

@ -1,7 +1,7 @@
{
"name": "fabric",
"description": "Object model for HTML5 canvas, and SVG-to-canvas parser. Backed by jsdom and node-canvas.",
"version": "0.9.17",
"version": "0.9.18",
"author": "Juriy Zaytsev <kangax@gmail.com>",
"keywords": ["canvas", "graphic", "graphics", "SVG", "node-canvas", "parser", "HTML5", "object model"],
"repository": "git://github.com/kangax/fabric.js",

View file

@ -364,12 +364,29 @@
getSvgTransform: function() {
var angle = this.getAngle();
var NUM_FRACTION_DIGITS = fabric.Object.NUM_FRACTION_DIGITS;
return [
"translate(", toFixed(this.left, NUM_FRACTION_DIGITS), " ", toFixed(this.top, NUM_FRACTION_DIGITS), ")",
angle !== 0 ? (" rotate(" + toFixed(angle, NUM_FRACTION_DIGITS) + ")") : '',
(this.scaleX === 1 && this.scaleY === 1) ? '' : (" scale(" + toFixed(this.scaleX, NUM_FRACTION_DIGITS) +
" " + toFixed(this.scaleY, NUM_FRACTION_DIGITS) + ")")
].join('');
var translatePart = "translate(" +
toFixed(this.left, NUM_FRACTION_DIGITS) +
" " +
toFixed(this.top, NUM_FRACTION_DIGITS) +
")";
var anglePart = angle !== 0
? (" rotate(" + toFixed(angle, NUM_FRACTION_DIGITS) + ")")
: '';
var scalePart = (this.scaleX === 1 && this.scaleY === 1)
? '' :
(" scale(" +
toFixed(this.scaleX, NUM_FRACTION_DIGITS) +
" " +
toFixed(this.scaleY, NUM_FRACTION_DIGITS) +
")");
var flipXPart = this.flipX ? "matrix(-1 0 0 1 0 0) " : "";
var flipYPart = this.flipY ? "matrix(1 0 0 -1 0 0)" : "";
return [ translatePart, anglePart, scalePart, flipXPart, flipYPart ].join('');
},
/**