Skip to content

Commit a05ca37

Browse files
committed
[css-transforms-1] Backport more math from SVG spec. Mostly in examples. w3c#909
1 parent bd5c21a commit a05ca37

5 files changed

Lines changed: 66 additions & 12 deletions

File tree

css-transforms-1/Overview.bs

Lines changed: 66 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,7 @@ The Transform Rendering Model {#transform-rendering}
180180

181181
<em>This section is normative.</em>
182182

183-
Specifying a value other than ''transform/none'' for the 'transform' property establishes a new [=local coordinate system=] at the element that it is applied to. The mapping from where the element would have rendered into that local coordinate system is given by the element's [=transformation matrix=]. Transformations are cumulative. That is, elements establish their local coordinate system within the coordinate system of their parent. From the perspective of the user, an element effectively accumulates all the 'transform' properties of its ancestors as well as any local transform applied to it. The accumulation of these transforms defines a [=current transformation matrix=] for the element.
184-
185-
The coordinate space is a coordinate system with two axes: the X axis increases horizontally to the right; the Y axis increases vertically downwards.
183+
Specifying a value other than ''transform/none'' for the 'transform' property establishes a new [=local coordinate system=] at the element that it is applied to. The mapping from where the element would have rendered into that local coordinate system is given by the element's [=transformation matrix=].
186184

187185
<p id="transformation-matrix-computation">
188186
The [=transformation matrix=] is computed from the 'transform' and 'transform-origin' properties as follows:
@@ -192,8 +190,63 @@ The [=transformation matrix=] is computed from the 'transform' and 'transform-or
192190
3. Multiply by each of the transform functions in 'transform' property from left to right
193191
4. Translate by the negated computed X and Y values of 'transform-origin'
194192

193+
<div class=example>
194+
195+
An element has a 'transform' property that is not ''transform/none''.
196+
197+
<pre><code highlight=css>
198+
div {
199+
transform-origin: 0 0;
200+
transform: translate(-10px, -20px) scale(2) rotate(45deg);
201+
}
202+
</code></pre>
203+
204+
The 'transform-origin' property is set to ''0 0'' and can be omitted. The [=transformation matrix=] <i>TM</i> gets computed by post-multying the <<translate()>>, <<scale()>> and <<rotate()>> <<transform-function>>s.
205+
206+
<img src="images/tm.png" alt="TM = \begin{bmatrix} 1 & 0 & 0 & -10 \\ 0 & 1 & 0 & -20 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} \cdot \begin{bmatrix} 2 & 0 & 0 & 0 \\ 0 & 2 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} \cdot \begin{bmatrix} cos(45) & -sin(45) & 0 & 0 \\ sin(45) & cos(45) & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix}" width="627">
207+
</div>
208+
195209
Transforms apply to [=transformable elements=].
196210

211+
The coordinate space is a coordinate system with two axes: the X axis increases horizontally to the right; the Y axis increases vertically downwards.
212+
213+
Transformations are cumulative. That is, elements establish their local coordinate system within the coordinate system of their parent.
214+
215+
To map a point <i>p<sub>local</sub></i> with the coordinate pair <i>x<sub>local</sub></i> and <i>y<sub>local</sub></i> from the [=local coordinate system=] of an element into the parent's coordinate system, post-multiply the [=transformation matrix=] <i>TM</i> of the element by <i>p<sub>local</sub></i>. The result is the mapped point <i>p<sub>parent</sub></i> with the coordinate pair <i>x<sub>parent</sub></i> and <i>y<sub>parent</sub></i> in the parent's [=local coordinate system=].
216+
217+
<img src="images/tm-map.png" alt="\begin{bmatrix} x_{parent} \\ y_{parent} \\ 0 \\ 1 \end{bmatrix} = TM \cdot \begin{bmatrix} x_{local} \\ y_{local} \\ 0 \\ 1 \end{bmatrix}" width="276">
218+
219+
From the perspective of the user, an element effectively accumulates all the 'transform' properties of its ancestors as well as any local transform applied to it. The accumulation of these transforms defines a [=current transformation matrix=] (CTM) for the element.
220+
221+
<p id="current-transformation-matrix-computation">
222+
The [=current transformation matrix=] is computed by post-multiplying all transformation matrices starting from the [=viewport coordinate system=] and ending with the [=transformation matrix=] of an element.
223+
224+
<div class=example>
225+
This example has multiple, nested elements in an SVG document. Some elements get transformed by a [=transformation matrix=].
226+
227+
<pre><code highlight=html>
228+
&lt;svg xmlns="http://www.w3.org/2000/svg">
229+
&lt;g transform="translate(-10, 20)">
230+
&lt;g transform="scale(2)">
231+
&lt;rect width="200" height="200" transform="rotate(45)"/>
232+
&lt;/g>
233+
&lt;/g>
234+
&lt;/svg>
235+
</code></pre>
236+
237+
* ''translate(-10, 20)'' computes to the transformation matrix <i>T1</i>
238+
* ''scale(2)'' computes to the transformation matrix <i>T2</i>
239+
* ''rotate(45)'' computes to the transformation matrix <i>T3</i>
240+
241+
The CTM for the SVG <a element>rect</a> element is the result of multiplying <i>T1</i>, <i>T2</i> and <i>T3</i> in order.
242+
243+
<img src="images/ctm.png" alt="CTM = \begin{bmatrix} 1 & 0 & 0 & -10 \\ 0 & 1 & 0 & -20 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} \cdot \begin{bmatrix} 2 & 0 & 0 & 0 \\ 0 & 2 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} \cdot \begin{bmatrix} cos(45) & -sin(45) & 0 & 0 \\ sin(45) & cos(45) & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix}" width="627">
244+
245+
To map a point <i>p<sub>local</sub></i> with the coordinate pair <i>x<sub>local</sub></i> and <i>y<sub>local</sub></i> from the [=local coordinate system=] of the SVG <a element>rect</a> element into the [=viewport coordinate system=], post-multiply the [=current transformation matrix=] <i>CTM</i> of the element by <i>p<sub>local</sub></i>. The result is the mapped point <i>p<sub>viewport</sub></i> with the coordinate pair <i>x<sub>viewport</sub></i> and <i>y<sub>viewport</sub></i> in the [=viewport coordinate system=].
246+
247+
<img src="images/ctm-map.png" alt="\begin{bmatrix} x_{viewport} \\ y_{viewport} \\ 0 \\ 1 \end{bmatrix} = CTM \cdot \begin{bmatrix} x_{local} \\ y_{local} \\ 0 \\ 1 \end{bmatrix}" width="276">
248+
</div>
249+
197250
Note: Transformations do affect the visual rendering, but have no affect on the CSS layout other than affecting overflow. Transforms are also taken into account when computing client rectangles exposed via the Element Interface Extensions, namely <a href="https://www.w3.org/TR/cssom-view/#dom-element-getclientrects">getClientRects()</a> and <a href="https://www.w3.org/TR/cssom-view/#dom-element-getboundingclientrect">getBoundingClientRect()</a>, which are specified in [[CSSOM-VIEW]].
198251

199252
<div class="example">
@@ -952,28 +1005,28 @@ Some transform functions can be represented by more generic transform functions.
9521005
The Transform Function Lists {#transform-function-lists}
9531006
========================================================
9541007

955-
If a list of <<transform-function>> is provided, then the net effect is as if each transform function had been specified separately in the order provided. For example,
1008+
If a list of <<transform-function>>s is provided, then the net effect is as if each transform function had been specified separately in the order provided.
1009+
1010+
That is, in the absence of other styling that affects position and dimensions, a nested set of transforms is equivalent to a single list of transform functions, applied from the coordinate system of the ancestor to the [=local coordinate system=] of a given element. The resulting transform is the matrix multiplication of the list of transforms.
1011+
1012+
<div class=example>
1013+
For example,
9561014

9571015
<pre><code highlight=html>
958-
&lt;div style="transform: translate(-10px,-20px) scale(2) rotate(45deg) translate(5px,10px)"/>
1016+
&lt;div style="transform: translate(-10px, -20px) scale(2) rotate(45deg)"/>
9591017
</code></pre>
9601018

9611019
is functionally equivalent to:
9621020

9631021
<pre><code highlight=html>
964-
&lt;div style="transform: translate(-10px,-20px)" id="root">
1022+
&lt;div style="transform: translate(-10px, -20px)" id="root">
9651023
&lt;div style="transform: scale(2)">
9661024
&lt;div style="transform: rotate(45deg)">
967-
&lt;div style="transform: translate(5px,10px)" id="child">
968-
&lt;/div>
9691025
&lt;/div>
9701026
&lt;/div>
9711027
&lt;/div>
9721028
</code></pre>
973-
974-
That is, in the absence of other styling that affects position and dimensions, a nested set of transforms is equivalent to a single list of transform functions, applied from the top ancestor (with the id <code>root</code>) to the deepest descendant (with the id <code>child</code>). The resulting transform is the matrix multiplication of the list of transforms.
975-
976-
Issue(w3c/csswg-drafts#909): Backport point mapping from one coordinate space to another from SVG.
1029+
</div>
9771030

9781031
If a transform function causes the [=current transformation matrix=] of an object to be non-invertible, the object and its content do not get displayed.
9791032

@@ -1414,6 +1467,7 @@ The following changes were made since the <a href="https://www.w3.org/TR/2017/WD
14141467
* No 'transform' on non-replaced inline boxes, table-column boxes, and table-column-group boxes.
14151468
* Define target coordinate space for transformations on <{pattern}>, <{linearGradient}>, <{radialGradient}> and <{clipPath}> elements.
14161469
* Remove 3-value <<rotate()>> from transform function primitives.
1470+
* Be more specific about computation of [=transformation matrix=] and [=current transformation matrix=].
14171471
* Editorial changes.
14181472

14191473
<h2 class=no-num id='acknowledgments'>Acknowledgments</h2>
6.47 KB
Loading

css-transforms-1/images/ctm.png

11.7 KB
Loading

css-transforms-1/images/tm-map.png

5.68 KB
Loading

css-transforms-1/images/tm.png

11.3 KB
Loading

0 commit comments

Comments
 (0)