Table of Contents

Struct GlyphPosition

Namespace
Egami.Fonts.Shaping
Assembly
Egami.Fonts.dll

How a shaped glyph moves the pen and sits relative to it, in the units of the Font it was shaped with.

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

Examples

// One run, one font, as HarfBuzz's hb_shape: ligatures, kerning and marks from the font's GSUB and GPOS.
var font = new Font(face, 24);
var glyphs = new GlyphBuffer();
string text = "office";
TextShaper.ShapeRun(text, 0, text.Length, font, new RunProperties { Script = Script.Latin }, glyphs);

for (int i = 0; i < glyphs.Count; i++)
{
    ushort id = glyphs.GlyphIds[i];
    int cluster = glyphs.Clusters[i];                 // index in text the glyph came from
    GlyphPosition position = glyphs.Positions[i];     // in the font's units (pixels here)
    bool breakable = (glyphs.Flags[i] & GlyphFlags.UnsafeToBreak) == 0;
}

float width = glyphs.Advance;

Constructors

GlyphPosition(float, float, float, float)

How a shaped glyph moves the pen and sits relative to it, in the units of the Font it was shaped with.

public GlyphPosition(float XAdvance, float YAdvance, float XOffset, float YOffset)

Parameters

XAdvance float

How far the pen moves right after the glyph.

YAdvance float

How far the pen moves up after the glyph (vertical runs move down, so this is negative).

XOffset float

How far right of the pen the glyph is drawn.

YOffset float

How far above the pen the glyph is drawn.

Examples

// One run, one font, as HarfBuzz's hb_shape: ligatures, kerning and marks from the font's GSUB and GPOS.
var font = new Font(face, 24);
var glyphs = new GlyphBuffer();
string text = "office";
TextShaper.ShapeRun(text, 0, text.Length, font, new RunProperties { Script = Script.Latin }, glyphs);

for (int i = 0; i < glyphs.Count; i++)
{
    ushort id = glyphs.GlyphIds[i];
    int cluster = glyphs.Clusters[i];                 // index in text the glyph came from
    GlyphPosition position = glyphs.Positions[i];     // in the font's units (pixels here)
    bool breakable = (glyphs.Flags[i] & GlyphFlags.UnsafeToBreak) == 0;
}

float width = glyphs.Advance;

Properties

XAdvance

How far the pen moves right after the glyph.

public float XAdvance { get; init; }

Property Value

float

XOffset

How far right of the pen the glyph is drawn.

public float XOffset { get; init; }

Property Value

float

YAdvance

How far the pen moves up after the glyph (vertical runs move down, so this is negative).

public float YAdvance { get; init; }

Property Value

float

YOffset

How far above the pen the glyph is drawn.

public float YOffset { get; init; }

Property Value

float