How to apply transformation matrix to path coordinates in Raphael JS 2?

I want to apply or "bake" the conversion of several paths in Raphael JS 2, then to combine them into one single path.

Here is an example of a path where I would like the "transform" attribute to be applied to all "d" coordinates.

<path style="" fill="#000000" stroke="none" d="M150,-265C182,-275,171,-220,180,-194L178,-194C181,-192,180,-185,181,-180C211,-169,282,-173,306,-166C308,-169,316,-171,315,-165C268,-157,225,-148,184,-137C188,-118,186,-96,190,-79L282,-131C289,-131,296,-135,297,-126C293,-118,271,-105,236,-80C190,-48,155,-20,125,-6C112,-15,115,-34,111,-51C121,-70,108,-107,107,-133C70,-132,-5,-126,0,-157C18,-170,39,-181,64,-191C75,-190,92,-181,100,-185C99,-198,95,-211,89,-225Z" transform="matrix(0.1389, 0, 0, 0.1389, 291.91, 235.465)" stroke-width="7.199999999999999"> 

I understand that the svg-edit structure can convert the coordinates of the path to absolute positions and remove the transformation matrix in the process.

Some related questions that I could not get an answer to:

+7
source share
2 answers

A partial solution can be found in this jsFiddle: http://jsfiddle.net/X6YNm/1/

 //include whoa font, and raphael paper = Raphael('holder'); var text = paper.print(300, 50, 'Foo', paper.getFont('whoa'), 50, 'baseline'); var path = new Array(); for ( var i = 0; i < text.length; i ++ ) { path[i] = paper.path(Raphael.pathToRelative(text[i].attr('path'))); path[i].attr({ fill: 'red' }).translate(i * 250, 300); } 

Creates a new path based on each character in the source set. However, the script does not correctly place the characters.

Some related google group discussion raphael: Some google group discussions here: https://groups.google.com/d/msg/raphaeljs/OP29oelR5Eg/zPi5m6rjsvIJ

0
source

Here's a jsFiddle that applies all the transforms for you: http://jsfiddle.net/ecmanaut/cFSjt/

Rafael may reveal some or all of the tools that I filled out myself, but if not, they do the trick beautifully. If your needs also cover more elements without a path (e.g. groups, rectangles, circles, ellipses, etc.), first convert them to path elements (using pathify , for instance).

+7
source

All Articles