ToSVG writes out the matrix in SVG notation, taking care of the proper order of transformations.
(h float64)
| 858 | |
| 859 | // ToSVG writes out the matrix in SVG notation, taking care of the proper order of transformations. |
| 860 | func (m Matrix) ToSVG(h float64) string { |
| 861 | s := &strings.Builder{} |
| 862 | tx, ty, phi, sx, sy, theta := m.Decompose() |
| 863 | if !Equal(m[0][2], 0.0) || !Equal(m[1][2], 0.0) { |
| 864 | fmt.Fprintf(s, " translate(%v,%v)", dec(tx), dec(h-ty)) |
| 865 | } |
| 866 | if !Equal(phi, 0.0) { |
| 867 | fmt.Fprintf(s, " rotate(%v)", dec(-phi)) |
| 868 | } |
| 869 | if !Equal(sx, 1.0) || !Equal(sy, 1.0) { |
| 870 | fmt.Fprintf(s, " scale(%v,%v)", dec(sx), dec(sy)) |
| 871 | } |
| 872 | if !Equal(theta, 0.0) { |
| 873 | fmt.Fprintf(s, " rotate(%v)", dec(-theta)) |
| 874 | } |
| 875 | |
| 876 | matrix := fmt.Sprintf("matrix(%v,%v,%v,%v,%v,%v)", dec(m[0][0]), -dec(m[1][0]), -dec(m[0][1]), dec(m[1][1]), dec(m[0][2]), dec(h-m[1][2])) |
| 877 | if s.Len() == 0 { |
| 878 | return "" |
| 879 | } else if len(matrix) < s.Len()-1 { |
| 880 | return matrix |
| 881 | } |
| 882 | return s.String()[1:] |
| 883 | } |
| 884 | |
| 885 | //////////////////////////////////////////////////////////////// |
| 886 |