GlyphBuffer Class

The glyphs of a run of text while it is shaped: characters come in, substitutions replace, insert and remove glyphs, positioning fills the positions.

public sealed class GlyphBuffer

Remarks

Clusters. Every glyph carries the index of the first character of its cluster. Glyphs that shaping ties together (a ligature, a reordered syllable, a character and its marks) share one cluster, the smallest index of their characters, and the clusters never decrease along a run. A cluster is what a caret, a selection or a line break can separate.

Bounds. A font is untrusted input: its lookups can multiply glyphs without end. The buffer refuses to grow beyond FontResourceLimits.MaxTextGlyphs, and counts the operations of the lookups so that a font cannot make shaping run for a time out of proportion with the text: a pass of a lookup over the glyphs is what shaping is, the lookups a rule applies and the number of subtables of the font are what is bounded.

Constructors

NameDescription
GlyphBuffer(FontResourceLimits)Initializes a new instance of the GlyphBuffer class.

GlyphBuffer(FontResourceLimits)

GlyphBuffer.cs

Initializes a new instance of the GlyphBuffer class.

public GlyphBuffer(FontResourceLimits limits)

Parameters

limits FontResourceLimits
The limits whose FontResourceLimits.MaxTextGlyphs bounds the number of glyphs.

Properties

NameDescription
InfoGets the glyphs.
LengthGets the number of glyphs.
PositionsGets the positions of the glyphs, once GlyphBuffer.CreatePositions was called.
PostContextGets the characters of the text after the run, from the nearest one.
PreContextGets the characters of the text before the run, from the nearest one, which change how its first characters are shaped (the letters that join).

Gets the glyphs.

public Span<GlyphInfo> Info { get; }

Property value

Span<GlyphInfo>

Gets the number of glyphs.

public int Length { get; }

Property value

int

Gets the positions of the glyphs, once GlyphBuffer.CreatePositions was called.

public Span<GlyphPosition> Positions { get; }

Property value

Span<GlyphPosition>

PostContext

GlyphBuffer.cs

Gets the characters of the text after the run, from the nearest one.

public ReadOnlySpan<int> PostContext { get; }

Property value

ReadOnlySpan<int>

PreContext

GlyphBuffer.cs

Gets the characters of the text before the run, from the nearest one, which change how its first characters are shaped (the letters that join).

public ReadOnlySpan<int> PreContext { get; }

Property value

ReadOnlySpan<int>

Methods

NameDescription
Add(int, int)Adds a character at the end.
AllocateLigatureId()Gets an identifier for a new ligature: a small number that differs from the ones of its neighbors.
Charge(int)Spends operations of the budget.
Clear()Removes every glyph and the context.
CreatePositions()Allocates the positions, all zero, once the substitutions are done.
Delete(int)Removes a glyph, and its position when the positions exist; its characters join the cluster of a neighbor, so that no character is lost.
MarkUnsafeToBreak(int, int)Marks the glyphs of a range that a break would separate from what the font did with the glyphs before them: those whose cluster is not the smallest of the range (GlyphInfo.UnsafeToBreak).
MergeClusters(int, int)Gives a range of glyphs one cluster: the smallest of theirs, extended to the glyphs that already share a cluster with an end of the range.
Remove(ReadOnlySpan<int>)Removes the glyphs at increasing indexes, moving the glyphs that follow each of them once.
Repeat(int, int)Inserts copies of a positioned glyph after it.
Resize(int, int, int)Replaces a range of glyphs by a number of glyphs, which are copies of the first glyph of the range (or of the glyph before the insertion point when the range is empty) and are then set by the caller.
Reverse()Reverses the order of the glyphs, and of their positions when they exist.
SetContext(ReadOnlySpan<int>, ReadOnlySpan<int>)Sets the characters of the text around the run, which is shaped as a part of a longer text: the letters of a joining script take the forms they have in the text. The first characters of each side are kept, from the nearest one.
StartPass(int)Counts a pass of a lookup over the glyphs: each of its subtables is tried at each glyph. That work is what shaping is, and is in proportion with the text as long as the lookups of the font are in reasonable number; what a lookup costs beyond it (the lookups its rules apply) is taken from the budget of the run.
StartShaping()Sets the budget of operations from the number of characters of the run.

