TextMetrics Class
The measurements of a text (https://html.spec.whatwg.org/multipage/canvas.html#textmetrics), returned by measureText(): the distances are in CSS px, relative to the alignment point and to the baseline of the text attributes of the context.
public sealed class TextMetricsProperties
| Name | Description |
|---|---|
| ActualBoundingBoxAscent | Gets the distance from the baseline to the top of the bounding box of the glyphs (positive upwards). |
| ActualBoundingBoxDescent | Gets the distance from the baseline to the bottom of the bounding box of the glyphs (positive downwards). |
| ActualBoundingBoxLeft | Gets the distance from the alignment point to the left of the bounding box of the glyphs (positive to the left). |
| ActualBoundingBoxRight | Gets the distance from the alignment point to the right of the bounding box of the glyphs (positive to the right). |
| AlphabeticBaseline | Gets the distance from the baseline to the alphabetic baseline (positive when the baseline is below it). |
| EmHeightAscent | Gets the distance from the baseline to the top of the em square (positive when the baseline is below it). |
| EmHeightDescent | Gets the distance from the baseline to the bottom of the em square (positive when the baseline is above it). |
| FontBoundingBoxAscent | Gets the distance from the baseline to the ascent of the first available font (positive upwards). |
| FontBoundingBoxDescent | Gets the distance from the baseline to the descent of the first available font (positive downwards). |
| HangingBaseline | Gets the distance from the baseline to the hanging baseline (positive when the baseline is below it). |
| IdeographicBaseline | Gets the distance from the baseline to the ideographic-under baseline (positive when the baseline is below it). |
| Width | Gets the advance width of the text. |
ActualBoundingBoxAscent
CanvasRenderingContext2DBase.Text.csGets the distance from the baseline to the top of the bounding box of the glyphs (positive upwards).
public double ActualBoundingBoxAscent { get; }ActualBoundingBoxDescent
CanvasRenderingContext2DBase.Text.csGets the distance from the baseline to the bottom of the bounding box of the glyphs (positive downwards).
public double ActualBoundingBoxDescent { get; }ActualBoundingBoxLeft
CanvasRenderingContext2DBase.Text.csGets the distance from the alignment point to the left of the bounding box of the glyphs (positive to the left).
public double ActualBoundingBoxLeft { get; }ActualBoundingBoxRight
CanvasRenderingContext2DBase.Text.csGets the distance from the alignment point to the right of the bounding box of the glyphs (positive to the right).
public double ActualBoundingBoxRight { get; }AlphabeticBaseline
CanvasRenderingContext2DBase.Text.csGets the distance from the baseline to the alphabetic baseline (positive when the baseline is below it).
public double AlphabeticBaseline { get; }EmHeightAscent
CanvasRenderingContext2DBase.Text.csGets the distance from the baseline to the top of the em square (positive when the baseline is below it).
public double EmHeightAscent { get; }Property value
See also
EmHeightDescent
CanvasRenderingContext2DBase.Text.csGets the distance from the baseline to the bottom of the em square (positive when the baseline is above it).
public double EmHeightDescent { get; }Property value
See also
FontBoundingBoxAscent
CanvasRenderingContext2DBase.Text.csGets the distance from the baseline to the ascent of the first available font (positive upwards).
public double FontBoundingBoxAscent { get; }FontBoundingBoxDescent
CanvasRenderingContext2DBase.Text.csGets the distance from the baseline to the descent of the first available font (positive downwards).
public double FontBoundingBoxDescent { get; }HangingBaseline
CanvasRenderingContext2DBase.Text.csGets the distance from the baseline to the hanging baseline (positive when the baseline is below it).
public double HangingBaseline { get; }Property value
See also
IdeographicBaseline
CanvasRenderingContext2DBase.Text.csGets the distance from the baseline to the ideographic-under baseline (positive when the baseline is below it).
public double IdeographicBaseline { get; }Methods
| Name | Description |
|---|---|
| GetActualBoundingBox(uint, uint) | Returns the bounding box of the glyphs of a range of the text (https://github.com/whatwg/html/pull/11000), relative to the alignment point and to the baseline: the box that the actualBoundingBox metrics give for the text where the other characters are not drawn. |
| GetIndexFromOffset(double) | Returns the index (in UTF-16 code units) of the caret position closest to a horizontal offset from the alignment point (https://github.com/whatwg/html/pull/11000): the position before the character under the offset in the reading direction when the offset is on its first half, else the position after it. |
| GetSelectionRects(uint, uint) | Returns the rectangles of the selection of a range of the text (https://github.com/whatwg/html/pull/11000), relative to the alignment point and to the baseline: one per bidi run of the range, of the height of the font bounding box. |
| GetTextClusters(TextClusterOptions?) | Returns the clusters of the text (https://github.com/whatwg/html/pull/11000), in logical order: its grapheme clusters (merged when a glyph spans several of them), each drawn by CanvasRenderingContext2DBase.FillTextCluster at the position that draws the text as fillText(). |
| GetTextClusters(uint, uint, TextClusterOptions?) | Returns the clusters of the text that have characters in a range (https://github.com/whatwg/html/pull/11000): see TextMetrics.GetTextClusters. |
GetActualBoundingBox(uint, uint)
CanvasRenderingContext2DBase.TextClusters.cs- Experimental (WEBPLATEXP0024)
Returns the bounding box of the glyphs of a range of the text (https://github.com/whatwg/html/pull/11000), relative to the alignment point and to the baseline: the box that the actualBoundingBox metrics give for the text where the other characters are not drawn.
[Experimental("WEBPLATEXP0024", UrlFormat = "https://github.com/meziantou/Meziantou.Framework/blob/main/src/Meziantou.Framework.WebPlatform/docs/experimental-apis.md#{0}")]
public DomRectReadOnly GetActualBoundingBox(uint start, uint end)Parameters
startuint- The index (in UTF-16 code units) of the start of the range.
enduint- The index (in UTF-16 code units) of the end of the range.
Returns
Exceptions
DomException- An
IndexSizeErrorwhen the start is not the index of a character, or the end is after the end of the text.
See also
GetIndexFromOffset(double)
CanvasRenderingContext2DBase.TextClusters.cs- Experimental (WEBPLATEXP0024)
Returns the index (in UTF-16 code units) of the caret position closest to a horizontal offset from the alignment point (https://github.com/whatwg/html/pull/11000): the position before the character under the offset in the reading direction when the offset is on its first half, else the position after it.
[Experimental("WEBPLATEXP0024", UrlFormat = "https://github.com/meziantou/Meziantou.Framework/blob/main/src/Meziantou.Framework.WebPlatform/docs/experimental-apis.md#{0}")]
public uint GetIndexFromOffset(double offset)GetSelectionRects(uint, uint)
CanvasRenderingContext2DBase.TextClusters.cs- Experimental (WEBPLATEXP0024)
Returns the rectangles of the selection of a range of the text (https://github.com/whatwg/html/pull/11000), relative to the alignment point and to the baseline: one per bidi run of the range, of the height of the font bounding box.
[Experimental("WEBPLATEXP0024", UrlFormat = "https://github.com/meziantou/Meziantou.Framework/blob/main/src/Meziantou.Framework.WebPlatform/docs/experimental-apis.md#{0}")]
public IReadOnlyList<DomRectReadOnly> GetSelectionRects(uint start, uint end)Parameters
startuint- The index (in UTF-16 code units) of the start of the range.
enduint- The index (in UTF-16 code units) of the end of the range: a range that ends at or before its start is a rectangle without width at the caret position of the end.
Returns
IReadOnlyList<DomRectReadOnly>
Exceptions
DomException- An
IndexSizeErrorwhen an index is after the end of the text.
See also
GetTextClusters overloads
GetTextClusters(TextClusterOptions?)
CanvasRenderingContext2DBase.TextClusters.cs- Experimental (WEBPLATEXP0024)
Returns the clusters of the text (https://github.com/whatwg/html/pull/11000), in logical order: its grapheme clusters (merged when a glyph spans several of them), each drawn by CanvasRenderingContext2DBase.FillTextCluster at the position that draws the text as fillText().
[Experimental("WEBPLATEXP0024", UrlFormat = "https://github.com/meziantou/Meziantou.Framework/blob/main/src/Meziantou.Framework.WebPlatform/docs/experimental-apis.md#{0}")]
public IReadOnlyList<TextCluster> GetTextClusters(TextClusterOptions? options = null)Parameters
optionsTextClusterOptions?- The alignment and the baseline of the positions of the clusters (by default, the ones of the context when the text was measured).
Returns
See also
GetTextClusters(uint, uint, TextClusterOptions?)
CanvasRenderingContext2DBase.TextClusters.cs- Experimental (WEBPLATEXP0024)
Returns the clusters of the text that have characters in a range (https://github.com/whatwg/html/pull/11000): see TextMetrics.GetTextClusters.
[Experimental("WEBPLATEXP0024", UrlFormat = "https://github.com/meziantou/Meziantou.Framework/blob/main/src/Meziantou.Framework.WebPlatform/docs/experimental-apis.md#{0}")]
public IReadOnlyList<TextCluster> GetTextClusters(uint start, uint end, TextClusterOptions? options = null)Parameters
startuint- The index (in UTF-16 code units) of the start of the range.
enduint- The index (in UTF-16 code units) of the end of the range.
optionsTextClusterOptions?- The alignment and the baseline of the positions of the clusters (by default, the ones of the context when the text was measured).
Returns
Exceptions
DomException- An
IndexSizeErrorwhen the start is not the index of a character, or the end is after the end of the text.