Table of Contents

Struct TextMeasure

Namespace
Egami.Fonts
Assembly
Egami.Fonts.dll

The size of text as MeasureText(string, ShapingOptions?) lays it out, in canvas units.

public readonly record struct TextMeasure : IEquatable<TextMeasure>
Implements
Inherited Members

Examples

// A label shrunk until it fits a 200-pixel button, then centred on it.
const string label = "Download the full report";
var box = new RectF(20, 20, 200, 40);
var font = new Font(face, 24);
while (font.MeasureText(label).Advance > box.Width - 16 && font.Size > 8)
{
    font = new Font(face, font.Size - 1);
}

TextMeasure size = font.MeasureText(label);
var origin = new Vector2(
    box.X + ((box.Width - size.Advance) / 2),
    box.Y + ((box.Height - size.Height) / 2) + size.Ascent);
using Raster<Rgba8> image = Raster.Create(240, 80, Rgba8.White);
using (RasterCanvas<Rgba8> canvas = image.CreateCanvas())
{
    canvas.FillRoundRect(new RoundRect(box, 8), new Rgba8(30, 90, 200, 255));
    canvas.DrawText(label, origin, font, Rgba8.White);
}

Constructors

TextMeasure(float, TextBounds, int, float, float, float)

The size of text as MeasureText(string, ShapingOptions?) lays it out, in canvas units.

public TextMeasure(float Advance, TextBounds InkBounds, int LineCount, float Ascent, float Descent, float LineHeight)

Parameters

Advance float

The widest line's advance: where the pen ends on that line.

InkBounds TextBounds

The exact box around the ink, relative to the first baseline's left end, y down.

LineCount int

The number of lines.

Ascent float

The font's ascent, positive.

Descent float

The font's descent, negative.

LineHeight float

The distance from one baseline to the next.

Examples

// A label shrunk until it fits a 200-pixel button, then centred on it.
const string label = "Download the full report";
var box = new RectF(20, 20, 200, 40);
var font = new Font(face, 24);
while (font.MeasureText(label).Advance > box.Width - 16 && font.Size > 8)
{
    font = new Font(face, font.Size - 1);
}

TextMeasure size = font.MeasureText(label);
var origin = new Vector2(
    box.X + ((box.Width - size.Advance) / 2),
    box.Y + ((box.Height - size.Height) / 2) + size.Ascent);
using Raster<Rgba8> image = Raster.Create(240, 80, Rgba8.White);
using (RasterCanvas<Rgba8> canvas = image.CreateCanvas())
{
    canvas.FillRoundRect(new RoundRect(box, 8), new Rgba8(30, 90, 200, 255));
    canvas.DrawText(label, origin, font, Rgba8.White);
}

Properties

Advance

The widest line's advance: where the pen ends on that line.

public float Advance { get; init; }

Property Value

float

Ascent

The font's ascent, positive.

public float Ascent { get; init; }

Property Value

float

Descent

The font's descent, negative.

public float Descent { get; init; }

Property Value

float

Height

Gets the height of the line boxes: the first line's ascent to the last line's descent.

public float Height { get; }

Property Value

float

InkBounds

The exact box around the ink, relative to the first baseline's left end, y down.

public TextBounds InkBounds { get; init; }

Property Value

TextBounds

LineCount

The number of lines.

public int LineCount { get; init; }

Property Value

int

LineHeight

The distance from one baseline to the next.

public float LineHeight { get; init; }

Property Value

float