Copyright © 2014 W3C® (MIT, ERCIM, Keio, Beihang), All Rights Reserved. W3C liability, trademark and document use rules apply.
This specification provides basic geometric interfaces to represent points, rectangles, quadrilaterals and transformation matrices that can be used by other modules or specifications. CSS is a language for describing the rendering of structured documents (such as HTML and XML) on screen, on paper, in speech, etc.
This section describes the status of this document at the time of its publication. Other documents may supersede this document. A list of current W3C publications and the latest revision of this technical report can be found in the W3C technical reports index at http://www.w3.org/TR/.
Publication as a Last Call Working Draft does not imply endorsement by the W3C Membership. This is a draft document and may be updated, replaced or obsoleted by other documents at any time. It is inappropriate to cite this document as other than work in progress.
The (archived) public mailing list public-fx@w3.org (see instructions) is preferred for discussion of this specification. When sending e-mail, please put the text “geometry” in the subject, preferably like this: “[geometry] …summary of comment…”
This document was produced by the CSS Working Group (part of the Style Activity) and the SVG Working Group (part of the Graphics Activity).
This document was produced by groups operating under the 5 February 2004 W3C Patent Policy. W3C maintains a public list of any patent disclosures (CSS) and a public list of any patent disclosures (SVG) made in connection with the deliverables of each group; these pages also includes instructions for disclosing a patent. An individual who has actual knowledge of a patent which the individual believes contains Essential Claim(s) must disclose the information in accordance with section 6 of the W3C Patent Policy.
This specification is a Last Call Working Draft. All persons are encouraged to review this document and send comments to the public-fx mailing list as described above. The deadline for comments is 7 August 2014.
This specification describes several geometry interfaces [WEBIDL] for the representation of points, rectangles, quadrilaterals and transformation matrices with the dimension of 3x2 and 4x4.
The SVG interfaces SVGPoint, SVGRect and SVGMatrix [SVG11] are aliasing the here defined interfaces in favor for common interfaces used by SVG, Canvas 2D Context [2DCONTEXT] and CSS Transforms [CSS3-TRANSFORMS].
A 2D point or a 3D point can be represented by the following WebIDL interfaces:
interface DOMPointReadOnly { readonly attribute unrestricted double x; readonly attribute unrestricted double y; readonly attribute unrestricted double z; readonly attribute unrestricted double w; DOMPoint matrixTransform(DOMMatrixReadOnly matrix); }; [Constructor(optional DOMPointInit point), Constructor(unrestricted double x, unrestricted double y, optional unrestricted double z = 0, optional unrestricted double w = 1)] interface DOMPoint : DOMPointReadOnly { inherit attribute unrestricted double x; inherit attribute unrestricted double y; inherit attribute unrestricted double z; inherit attribute unrestricted double w; }; dictionary DOMPointInit { unrestricted double x = 0; unrestricted double y = 0; unrestricted double z = 0; unrestricted double w = 1; };
The DOMPoint()
constructor, when invoked, must run the following steps:
If invoked with one argument, follow these substeps:
Let point be the argument.
Let x be the x
dictionary member of point.
Let y be the y
dictionary member of point.
Let z be the z
dictionary member of point.
Let w be the w
dictionary member of point.
Otherwise, let x, y, z and w be the given arguments, respectively.
Return a new DOMPoint object with the x, y, z and w attributes set to x, y, z and w, respectively.
The y attribute gives the y coordinate of the point. On getting, it must return the current value. On setting, it must set the current value to the new value.
The z attribute gives the z coordinate of the point. On getting, it must return the current value. On setting, it must set the current value to the new value.
The w attribute gives the perspective of the point. On getting, it must return the current value. On setting, it must set the current value to the new value.
The following method does not modify the current DOMPointReadOnly object and returns a new DOMPoint object.
In this example the method matrixTransform() on point is called with a the DOMMatrix argument matrix.
var point = new DOMPoint(5, 4);
var matrix = new DOMMarix(2, 0, 0, 2, 10, 10);
var transformedPoint = point.matrixTransform(matrix);
point creates a new DOMPoint object initialized to the same attribute values as point. This new DOMPoint is now scaled and the translated by matrix. This resulting transformPoint has the attribute values x: 20
and y: 18
.
For historical reasons, Window objects must also have a writable, configurable, non-enumerable property named SVGPoint
whose value is the DOMPoint interface object.
Objects implementing the DOMRectReadOnly interface represent a rectangle. The type of box is specified by the method or attribute that returns a DOMRect or DOMRectReadOnly object.
Rectangles have the following properties:
[Constructor, Constructor(unrestricted double x, unrestricted double y, unrestricted double width, unrestricted double height)] interface DOMRect : DOMRectReadOnly { inherit attribute unrestricted double x; inherit attribute unrestricted double y; inherit attribute unrestricted double width; inherit attribute unrestricted double height; }; interface DOMRectReadOnly { readonly attribute unrestricted double x; readonly attribute unrestricted double y; readonly attribute unrestricted double width; readonly attribute unrestricted double height; readonly attribute unrestricted double top; readonly attribute unrestricted double right; readonly attribute unrestricted double bottom; readonly attribute unrestricted double left; };
The DOMRect(x, y, width, height)
constructor, when
invoked, must run the following steps:
If invoked with no arguments, let x, y, width and height be zero.
Return a new DOMRect object with x coordinate set to x, y coordinate set to y, width set to width and height set to height.
The y attribute, on getting, it must return the y coordinate. The y attribute, on setting, must set the y coordinate to the new value.
The width attribute, on getting, must return the width. The width attribute, on setting, must set the width to the new value.
The height attribute, on getting, must return the height. The height attribute, on setting, must set the height to the new value.
The top attribute, on getting, must return min(y coordinate, y coordinate + height).
The right attribute, on getting, must return max(x coordinate, x coordinate + width).
The bottom attribute, on getting, must return max(y coordinate, y coordinate + height).
The left attribute, on getting, must return min(x coordinate, x coordinate + width).
For historical reasons, Window objects must also have a writable, configurable, non-enumerable property named SVGRect
whose value is the DOMRect interface object.
interface DOMRectList { readonly attribute unsigned long length; getter DOMRect item(unsigned long index); };
The length attribute must return the total number of DOMRect objects associated with the object.
The item(index) method, when invoked, must throw an IndexSizeError exception when index is greater than the number of DOMRect objects associated with the object. Otherwise, the DOMRect object at index must be returned.
Objects implementing the DOMQuad interface represents a quadrilateral.
[Constructor(optional DOMPointInit p1, optional DOMPointInit p2, optional DOMPointInit p3, optional DOMPointInit p4), Constructor(DOMRectReadOnly rect)] interface DOMQuad { [SameObject] readonly attribute DOMPoint p1; [SameObject] readonly attribute DOMPoint p2; [SameObject] readonly attribute DOMPoint p3; [SameObject] readonly attribute DOMPoint p4; [SameObject] readonly attribute DOMRectReadOnly bounds; };
The DOMQuad()
constructor, when invoked, must run the following steps:
If invoked with one argument, follow these substeps:
Otherwise, follow these substeps:
Return a new DOMQuad with p1 set to point 1, p2 set to point 2, p3 set to point 3 and p4 set to point 4, and let the associated bounding rectangle be bounds.
Note that it is possible to pass DOMPoint/DOMPointReadOnly arguments as well. The passed arguments will be transformed to the correct object type internally following the WebIDL rules [WEBIDL].
The p2 attribute must return a DOMPoint that represents p2 of the quadrilateral. The author can modify the returned DOMPoint object, which has direct affect on the quadrilateral.
The p3 attribute must return a DOMPoint that represents p3 of the quadrilateral. The author can modify the returned DOMPoint object, which has direct affect on the quadrilateral.
The p4 attribute must return a DOMPoint that represents p4 of the quadrilateral. The author can modify the returned DOMPoint object, which has direct affect on the quadrilateral.
The bounds attribute must return the associated bounding rectangle.
DOMQuad objects have an associated bounding rectangle set to a DOMRectReadOnly object when created. The associated bounding rectangle is live; whenever the objects in p1, p2, p3 or p4 are changed, the associated bounding rectangle must update its attributes as appropriate to describe the new smallest bounding box of the four points.
The associated bounding rectangle is computed as follows:
In this example the DOMQuad constructor is called with arguments of type DOMPoint and DOMPointInit. Both arguments are accepted and can be used.
var point = new DOMPoint(2, 0);
var quad1 = new DOMQuad(point, {x: 12, y: 0}, {x: 2, y: 10}, {x: 12, 10});
The attribute values of the resulting DOMQuad quad1 above are also equal to the attribute values of the following DOMQuad quad2:
var rect = new DOMRect(2, 0, 10, 10);
var quad2 = new DOMQuad(rect);
This is an example of an irregular quadrilateral:
new DOMQuad({x: 40, y: 25}, {x: 180, y: 8}, {x: 210, y: 150}, {x: 10, y: 180});
The DOMMatrix and DOMMatrixReadOnly interfaces represent a mathematical matrix with the purpose of describing transformations in a graphical context. The following sections describe the details of the interface.
The DOMMatrix and DOMMatrixReadOnly interfaces replace the SVGMatrix interface from SVG [SVG11].
For legacy reasons, if the user agent supports SVG, Window objects must have a writable, configurable, non-enumerable property named SVGMatrix whose value is the DOMMatrix interface object. [SVG11]
A 4x4 matrix representing a DOMMatrix with items m11 to m44.
In the following sections, terms have the following meaning:
interface DOMMatrixReadOnly { // These attributes are simple aliases for certain elements of the 4x4 matrix readonly attribute unrestricted double a; readonly attribute unrestricted double b; readonly attribute unrestricted double c; readonly attribute unrestricted double d; readonly attribute unrestricted double e; readonly attribute unrestricted double f; readonly attribute unrestricted double m11; readonly attribute unrestricted double m12; readonly attribute unrestricted double m13; readonly attribute unrestricted double m14; readonly attribute unrestricted double m21; readonly attribute unrestricted double m22; readonly attribute unrestricted double m23; readonly attribute unrestricted double m24; readonly attribute unrestricted double m31; readonly attribute unrestricted double m32; readonly attribute unrestricted double m33; readonly attribute unrestricted double m34; readonly attribute unrestricted double m41; readonly attribute unrestricted double m42; readonly attribute unrestricted double m43; readonly attribute unrestricted double m44; readonly attribute boolean is2D; readonly attribute boolean isIdentity; // Immutable transform methods DOMMatrix translate(unrestricted double tx, unrestricted double ty, optional unrestricted double tz = 0); DOMMatrix scale(unrestricted double scale, optional unrestricted double originX = 0, optional unrestricted double originY = 0); DOMMatrix scale3d(unrestricted double scale, optional unrestricted double originX = 0, optional unrestricted double originY = 0, optional unrestricted double originZ = 0); DOMMatrix scaleNonUniform(unrestricted double scaleX, optional unrestricted double scaleY = 1, optional unrestricted double scaleZ = 1, optional unrestricted double originX = 0, optional unrestricted double originY = 0, optional unrestricted double originZ = 0); DOMMatrix rotate(unrestricted double angle, optional unrestricted double originX = 0, optional unrestricted double originY = 0); DOMMatrix rotateFromVector(unrestricted double x, unrestricted double y); DOMMatrix rotateAxisAngle(unrestricted double x, unrestricted double y, unrestricted double z, unrestricted double angle); DOMMatrix skewX(unrestricted double sx); DOMMatrix skewY(unrestricted double sy); DOMMatrix multiply(DOMMatrix other); DOMMatrix flipX(); DOMMatrix flipY(); DOMMatrix inverse(); DOMPoint transformPoint(optional DOMPointInit point); Float32Array toFloat32Array(); Float64Array toFloat64Array(); stringifier; }; [Constructor, Constructor(DOMString transformList), Constructor(DOMMatrixReadOnly other), Constructor(Float32Array array32), Constructor(Float64Array array64), Constructor(sequence<unrestricted double> numberSequence)] interface DOMMatrix : DOMMatrixReadOnly { // These attributes are simple aliases for certain elements of the 4x4 matrix inherit attribute unrestricted double a; inherit attribute unrestricted double b; inherit attribute unrestricted double c; inherit attribute unrestricted double d; inherit attribute unrestricted double e; inherit attribute unrestricted double f; inherit attribute unrestricted double m11; inherit attribute unrestricted double m12; inherit attribute unrestricted double m13; inherit attribute unrestricted double m14; inherit attribute unrestricted double m21; inherit attribute unrestricted double m22; inherit attribute unrestricted double m23; inherit attribute unrestricted double m24; inherit attribute unrestricted double m31; inherit attribute unrestricted double m32; inherit attribute unrestricted double m33; inherit attribute unrestricted double m34; inherit attribute unrestricted double m41; inherit attribute unrestricted double m42; inherit attribute unrestricted double m43; inherit attribute unrestricted double m44; // Mutable transform methods DOMMatrix multiplySelf(DOMMatrix other); DOMMatrix preMultiplySelf(DOMMatrix other); DOMMatrix translateSelf(unrestricted double tx, unrestricted double ty, optional unrestricted double tz = 0); DOMMatrix scaleSelf(unrestricted double scale, optional unrestricted double originX = 0, optional unrestricted double originY = 0); DOMMatrix scale3dSelf(unrestricted double scale, optional unrestricted double originX = 0, optional unrestricted double originY = 0, optional unrestricted double originZ = 0); DOMMatrix scaleNonUniformSelf(unrestricted double scaleX, optional unrestricted double scaleY = 1, optional unrestricted double scaleZ = 1, optional unrestricted double originX = 0, optional unrestricted double originY = 0, optional unrestricted double originZ = 0); DOMMatrix rotateSelf(unrestricted double angle, optional unrestricted double originX = 0, optional unrestricted double originY = 0); DOMMatrix rotateFromVectorSelf(unrestricted double x, unrestricted double y); DOMMatrix rotateAxisAngleSelf(unrestricted double x, unrestricted double y, unrestricted double z, unrestricted double angle); DOMMatrix skewXSelf(unrestricted double sx); DOMMatrix skewYSelf(unrestricted double sy); DOMMatrix invertSelf(); DOMMatrix setMatrixValue(DOMString transformList); };
For historical reasons, Window objects must also have a writable, configurable, non-enumerable property named SVGMatrix
whose value is the DOMMatrix interface object.
The DOMMatrix()
constructor, when invoked, must run the following steps:
The following attributes m11 to m44 correspond to the 16 items of the matrix interfaces. If the attributes m31, m32, m13, m23, m43, m14, m24, m34 are set to something else than 0 or m33, m44 are set to something else than 1 set is2D to false.
The following attributes a to b correspond to the 2D components of the matrix interfaces.
The following attribute provide status information about DOMMatrixReadOnly.
Every DOMMatrixReadOnly object must be flagged with a boolean is2D. This flag indicates that
is2D can never be set to true when it was set to false before on a DOMMatrix object with the exception of calling the setMatrixValue() method.
Returns the value of is2D.
The following methods do not modify the current matrix and return a new DOMMatrix object.
The current matrix is not modified.
The current matrix is not modified.
The current matrix is not modified.
The current matrix is not modified.
The current matrix is not modified.
The current matrix is not modified.
The current matrix is not modified.
The current matrix is not modified.
The current matrix is not modified.
The current matrix is not modified.
DOMMatrix(-1, 0, 0, 1, 0, 0)
.The current matrix is not modified.
DOMMatrix(1, 0, 0, -1, 0, 0)
.The current matrix is not modified.
The current matrix is not modified.
The following methods do not modify the current matrix.
Note: Even though is2D of the current matrix may return true, a 4x4 matrix mutliplication must be performed if the z attribute of point is not 0 or the w attribute of point is not 1.
In this example a matrix is created and several methods with 2D transformations are called.
var matrix = new DOMMatrix();
matrix.scaleSelf(2);
matrix.translateSelf(20,20);
Calling matrix.toString()
returns the DOMString:
"matrix(2, 0, 0, 2, 20, 20)"
For 3D operations, the stringifier returns a DOMString representing a 3D matrix.
var matrix = new DOMMatrix();
matrix.scale3dSelf(2);
Calling matrix.toString()
after the snippet above returns the DOMString:
"matrix3d(2, 0, 0, 0, 0, 2, 0, 0, 0, 0, 2, 0, 0, 0, 0, 1)"
The following methods do modify the current matrix. Each method returns the current matrix the method was called on. This allows authors to chain method calls.
The following code example
var matrix = new DOMMatrix();
matrix.translateSelf(20, 20);
matrix.scaleSelf(2);
matrix.translateSelf(-20, -20);
is equivalent to
var matrix = new DOMMatrix();
matrix.translateSelf(20, 20).scaleSelf(2).translateSelf(-20, -20);
Note: Authors who use chained method calls are recommended to use mutable transformation methods to avoid unnecessary memory allocations due to intermediate DOMMatrix creations in User Agents.
alpha
is the angle between the vector (1,0)T and (x,y)T in degrees [CSS3-TRANSFORMS].The following changes were made since the 22 May 2014 First Public Working Draft.
The editors would like to thank Robert O’Callahan for contributing to this specification. Many thanks to Dean Jackson for his initial proposal of DOMMatrix. Thanks to Brian Birtles, Benoit Jacob, Cameron McCormack, Kari Pihkala and Boris Zbarsky for their careful reviews, comments, and corrections.
Conformance requirements are expressed with a combination of descriptive assertions and RFC 2119 terminology. The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in the normative parts of this document are to be interpreted as described in RFC 2119. However, for readability, these words do not appear in all uppercase letters in this specification.
All of the text of this specification is normative except sections explicitly marked as non-normative, examples, and notes. [RFC2119]
Examples in this specification are introduced with the words "for example"
or are set apart from the normative text with class="example"
,
like this:
This is an example of an informative example.
Informative notes begin with the word "Note" and are set apart from the
normative text with class="note"
, like this:
Note, this is an informative note.
Conformance to this specification is defined for three conformance classes:
A style sheet is conformant to this specification if all of its statements that use syntax defined in this module are valid according to the generic CSS grammar and the individual grammars of each feature defined in this module.
A renderer is conformant to this specification if, in addition to interpreting the style sheet as defined by the appropriate specifications, it supports all the features defined by this specification by parsing them correctly and rendering the document accordingly. However, the inability of a UA to correctly render a document due to limitations of the device does not make the UA non-conformant. (For example, a UA is not required to render color on a monochrome monitor.)
An authoring tool is conformant to this specification if it writes style sheets that are syntactically correct according to the generic CSS grammar and the individual grammars of each feature in this module, and meet all other conformance requirements of style sheets as described in this module.
So that authors can exploit the forward-compatible parsing rules to assign fallback values, CSS renderers must treat as invalid (and ignore as appropriate) any at-rules, properties, property values, keywords, and other syntactic constructs for which they have no usable level of support. In particular, user agents must not selectively ignore unsupported component values and honor supported values in a single multi-value property declaration: if any value is considered invalid (as unsupported values must be), CSS requires that the entire declaration be ignored.
To avoid clashes with future CSS features, the CSS2.1 specification reserves a prefixed syntax for proprietary and experimental extensions to CSS.
Prior to a specification reaching the Candidate Recommendation stage in the W3C process, all implementations of a CSS feature are considered experimental. The CSS Working Group recommends that implementations use a vendor-prefixed syntax for such features, including those in W3C Working Drafts. This avoids incompatibilities with future changes in the draft.
Once a specification reaches the Candidate Recommendation stage, non-experimental implementations are possible, and implementors should release an unprefixed implementation of any CR-level feature they can demonstrate to be correctly implemented according to spec.
To establish and maintain the interoperability of CSS across implementations, the CSS Working Group requests that non-experimental CSS renderers submit an implementation report (and, if necessary, the testcases used for that implementation report) to the W3C before releasing an unprefixed implementation of any CSS features. Testcases submitted to W3C are subject to review and correction by the CSS Working Group.
Further information on submitting testcases and implementation reports can be found from on the CSS Working Group’s website at http://www.w3.org/Style/CSS/Test/. Questions should be directed to the public-css-testsuite@w3.org mailing list.
No properties defined.