Add(int, int)

GlyphBuffer.cs

Adds a character at the end.

public void Add(int codePoint, int cluster)

Parameters

codePoint int
cluster int

AllocateLigatureId()

GlyphBuffer.cs

Gets an identifier for a new ligature: a small number that differs from the ones of its neighbors.

public byte AllocateLigatureId()

Returns

byte

Charge(int)

GlyphBuffer.cs

Spends operations of the budget.

public void Charge(int count)

Parameters

count int

Exceptions

InvalidFontException
The font asks for more work than a text can need.

Removes every glyph and the context.

public void Clear()

CreatePositions()

GlyphBuffer.cs

Allocates the positions, all zero, once the substitutions are done.

public void CreatePositions()

Delete(int)

GlyphBuffer.cs

Removes a glyph, and its position when the positions exist; its characters join the cluster of a neighbor, so that no character is lost.

public void Delete(int index)

Parameters

index int

MarkUnsafeToBreak(int, int)

GlyphBuffer.cs

Marks the glyphs of a range that a break would separate from what the font did with the glyphs before them: those whose cluster is not the smallest of the range (GlyphInfo.UnsafeToBreak).

public void MarkUnsafeToBreak(int start, int end)

Parameters

start int
end int

MergeClusters(int, int)

GlyphBuffer.cs

Gives a range of glyphs one cluster: the smallest of theirs, extended to the glyphs that already share a cluster with an end of the range.

public void MergeClusters(int start, int end)

Parameters

start int
end int

Remove(ReadOnlySpan<int>)

GlyphBuffer.cs

Removes the glyphs at increasing indexes, moving the glyphs that follow each of them once.

public void Remove(ReadOnlySpan<int> indexes)

Parameters

indexes ReadOnlySpan<int>

Repeat(int, int)

GlyphBuffer.cs

Inserts copies of a positioned glyph after it.

public void Repeat(int index, int copies)

Parameters

index int
copies int

Exceptions

FontResourceLimitException
The glyphs exceed FontResourceLimits.MaxTextGlyphs.

Resize(int, int, int)

GlyphBuffer.cs

Replaces a range of glyphs by a number of glyphs, which are copies of the first glyph of the range (or of the glyph before the insertion point when the range is empty) and are then set by the caller.

public void Resize(int index, int oldCount, int newCount)

Parameters

index int
oldCount int
newCount int

Exceptions

FontResourceLimitException
The glyphs exceed FontResourceLimits.MaxTextGlyphs.

Reverses the order of the glyphs, and of their positions when they exist.

public void Reverse()

SetContext(ReadOnlySpan<int>, ReadOnlySpan<int>)

GlyphBuffer.cs

Sets the characters of the text around the run, which is shaped as a part of a longer text: the letters of a joining script take the forms they have in the text. The first characters of each side are kept, from the nearest one.

public void SetContext(ReadOnlySpan<int> before, ReadOnlySpan<int> after)

Parameters

before ReadOnlySpan<int>
The characters before the run, from the nearest one.
after ReadOnlySpan<int>
The characters after the run, from the nearest one.

StartPass(int)

GlyphBuffer.cs

Counts a pass of a lookup over the glyphs: each of its subtables is tried at each glyph. That work is what shaping is, and is in proportion with the text as long as the lookups of the font are in reasonable number; what a lookup costs beyond it (the lookups its rules apply) is taken from the budget of the run.

public void StartPass(int subtableCount)

Parameters

subtableCount int

Exceptions

InvalidFontException
The lookups have more subtables than a font can need.

StartShaping()

GlyphBuffer.cs

Sets the budget of operations from the number of characters of the run.

public void StartShaping()

Constants

NameDescription
MaxContextLengthThe greatest number of characters of context kept on each side of a run.

MaxContextLength

The greatest number of characters of context kept on each side of a run.

public const int MaxContextLength = 5