Struct GlyphTransform
A glyph's placement in a transformed GlyphRun: a rotation and uniform scale, then its origin, as Skia's RSXform. A point (x, y) of the glyph, y down, goes to (ScaleCos x - ScaleSin y + Tx, ScaleSin x + ScaleCos y + Ty).
public readonly record struct GlyphTransform : IEquatable<GlyphTransform>
- Implements
- Inherited Members
Examples
// A label along a curve: each glyph's midpoint on the path, turned to its direction, as SVG's textPath. The result is
// still a glyph run, so a PDF backend writes it as searchable text.
Path curve = new PathBuilder().MoveTo(20, 150).CubicTo(80, 20, 240, 20, 300, 150).ToPath();
var font = new Font(face, 18);
using (RasterCanvas<Rgba8> canvas = image.CreateCanvas())
{
canvas.DrawTextOnPath("Text that follows the curve", curve, font, Rgba8.Black,
new TextOnPathOptions { StartFraction = 0.5f, Anchor = TextAnchor.Center, BaselineShift = 4 });
}
// Or place glyphs yourself, each with its own turn and scale.
GlyphRun dial = GlyphRun.CreateTransformed(font, [face.GetGlyph('N'), face.GetGlyph('E')],
[GlyphTransform.FromRotationScale(1, 0, new Vector2(150, 30)), GlyphTransform.FromRotationScale(1, 90, new Vector2(290, 90))]);
Constructors
GlyphTransform(float, float, float, float)
A glyph's placement in a transformed GlyphRun: a rotation and uniform scale, then its origin, as Skia's RSXform. A point (x, y) of the glyph, y down, goes to (ScaleCos x - ScaleSin y + Tx, ScaleSin x + ScaleCos y + Ty).
public GlyphTransform(float ScaleCos, float ScaleSin, float Tx, float Ty)
Parameters
ScaleCosfloatThe scale times the cosine of the turn; 1 for an upright glyph at the font's size.
ScaleSinfloatThe scale times the sine of the turn (clockwise on a y-down canvas); 0 for an upright glyph.
TxfloatThe glyph origin's x, relative to the run's origin.
TyfloatThe glyph origin's y, relative to the run's origin, y down.
Examples
// A label along a curve: each glyph's midpoint on the path, turned to its direction, as SVG's textPath. The result is
// still a glyph run, so a PDF backend writes it as searchable text.
Path curve = new PathBuilder().MoveTo(20, 150).CubicTo(80, 20, 240, 20, 300, 150).ToPath();
var font = new Font(face, 18);
using (RasterCanvas<Rgba8> canvas = image.CreateCanvas())
{
canvas.DrawTextOnPath("Text that follows the curve", curve, font, Rgba8.Black,
new TextOnPathOptions { StartFraction = 0.5f, Anchor = TextAnchor.Center, BaselineShift = 4 });
}
// Or place glyphs yourself, each with its own turn and scale.
GlyphRun dial = GlyphRun.CreateTransformed(font, [face.GetGlyph('N'), face.GetGlyph('E')],
[GlyphTransform.FromRotationScale(1, 0, new Vector2(150, 30)), GlyphTransform.FromRotationScale(1, 90, new Vector2(290, 90))]);
Properties
IsTranslation
Gets whether the glyph is only moved, not turned or scaled.
public bool IsTranslation { get; }
Property Value
ScaleCos
The scale times the cosine of the turn; 1 for an upright glyph at the font's size.
public float ScaleCos { get; init; }
Property Value
ScaleSin
The scale times the sine of the turn (clockwise on a y-down canvas); 0 for an upright glyph.
public float ScaleSin { get; init; }
Property Value
Tx
The glyph origin's x, relative to the run's origin.
public float Tx { get; init; }
Property Value
Ty
The glyph origin's y, relative to the run's origin, y down.
public float Ty { get; init; }
Property Value
Methods
FromRotationScale(float, float, Vector2)
Creates a placement that scales and turns a glyph about its origin and puts the origin at a position.
public static GlyphTransform FromRotationScale(float scale, float degrees, Vector2 origin)
Parameters
scalefloatThe scale; 1 for the font's size.
degreesfloatThe clockwise turn on a y-down canvas.
originVector2Where the glyph's origin goes, relative to the run's origin.
Returns
- GlyphTransform
The placement.
ToMatrix()
Returns the transform as a matrix from the glyph's y-down coordinates to the run's.
public Matrix3x2 ToMatrix()
Returns
- Matrix3x2
The matrix.