CanvasShapedText Class

  • Experimental (WEBPLATEXP0025)

A text shaped by CanvasRenderingContext2DBase.ShapeText with the font, the text styles, the direction, the alignment and the baseline of the context: its glyph runs and clusters, the caret positions and the selection rectangles. The distances are in CSS px, relative to the alignment point and to the baseline of the text.

[Experimental("WEBPLATEXP0025", UrlFormat = "https://github.com/meziantou/Meziantou.Framework/blob/main/src/Meziantou.Framework.WebPlatform/docs/experimental-apis.md#{0}")]
public sealed class CanvasShapedText

Properties

NameDescription
WidthGets the advance width of the text.

Methods

NameDescription
ActualBoundingBox(uint, uint)Returns the bounding box of the glyphs of a range of the text: see TextMetrics.GetActualBoundingBox.
AdvanceToPosition(double)Returns the index (in UTF-16 code units) of the caret position closest to a horizontal offset from the alignment point: see TextMetrics.GetIndexFromOffset.
GlyphClusters()Returns the clusters of the text, in logical order, as glyph runs: its grapheme clusters, merged when a glyph spans several of them.
GlyphClusters(uint, uint)Returns the clusters of the text that have characters in a range, in logical order, as glyph runs.
GlyphRuns()Returns the glyph runs of the text, from left to right: the glyphs of a bidi run with the same font.
PositionToAdvance(uint)Returns the horizontal offset from the alignment point of the caret position before a character (or at the end of the text).
SelectionRects(uint, uint)Returns the rectangles of the selection of a range of the text: see TextMetrics.GetSelectionRects.

Returns the bounding box of the glyphs of a range of the text: see TextMetrics.GetActualBoundingBox.

public DomRectReadOnly ActualBoundingBox(uint start, uint end)

Parameters

start uint
The index (in UTF-16 code units) of the start of the range.
end uint
The index (in UTF-16 code units) of the end of the range.

Returns

DomRectReadOnly

Exceptions

DomException
An IndexSizeError when the start is not the index of a character, or the end is after the end of the text.

See also

Returns the index (in UTF-16 code units) of the caret position closest to a horizontal offset from the alignment point: see TextMetrics.GetIndexFromOffset.

public uint AdvanceToPosition(double advance)

GlyphClusters overloads

Returns the clusters of the text, in logical order, as glyph runs: its grapheme clusters, merged when a glyph spans several of them.

public IReadOnlyList<CanvasGlyphRun> GlyphClusters()

Returns the clusters of the text that have characters in a range, in logical order, as glyph runs.

public IReadOnlyList<CanvasGlyphRun> GlyphClusters(uint start, uint end)
Parameters
start uint
The index (in UTF-16 code units) of the start of the range.
end uint
The index (in UTF-16 code units) of the end of the range.
Returns

IReadOnlyList<CanvasGlyphRun>

Exceptions
DomException
An IndexSizeError when the start is not the index of a character, or the end is after the end of the text.
See also

Returns the glyph runs of the text, from left to right: the glyphs of a bidi run with the same font.

public IReadOnlyList<CanvasGlyphRun> GlyphRuns()

Returns the horizontal offset from the alignment point of the caret position before a character (or at the end of the text).

public double PositionToAdvance(uint position)

Parameters

position uint
The index (in UTF-16 code units) of the caret position.

Returns

double

Exceptions

DomException
An IndexSizeError when the index is after the end of the text.

See also

Returns the rectangles of the selection of a range of the text: see TextMetrics.GetSelectionRects.

public IReadOnlyList<DomRectReadOnly> SelectionRects(uint start, uint end)

Parameters

start uint
The index (in UTF-16 code units) of the start of the range.
end uint
The index (in UTF-16 code units) of the end of the range.

Returns

IReadOnlyList<DomRectReadOnly>

Exceptions

DomException
An IndexSizeError when an index is after the end of the text.

See also