kangax/fabric.js — pull request #562 by timandres (2013-04-16 06:33:26+00:00)
Title: Bug fix: Exported SVG paths have wrong translation on re-parsing

The project I'm working on requires me to export some fabric objects to SVG, and then reload them from an svg string later. I've noticed that with paths where `top` and `left` values are set, the translations are wildly off when I reload them later.

To see an example of this behavior, run the Kitchensink demo, and load any SVG path from the SVG tab. Then run the following code:
```javascript
var svg = canvas.toSVG();
canvas.clear();

fabric.loadSVGFromString(svg, function(objects) {
for(var i=0; i` element with a `transform="translate(x y)"` attribute, but the `` element also has a `transform` attribute. Inspecting the parsed object from the SVG string showed that the transform matrix only accounted for the transform applied to the `` and not the ``.

To fix this issue, I implemented a matrix multiplication utility function in src/util/misc.js, and I modified `fabric.parseAttributes` so that for the transformMatrix attribute, the transformations are nested from the parent element's transformation (see http://www.w3.org/TR/SVG/coords.html#NestedTransformations).