Fixed path translation bug with SVG parsing

This commit is contained in:
Tim Andres 2013-04-16 01:49:42 -04:00
parent 85a8915a54
commit e2bba99e98
4 changed files with 2083 additions and 10 deletions

2045
dist/all.js vendored

File diff suppressed because it is too large Load diff

BIN
dist/all.min.js.gz vendored

Binary file not shown.

View file

@ -10,7 +10,8 @@
var fabric = global.fabric || (global.fabric = { }),
extend = fabric.util.object.extend,
capitalize = fabric.util.string.capitalize,
clone = fabric.util.object.clone;
clone = fabric.util.object.clone,
nestTransformMatrices = fabric.util.nestTransformMatrices;
var attributesMap = {
'cx': 'left',
@ -74,7 +75,12 @@
value = (value === 'evenodd') ? 'destination-over' : value;
}
if (attr === 'transform') {
value = fabric.parseTransformAttribute(value);
if (parentAttributes.transformMatrix) {
value = nestTransformMatrices(parentAttributes.transformMatrix, fabric.parseTransformAttribute(value));
}
else {
value = fabric.parseTransformAttribute(value);
}
}
attr = normalizeAttr(attr);
memo[attr] = isNaN(parsed) ? value : parsed;

View file

@ -396,6 +396,43 @@
ctx.clip();
}
function nestTransformMatrices(matrixA, matrixB) {
// Matrix multiply matrixA * matrixB
var a = [
[matrixA[0], matrixA[2], matrixA[4]],
[matrixA[1], matrixA[3], matrixA[5]],
[0 , 0 , 1 ]
];
var b = [
[matrixB[0], matrixB[2], matrixB[4]],
[matrixB[1], matrixB[3], matrixB[5]],
[0 , 0 , 1 ]
];
var result = [];
for (var r=0; r<3; r++) {
result[r] = [];
for (var c=0; c<3; c++) {
var sum = 0;
for (var k=0; k<3; k++) {
sum += a[r][k]*b[k][c];
}
result[r][c] = sum;
}
}
return [
result[0][0],
result[1][0],
result[0][1],
result[1][1],
result[0][2],
result[1][2]
];
}
fabric.util.removeFromArray = removeFromArray;
fabric.util.degreesToRadians = degreesToRadians;
fabric.util.radiansToDegrees = radiansToDegrees;
@ -413,5 +450,6 @@
fabric.util.createCanvasElement = createCanvasElement;
fabric.util.createAccessors = createAccessors;
fabric.util.clipContext = clipContext;
fabric.util.nestTransformMatrices = nestTransformMatrices;
})();