Documentation
¶
Overview ¶
Package transform parses CSS transform strings (translate, scale, rotate, skew, matrix) and composes them into a single 2D affine matrix expressed in PDF operand order [A B C D E F]. The renderer emits that matrix directly as a PDF `cm` operator to position and orient content.
Matrix convention. A Matrix maps a point (x, y) to (x', y') as
x' = A*x + C*y + E y' = B*x + D*y + F
which is exactly the PDF `cm` operator's meaning. In 3x3 homogeneous form with row vectors [x y 1]:
[x' y' 1] = [x y 1] * | A B 0 |
| C D 0 |
| E F 1 |
Coordinate space. waffle's layout space is y-DOWN (origin top-left, like CSS and the screen). All matrices here operate in that y-down space; the renderer applies them BEFORE its own y-flip into PDF's y-up page space. Rotate is defined so a positive angle rotates CLOCKWISE as seen on screen, matching the visual result of CSS `rotate()`. See Rotate for the exact formula.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ParseAngle ¶
ParseAngle parses a CSS angle token and returns the angle in radians. It accepts the units deg, grad, rad, and turn; a bare number is interpreted as degrees. It is the shared angle helper used by rotate and skew parsing.
Types ¶
type Matrix ¶
type Matrix struct{ A, B, C, D, E, F float64 }
Matrix is a 2D affine transform stored in PDF operand order: [A B C D E F]. The zero value is NOT the identity; use Identity.
func Identity ¶
func Identity() Matrix
Identity returns the identity transform (maps every point to itself).
func Parse ¶
Parse parses a CSS transform string such as
"rotate(45deg) translate(10, 5px) scale(1.5)"
into a single composed matrix. Functions are read left to right and composed so the composed matrix is M = f1 ∘ f2 ∘ ... : the FIRST (leftmost) function is the outermost and is applied to points LAST, matching CSS. Equivalently, the last function listed transforms the point first.
Supported functions: translate/translateX/translateY, scale/scaleX/scaleY, rotate, skew/skewX/skewY, and matrix(a,b,c,d,e,f). Function names are matched case-insensitively. Lengths accept px, pt, or a bare number, all treated as PDF points (at waffle's default 72 dpi, 1px == 1pt); percentages are NOT supported and produce an error. Angles accept deg (the default for a bare number), rad, grad, and turn.
Parse returns Identity for the empty string. Unknown or unsupported functions (e.g. translate3d, perspective) are ignored. Malformed input — a bad number, a wrong argument count for a known function, a percentage length, or broken syntax such as an unclosed parenthesis — returns (Identity, error). Parse never panics.
func Rotate ¶
Rotate returns a rotation by deg degrees. In waffle's y-down space a positive angle rotates CLOCKWISE as seen on screen, matching CSS `rotate()`. The matrix uses the standard trigonometric form
A = cos θ B = sin θ C = -sin θ D = cos θ
(θ = deg in radians); it appears clockwise because y increases downward. For example Rotate(90) maps (1,0) -> (0,1), i.e. the +x axis turns toward +y (down on screen).
func Skew ¶
Skew returns a skew by ax degrees along x and ay degrees along y, matching CSS `skew(ax, ay)` == matrix(1, tan(ay), tan(ax), 1, 0, 0).
func (Matrix) AboutOrigin ¶
AboutOrigin returns m applied about the point (ox, oy) instead of about the coordinate origin, i.e. translate(ox,oy) ∘ m ∘ translate(-ox,-oy). This is what a renderer uses to honor CSS transform-origin: wrap an element's own transform M as element.AboutOrigin(originX, originY).