blob: 0e96dff146f56cadcb743a6e1c71d0726c3fc8bb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Matrix testing</title>
<style type="text/css" media="screen">
div {
-webkit-box-sizing: border-box;
}
.column {
margin: 10px;
display: inline-block;
vertical-align: top;
}
.container {
position: relative;
height: 200px;
width: 200px;
margin: 10px;
background-color: silver;
border: 1px solid black;
}
.box {
position: absolute;
top: 0;
left: 0;
height: 60px;
width: 60px;
border: 1px dotted black;
-webkit-transform-origin: top left; /* to match SVG */
}
.final {
border: 1px solid blue;
}
</style>
<script type="text/javascript" charset="utf-8">
function doTest()
{
doCSS();
doSVG();
}
function doCSS()
{
var matrixDiv = document.getElementById('matrixed');
var firstMatrix = new WebKitCSSMatrix(document.getElementById('box1').style.transform);
var secondMatrix = new WebKitCSSMatrix(document.getElementById('box2').style.transform);
var thirdMatrix = new WebKitCSSMatrix(document.getElementById('box3').style.transform);
var finalMatrix = firstMatrix.multiply(secondMatrix);
finalMatrix = finalMatrix.multiply(thirdMatrix);
// "Flipped" behavior
// var finalMatrix = thirdMatrix.multiply(secondMatrix);
// finalMatrix = finalMatrix.multiply(firstMatrix);
matrixDiv.style.transform = finalMatrix;
}
function doSVG()
{
var matrixDiv = document.getElementById('matrix-svg');
var svgroot = document.getElementsByTagName('svg')[0];
var firstMatrix = svgroot.createSVGMatrix();
firstMatrix = firstMatrix.translate(75, 25);
var secondMatrix = svgroot.createSVGMatrix();
secondMatrix = secondMatrix.scale(2);
var thirdMatrix = svgroot.createSVGMatrix();
thirdMatrix = thirdMatrix.rotate(45);
var finalMatrix = firstMatrix.multiply(secondMatrix);
finalMatrix = finalMatrix.multiply(thirdMatrix);
var matrixString = "matrix(" + finalMatrix.a + " " + finalMatrix.b +
" " + finalMatrix.c + " " + finalMatrix.d + " " + finalMatrix.e + " "
+ finalMatrix.f + ")";
matrixDiv.setAttribute("transform", matrixString);
}
window.addEventListener('load', doTest, false)
</script>
</head>
<body>
<div class="column">
<h2>SVG nested</h2>
<div class="container">
<svg xmlns="http://www.w3.org/2000/svg" version="1.1"
viewBox="0 0 200 200" style="width:200px; height:200px;">
<g id="group1" x="0" y="0" width="60" height="60" transform="translate(75, 25)">
<rect x="0" y="0" width="60" height="60" stroke="black" stroke-width="1px" stroke-dasharray="1 1" fill="none" />
<g id="group2" x="0" y="0" width="60" height="60" transform="scale(2)" >
<rect x="0" y="0" width="60" height="60" stroke="black" stroke-dasharray="1 1" stroke-width="1px" fill="none" />
<rect id="group3" x="0" y="0" width="60" height="60" stroke="blue" fill="none" transform="rotate(45)" />
</g>
</g>
</svg>
</div>
<h2>CSS nested</h2>
<div class="container">
<div id="box1" class="box" style="transform: translate(75px, 25px)">
<div id="box2" class="box" style="transform: scale(2)">
<div id="box3" class="final box" style="transform: rotate(45deg)">
</div>
</div>
</div>
</div>
</div>
<div class="column">
<h2>SVG compound</h2>
<div class="container">
<svg xmlns="http://www.w3.org/2000/svg" version="1.1"
viewBox="0 0 200 200" style="width:200px; height:200px;">
<rect x="0" y="0" width="60" height="60" stroke="blue" fill="none" transform="translate(75, 25) scale(2) rotate(45)">
</rect>
</svg>
</div>
<h2>CSS compound</h2>
<div class="container">
<div class="final box" style="transform: translate(75px, 25px) scale(2) rotate(45deg)">
</div>
</div>
</div>
<div class="column">
<h2>SVG Matrix</h2>
<div class="container">
<svg xmlns="http://www.w3.org/2000/svg" version="1.1"
viewBox="0 0 200 200" style="width:200px; height:200px;">
<rect id="matrix-svg" x="0" y="0" width="60" height="60" stroke="blue" fill="none">
</rect>
</svg>
</div>
<h2>CSSMatrix</h2>
<div class="container">
<div id="matrixed" class="final box">
</div>
</div>
</div>
</body>
</html>
|