Struct GlyphPosition
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
XAdvancefloatHow far the pen moves right after the glyph.
YAdvancefloatHow far the pen moves up after the glyph (vertical runs move down, so this is negative).
XOffsetfloatHow far right of the pen the glyph is drawn.
YOffsetfloatHow 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
XOffset
How far right of the pen the glyph is drawn.
public float XOffset { get; init; }
Property Value
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
YOffset
How far above the pen the glyph is drawn.
public float YOffset { get; init; }