2
votes

I'm working on an SVG map, which contains a lot of text elements. The problem is, the old/source file has been generated years ago in Adobe Illustrator, which for some reason printed these elements as, e.g.:

<text transform="matrix(1 0 0 1 604.9754 765.0283)">4</text>

(First four arguments (1, 0, 0, 1) never change.)

What I want to achieve is to translate it into something like

<text x='123' y='456'>4</text>

I've already managed to collect all values needed using regex (text content and the two last transform arguments), but I have no idea what should I do next. I've also found out, that

The matrix( ) transform function specifies a transformation in the form of a transformation matrix of six values. matrix(a,b,c,d,e,f) is equivalent to applying the transformation matrix:

\begin{pmatrix} a & c & e \\ b & d & f \\ 0 & 0 & 1 \end{pmatrix}

which maps coordinates from a previous coordinate system into a new coordinate system by the following matrix equalities:

\begin{pmatrix} x_{\mathrm{newCoordSys}} \\ y_{\mathrm{newCoordSys}} \\ 1 \end{pmatrix} = \begin{pmatrix} a & c & e \\ b & d & f \\ 0 & 0 & 1 \end{pmatrix} \begin{pmatrix} x_{\mathrm{prevCoordSys}} \\ y_{\mathrm{prevCoordSys}} \\ 1 \end{pmatrix} = \begin{pmatrix} a x_{\mathrm{prevCoordSys}} + c y_{\mathrm{prevCoordSys}} + e \\ b x_{\mathrm{prevCoordSys}} + d y_{\mathrm{prevCoordSys}} + f \\ 1 \end{pmatrix}

So my question is:

how can I translate these matrix transform values into X,Y coordinates?

1
If you have effects such as filters on the text you might not get the same results if you replace a transform with x, yRobert Longson

1 Answers

1
votes

I've found out, that matrix(1 0 0 1 100px 200px) is equivalent to translateX(100px) translateY(200px) which means, that these values are actually the exact values I've been looking for. The reason I didn't realize it earlier was because I didn't adjust them (multiply, add) to my new image. I've also used X as Y coordinates inversely (ouch). I hope it can help someone.