Table of Contents

Class CssMatrixTransform

Namespace
Egami.Css
Assembly
Egami.Css.dll

matrix(a, b, c, d, e, f).

public sealed record CssMatrixTransform : CssTransformFunction, IEquatable<CssTransformFunction>, IEquatable<CssMatrixTransform>
Inheritance
CssMatrixTransform
Implements
Inherited Members

Examples

// A CSS transform list, its matrix, and the functions it holds.
bool isTransform = CssTransformList.TryParse("translate(10px, 50%) rotate(45deg) scale(2)", out CssTransformList? css);
Matrix3x2 matrix = css!.ToMatrix((length, isX) => length.Unit == CssUnit.Percent ? length.Value * (isX ? 2 : 1) : length.Value);

foreach (CssTransformFunction function in css.Functions)
{
    string kind = function switch
    {
        CssTranslateTransform t => $"translate {t.X} {t.Y}",
        CssRotateTransform r => $"rotate {r.Degrees} about ({r.CenterX}, {r.CenterY})",
        CssScaleTransform s => $"scale {s.X} {s.Y}",
        CssSkewTransform k => $"skew {k.XDegrees} {k.YDegrees}",
        CssMatrixTransform m => $"matrix {m.A} {m.B} {m.C} {m.D} {m.E} {m.F}",
        CssUnsupportedTransform u => $"{u.Name} (3D, ignored)",
        _ => "",
    };
}

bool isOrigin = CssTransformOrigin.TryParse("left bottom", out CssTransformOrigin origin); // (0%, 100%, 0)

Constructors

CssMatrixTransform(double, double, double, double, double, double)

matrix(a, b, c, d, e, f).

public CssMatrixTransform(double A, double B, double C, double D, double E, double F)

Parameters

A double

The x scale.

B double

The y skew.

C double

The x skew.

D double

The y scale.

E double

The x translation.

F double

The y translation.

Examples

// A CSS transform list, its matrix, and the functions it holds.
bool isTransform = CssTransformList.TryParse("translate(10px, 50%) rotate(45deg) scale(2)", out CssTransformList? css);
Matrix3x2 matrix = css!.ToMatrix((length, isX) => length.Unit == CssUnit.Percent ? length.Value * (isX ? 2 : 1) : length.Value);

foreach (CssTransformFunction function in css.Functions)
{
    string kind = function switch
    {
        CssTranslateTransform t => $"translate {t.X} {t.Y}",
        CssRotateTransform r => $"rotate {r.Degrees} about ({r.CenterX}, {r.CenterY})",
        CssScaleTransform s => $"scale {s.X} {s.Y}",
        CssSkewTransform k => $"skew {k.XDegrees} {k.YDegrees}",
        CssMatrixTransform m => $"matrix {m.A} {m.B} {m.C} {m.D} {m.E} {m.F}",
        CssUnsupportedTransform u => $"{u.Name} (3D, ignored)",
        _ => "",
    };
}

bool isOrigin = CssTransformOrigin.TryParse("left bottom", out CssTransformOrigin origin); // (0%, 100%, 0)

Properties

A

The x scale.

public double A { get; init; }

Property Value

double

B

The y skew.

public double B { get; init; }

Property Value

double

C

The x skew.

public double C { get; init; }

Property Value

double

D

The y scale.

public double D { get; init; }

Property Value

double

E

The x translation.

public double E { get; init; }

Property Value

double

F

The y translation.

public double F { get; init; }

Property Value

double

Methods

ToMatrix(Func<CssLength, bool, double>)

Gets the function as a matrix.

public override Matrix3x2 ToMatrix(Func<CssLength, bool, double> resolve)

Parameters

resolve Func<CssLength, bool, double>

Converts a length (possibly a percentage) to pixels; the flag is true for the x axis.

Returns

Matrix3x2

The matrix (identity for an unsupported function).