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 GlyphBufferRemarks
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
| Name | Description |
|---|---|
| GlyphBuffer(FontResourceLimits) | Initializes a new instance of the GlyphBuffer class. |
GlyphBuffer(FontResourceLimits)
GlyphBuffer.csInitializes a new instance of the GlyphBuffer class.
public GlyphBuffer(FontResourceLimits limits)Parameters
limitsFontResourceLimits- The limits whose
FontResourceLimits.MaxTextGlyphsbounds the number of glyphs.
Properties
| Name | Description |
|---|---|
| Info | Gets the glyphs. |
| Length | Gets the number of glyphs. |
| Positions | Gets the positions of the glyphs, once GlyphBuffer.CreatePositions was called. |
| PostContext | Gets the characters of the text after the run, from the nearest one. |
| PreContext | 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). |
Info
GlyphBuffer.csLength
GlyphBuffer.csPositions
GlyphBuffer.csGets the positions of the glyphs, once GlyphBuffer.CreatePositions was called.
public Span<GlyphPosition> Positions { get; }Property value
PostContext
GlyphBuffer.csGets the characters of the text after the run, from the nearest one.
public ReadOnlySpan<int> PostContext { get; }Property value
PreContext
GlyphBuffer.csGets 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
Methods
| Name | Description |
|---|---|
| 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.csAllocateLigatureId()
GlyphBuffer.csCharge(int)
GlyphBuffer.csSpends operations of the budget.
Clear()
GlyphBuffer.csRemoves every glyph and the context.
public void Clear()CreatePositions()
GlyphBuffer.csAllocates the positions, all zero, once the substitutions are done.
public void CreatePositions()Delete(int)
GlyphBuffer.csMarkUnsafeToBreak(int, int)
GlyphBuffer.csMergeClusters(int, int)
GlyphBuffer.csRemove(ReadOnlySpan<int>)
GlyphBuffer.csRemoves the glyphs at increasing indexes, moving the glyphs that follow each of them once.
public void Remove(ReadOnlySpan<int> indexes)Parameters
indexesReadOnlySpan<int>
Repeat(int, int)
GlyphBuffer.csInserts copies of a positioned glyph after it.
Resize(int, int, int)
GlyphBuffer.csReplaces 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()
GlyphBuffer.csReverses the order of the glyphs, and of their positions when they exist.
public void Reverse()SetContext(ReadOnlySpan<int>, ReadOnlySpan<int>)
GlyphBuffer.csSets 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
beforeReadOnlySpan<int>- The characters before the run, from the nearest one.
afterReadOnlySpan<int>- The characters after the run, from the nearest one.
StartPass(int)
GlyphBuffer.csCounts 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.
Parameters
subtableCountint
Exceptions
InvalidFontException- The lookups have more subtables than a font can need.
StartShaping()
GlyphBuffer.csSets the budget of operations from the number of characters of the run.
public void StartShaping()Constants
| Name | Description |
|---|---|
| MaxContextLength | The 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