Class GlyphBuffer
A reusable buffer of shaped glyphs: glyph ids, the UTF-16 index of the text each came from, glyph flags and positions, in visual order. ShapeRun(ReadOnlySpan<char>, int, int, Font, RunProperties, GlyphBuffer) fills it; reuse one buffer for many runs to avoid allocations.
public sealed class GlyphBuffer
- Inheritance
-
GlyphBuffer
- 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;
Remarks
Not thread-safe: one buffer per thread.
Properties
Advance
Gets the run's advance: the sum of the glyphs' horizontal advances.
public float Advance { get; }
Property Value
Clusters
Gets the UTF-16 index in the text each glyph's cluster starts at.
public ReadOnlySpan<int> Clusters { get; }
Property Value
Count
Gets the number of glyphs.
public int Count { get; }
Property Value
Flags
Gets each glyph's flags.
public ReadOnlySpan<GlyphFlags> Flags { get; }
Property Value
GlyphIds
Gets the glyph ids.
public ReadOnlySpan<ushort> GlyphIds { get; }
Property Value
Positions
Gets each glyph's advance and offset, in the units of the font the run was shaped with.
public ReadOnlySpan<GlyphPosition> Positions { get; }
Property Value
Methods
Clear()
Empties the buffer, keeping its storage.
public void Clear()