(String matrixStr)
| 1085 | |
| 1086 | |
| 1087 | static protected PMatrix2D parseSingleTransform(String matrixStr) { |
| 1088 | //String[] pieces = PApplet.match(matrixStr, "^\\s*(\\w+)\\((.*)\\)\\s*$"); |
| 1089 | String[] pieces = PApplet.match(matrixStr, "[,\\s]*(\\w+)\\((.*)\\)"); |
| 1090 | if (pieces == null) { |
| 1091 | System.err.println("Could not parse transform " + matrixStr); |
| 1092 | return null; |
| 1093 | } |
| 1094 | float[] m = PApplet.parseFloat(PApplet.splitTokens(pieces[2], ", ")); |
| 1095 | if (pieces[1].equals("matrix")) { |
| 1096 | return new PMatrix2D(m[0], m[2], m[4], m[1], m[3], m[5]); |
| 1097 | |
| 1098 | } else if (pieces[1].equals("translate")) { |
| 1099 | float tx = m[0]; |
| 1100 | float ty = (m.length == 2) ? m[1] : m[0]; |
| 1101 | return new PMatrix2D(1, 0, tx, 0, 1, ty); |
| 1102 | |
| 1103 | } else if (pieces[1].equals("scale")) { |
| 1104 | float sx = m[0]; |
| 1105 | float sy = (m.length == 2) ? m[1] : m[0]; |
| 1106 | return new PMatrix2D(sx, 0, 0, 0, sy, 0); |
| 1107 | |
| 1108 | } else if (pieces[1].equals("rotate")) { |
| 1109 | float angle = m[0]; |
| 1110 | |
| 1111 | if (m.length == 1) { |
| 1112 | float c = PApplet.cos(angle); |
| 1113 | float s = PApplet.sin(angle); |
| 1114 | // SVG version is cos(a) sin(a) -sin(a) cos(a) 0 0 |
| 1115 | return new PMatrix2D(c, -s, 0, s, c, 0); |
| 1116 | |
| 1117 | } else if (m.length == 3) { |
| 1118 | PMatrix2D mat = new PMatrix2D(0, 1, m[1], 1, 0, m[2]); |
| 1119 | mat.rotate(m[0]); |
| 1120 | mat.translate(-m[1], -m[2]); |
| 1121 | return mat; |
| 1122 | } |
| 1123 | |
| 1124 | } else if (pieces[1].equals("skewX")) { |
| 1125 | return new PMatrix2D(1, 0, 1, PApplet.tan(m[0]), 0, 0); |
| 1126 | |
| 1127 | } else if (pieces[1].equals("skewY")) { |
| 1128 | return new PMatrix2D(1, 0, 1, 0, PApplet.tan(m[0]), 0); |
| 1129 | } |
| 1130 | return null; |
| 1131 | } |
| 1132 | |
| 1133 | |
| 1134 | protected void parseColors(XML properties) { |
no test coverage detected