SVGTransform - Web APIs 编辑

SVG transform interface

SVGTransform is the interface for one of the component transformations within an SVGTransformList; thus, an SVGTransform object corresponds to a single component (e.g., scale(…) or matrix(…)) within a transform attribute.

An SVGTransform object can be designated as read only, which means that attempts to modify the object will result in an exception being thrown.

Interface overview

Also implementNone
Methods
  • void setMatrix(in SVGMatrix matrix)
  • void setTranslate(in float tx, in float ty)
  • void setScale(in float sx, in float sy)
  • void setRotate(in float angle, in float cx, in float cy)
  • void setSkewX(in float angle)
  • void setSkewY(in float angle)
Properties
  • readonly unsigned short type
  • readonly float angle
  • readonly SVGMatrix matrix
Constants
  • SVG_TRANSFORM_UNKNOWN = 0
  • SVG_TRANSFORM_MATRIX = 1
  • SVG_TRANSFORM_TRANSLATE = 2
  • SVG_TRANSFORM_SCALE = 3
  • SVG_TRANSFORM_ROTATE = 4
  • SVG_TRANSFORM_SKEWX = 5
  • SVG_TRANSFORM_SKEWY = 6
Normative documentSVG 1.1 (2nd Edition)

Constants

NameValueDescription
SVG_TRANSFORM_UNKNOWN0The unit type is not one of predefined unit types. It is invalid to attempt to define a new value of this type or to attempt to switch an existing value to this type.
SVG_TRANSFORM_MATRIX1A matrix(…) transformation
SVG_TRANSFORM_TRANSLATE2A translate(…) transformation
SVG_TRANSFORM_SCALE3A scale(…) transformation
SVG_TRANSFORM_ROTATE4A rotate(…) transformation
SVG_TRANSFORM_SKEWX5A skewx(…) transformation
SVG_TRANSFORM_SKEWY6A skewy(…) transformation

Properties

NameTypeDescription
typeunsigned shortThe type of the value as specified by one of the SVG_TRANSFORM_* constants defined on this interface.
anglefloatA convenience attribute for SVG_TRANSFORM_ROTATE, SVG_TRANSFORM_SKEWX and SVG_TRANSFORM_SKEWY. It holds the angle that was specified.

For SVG_TRANSFORM_MATRIX, SVG_TRANSFORM_TRANSLATE and SVG_TRANSFORM_SCALE, angle will be zero.
matrixSVGMatrix

The matrix that represents this transformation. The matrix object is live, meaning that any changes made to the SVGTransform object are immediately reflected in the matrix object and vice versa. In case the matrix object is changed directly (i.e., without using the methods on the SVGTransform interface itself) then the type of the SVGTransform changes to SVG_TRANSFORM_MATRIX.

  • For SVG_TRANSFORM_MATRIX, the matrix contains the a, b, c, d, e, f values supplied by the user.
  • For SVG_TRANSFORM_TRANSLATE, e and f represent the translation amounts (a=1, b=0, c=0 and d=1).
  • For SVG_TRANSFORM_SCALE, a and d represent the scale amounts (b=0, c=0, e=0 and f=0).
  • For SVG_TRANSFORM_SKEWX and SVG_TRANSFORM_SKEWY, a, b, c and d represent the matrix which will result in the given skew (e=0 and f=0).
  • For SVG_TRANSFORM_ROTATE, a, b, c, d, e and f together represent the matrix which will result in the given rotation. When the rotation is around the center point (0, 0), e and f will be zero.

Methods

Name & ArgumentsReturnDescription
setMatrix(in SVGMatrix matrix)void

Sets the transform type to SVG_TRANSFORM_MATRIX, with parameter matrix defining the new transformation. Note that the values from the parameter matrix are copied.

Exceptions:

  • a DOMException with code NO_MODIFICATION_ALLOWED_ERR is raised when attempting to modify a read only attribute or when the object itself is read only.
setTranslate(in float tx , in float ty)void

Sets the transform type to SVG_TRANSFORM_TRANSLATE, with parameters tx and ty defining the translation amounts.

Exceptions:

  • a DOMException with code NO_MODIFICATION_ALLOWED_ERR is raised when attempting to modify a read only attribute or when the object itself is read only.
setScale(in float sx , in float sy)void

Sets the transform type to SVG_TRANSFORM_SCALE, with parameters sx and sy defining the scale amounts.

Exceptions:

  • a DOMException with code NO_MODIFICATION_ALLOWED_ERR is raised when attempting to modify a read only attribute or when the object itself is read only.
setRotate(in float angle, in float cx , in float cy)void

Sets the transform type to SVG_TRANSFORM_ROTATE, with parameter angle defining the rotation angle and parameters cx and cy defining the optional center of rotation.

Exceptions:

  • a DOMException with code NO_MODIFICATION_ALLOWED_ERR is raised when attempting to modify a read only attribute or when the object itself is read only.
setSkewX(in float angle)void

Sets the transform type to SVG_TRANSFORM_SKEWX, with parameter angle defining the amount of skew.

Exceptions:

  • a DOMException with code NO_MODIFICATION_ALLOWED_ERR is raised when attempting to modify a read only attribute or when the object itself is read only.
setSkewY(in float angle)void

Sets the transform type to SVG_TRANSFORM_SKEWY, with parameter angle defining the amount of skew.

Exceptions:

  • a DOMException with code NO_MODIFICATION_ALLOWED_ERR is raised when attempting to modify a read only attribute or when the object itself is read only.

Browser compatibility

BCD tables only load in the browser

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:57 次

字数:10144

最后编辑:7年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文