Class TextMeasurer
Encapsulates logic for laying out and then measuring text properties.
public static class TextMeasurer
- Inheritance
-
TextMeasurer
- Inherited Members
Methods
CountLines(ReadOnlySpan<char>, TextOptions)
Gets the number of laid-out lines contained within the text.
public static int CountLines(ReadOnlySpan<char> text, TextOptions options)
Parameters
textReadOnlySpan<char>The text.
optionsTextOptionsThe text options. WrappingLength controls wrapping; use
-1to disable wrapping.
Returns
- int
The laid-out line count.
CountLines(string, TextOptions)
Gets the number of laid-out lines contained within the text.
public static int CountLines(string text, TextOptions options)
Parameters
textstringThe text.
optionsTextOptionsThe text options. WrappingLength controls wrapping; use
-1to disable wrapping.
Returns
- int
The laid-out line count.
GetGlyphMetrics(TextShapingBuffer, GlyphOptions)
Gets the positioned metrics of shaped glyphs in pixel units.
public static ReadOnlyMemory<GlyphMetrics> GetGlyphMetrics(TextShapingBuffer buffer, GlyphOptions options)
Parameters
bufferTextShapingBufferThe buffer containing the shaped glyphs.
optionsGlyphOptionsThe glyph options supplying the shaping font, resolution, and baseline origin.
Returns
- ReadOnlyMemory<GlyphMetrics>
A read-only memory region containing one positioned metrics entry per shaped glyph.
GetGlyphMetrics(ReadOnlySpan<char>, TextOptions)
Gets the positioned metrics of each laid-out glyph entry in pixel units.
public static ReadOnlyMemory<GlyphMetrics> GetGlyphMetrics(ReadOnlySpan<char> text, TextOptions options)
Parameters
textReadOnlySpan<char>The text.
optionsTextOptionsThe text options. WrappingLength controls wrapping; use
-1to disable wrapping.
Returns
- ReadOnlyMemory<GlyphMetrics>
A read-only memory region containing the per-glyph metrics entries of the text if it was to be rendered.
GetGlyphMetrics(ReadOnlySpan<ushort>, ReadOnlySpan<Vector2>, GlyphOptions)
Gets the positioned metrics of glyphs at supplied points in pixel units.
public static ReadOnlyMemory<GlyphMetrics> GetGlyphMetrics(ReadOnlySpan<ushort> glyphIds, ReadOnlySpan<Vector2> points, GlyphOptions options)
Parameters
glyphIdsReadOnlySpan<ushort>The glyph identifiers.
pointsReadOnlySpan<Vector2>The absolute glyph origins in pixel units.
optionsGlyphOptionsThe glyph options, including the font and layout mode.
Returns
- ReadOnlyMemory<GlyphMetrics>
A read-only memory region containing one positioned metrics entry per input glyph.
Remarks
The metrics are computed directly from the font's cached per-glyph metrics without decoding outlines or running the layout engine. Each glyph is measured at its supplied point exactly as RenderTo(IGlyphRenderer, ReadOnlySpan<ushort>, ReadOnlySpan<Vector2>, GlyphOptions) renders it; Origin is replaced per glyph and restored. One entry is returned per input glyph so results correlate with run indices: each entry's grapheme index is GraphemeIndex plus the run index and its string index is the run index. Glyph ids the font does not contain, and glyphs that never render, produce entries with empty rectangles.
GetGlyphMetrics(string, TextOptions)
Gets the positioned metrics of each laid-out glyph entry in pixel units.
public static ReadOnlyMemory<GlyphMetrics> GetGlyphMetrics(string text, TextOptions options)
Parameters
textstringThe text.
optionsTextOptionsThe text options. WrappingLength controls wrapping; use
-1to disable wrapping.
Returns
- ReadOnlyMemory<GlyphMetrics>
A read-only memory region containing the per-glyph metrics entries of the text if it was to be rendered.
GetGlyphMetrics(ushort, GlyphOptions)
Gets the positioned metrics of a single glyph, identified by its glyph id, in pixel units.
public static GlyphMetrics GetGlyphMetrics(ushort glyphId, GlyphOptions options)
Parameters
glyphIdushortThe glyph identifier within the font face referenced by
options.optionsGlyphOptionsThe glyph options, including the font, origin, and layout mode.
Returns
- GlyphMetrics
The positioned metrics entry of the glyph if it was to be rendered.
Remarks
The metrics are computed directly from the font's cached per-glyph metrics without
decoding outlines or running the layout engine, positioned at
Origin. The entry's grapheme index is
GraphemeIndex and its string index is 0: glyph ids carry
no source text, so the index identifies the glyph within the measured input instead. A
glyph the font does not contain, or one that never renders, produces an entry with empty
rectangles.
GetGraphemeMetrics(ReadOnlySpan<char>, TextOptions)
Gets the positioned metrics of each laid-out grapheme in pixel units.
public static ReadOnlyMemory<GraphemeMetrics> GetGraphemeMetrics(ReadOnlySpan<char> text, TextOptions options)
Parameters
textReadOnlySpan<char>The text.
optionsTextOptionsThe text options. WrappingLength controls wrapping; use
-1to disable wrapping.
Returns
- ReadOnlyMemory<GraphemeMetrics>
A read-only memory region containing the per-grapheme metrics entries of the text if it was to be rendered.
GetGraphemeMetrics(string, TextOptions)
Gets the positioned metrics of each laid-out grapheme in pixel units.
public static ReadOnlyMemory<GraphemeMetrics> GetGraphemeMetrics(string text, TextOptions options)
Parameters
textstringThe text.
optionsTextOptionsThe text options. WrappingLength controls wrapping; use
-1to disable wrapping.
Returns
- ReadOnlyMemory<GraphemeMetrics>
A read-only memory region containing the per-grapheme metrics entries of the text if it was to be rendered.
GetIntersections(TextShapingBuffer, GlyphOptions, float, float)
Gets the x-axis intervals where shaped glyph outlines cross a horizontal band, in pixel units.
public static ReadOnlyMemory<float> GetIntersections(TextShapingBuffer buffer, GlyphOptions options, float lowerLimit, float upperLimit)
Parameters
bufferTextShapingBufferThe buffer containing the shaped glyphs.
optionsGlyphOptionsThe glyph options supplying the shaping font, resolution, and baseline origin.
lowerLimitfloatOne edge of the horizontal band.
upperLimitfloatThe other edge of the horizontal band.
Returns
- ReadOnlyMemory<float>
A read-only memory region containing merged, x-sorted interval pairs (start, end, start, end, ...); empty when no outline crosses the band.
GetIntersections(ReadOnlySpan<char>, TextOptions, float, float)
Gets the x-axis intervals where the laid-out text's glyph outlines cross a horizontal band, in pixel units.
public static ReadOnlyMemory<float> GetIntersections(ReadOnlySpan<char> text, TextOptions options, float lowerLimit, float upperLimit)
Parameters
textReadOnlySpan<char>The text.
optionsTextOptionsThe text options. WrappingLength controls wrapping; use
-1to disable wrapping.lowerLimitfloatOne edge of the horizontal band.
upperLimitfloatThe other edge of the horizontal band.
Returns
- ReadOnlyMemory<float>
A read-only memory region containing merged, x-sorted interval pairs (start, end, start, end, ...); empty when no outline crosses the band.
Remarks
The intervals are computed from the exact outline geometry the renderer would draw (including hinting), so text decorations can be broken precisely around descenders. Glyphs whose bounds do not touch the band skip outline decoding entirely. The band and the returned x-values share the laid-out text's coordinate space.
GetIntersections(ReadOnlySpan<ushort>, ReadOnlySpan<Vector2>, GlyphOptions, float, float)
Gets the x-axis intervals where positioned glyph outlines cross a horizontal band, in pixel units.
public static ReadOnlyMemory<float> GetIntersections(ReadOnlySpan<ushort> glyphIds, ReadOnlySpan<Vector2> points, GlyphOptions options, float lowerLimit, float upperLimit)
Parameters
glyphIdsReadOnlySpan<ushort>The glyph identifiers.
pointsReadOnlySpan<Vector2>The absolute glyph origins in pixel units.
optionsGlyphOptionsThe glyph options, including the font and layout mode.
lowerLimitfloatOne edge of the horizontal band.
upperLimitfloatThe other edge of the horizontal band.
Returns
- ReadOnlyMemory<float>
A read-only memory region containing merged, x-sorted interval pairs (start, end, start, end, ...); empty when no outline crosses the band.
Remarks
The intervals are computed from the exact outline geometry the renderer would draw (including hinting), each glyph at its own run origin, so text decorations can be broken precisely around descenders. Glyphs whose bounds do not touch the band skip outline decoding entirely. The band and the returned x-values share the points' coordinate space.
GetIntersections(string, TextOptions, float, float)
Gets the x-axis intervals where the laid-out text's glyph outlines cross a horizontal band, in pixel units.
public static ReadOnlyMemory<float> GetIntersections(string text, TextOptions options, float lowerLimit, float upperLimit)
Parameters
textstringThe text.
optionsTextOptionsThe text options. WrappingLength controls wrapping; use
-1to disable wrapping.lowerLimitfloatOne edge of the horizontal band.
upperLimitfloatThe other edge of the horizontal band.
Returns
- ReadOnlyMemory<float>
A read-only memory region containing merged, x-sorted interval pairs (start, end, start, end, ...); empty when no outline crosses the band.
Remarks
The intervals are computed from the exact outline geometry the renderer would draw (including hinting), so text decorations can be broken precisely around descenders. Glyphs whose bounds do not touch the band skip outline decoding entirely. The band and the returned x-values share the laid-out text's coordinate space.
GetIntersections(ushort, GlyphOptions, float, float)
Gets the x-axis intervals where a single glyph's outline, identified by its glyph id, crosses a horizontal band, in pixel units.
public static ReadOnlyMemory<float> GetIntersections(ushort glyphId, GlyphOptions options, float lowerLimit, float upperLimit)
Parameters
glyphIdushortThe glyph identifier within the font face referenced by
options.optionsGlyphOptionsThe glyph options, including the font, origin, and layout mode.
lowerLimitfloatOne edge of the horizontal band.
upperLimitfloatThe other edge of the horizontal band.
Returns
- ReadOnlyMemory<float>
A read-only memory region containing merged, x-sorted interval pairs (start, end, start, end, ...); empty when the outline does not cross the band.
Remarks
The intervals are computed from the exact outline geometry the renderer would draw (including hinting) at Origin. The band and the returned x-values share the glyph origin's coordinate space.
GetLineMetrics(ReadOnlySpan<char>, TextOptions)
Gets per-line layout metrics for the supplied text.
public static ReadOnlyMemory<LineMetrics> GetLineMetrics(ReadOnlySpan<char> text, TextOptions options)
Parameters
textReadOnlySpan<char>The text to measure.
optionsTextOptionsThe text options. WrappingLength controls wrapping; use
-1to disable wrapping.
Returns
- ReadOnlyMemory<LineMetrics>
A read-only memory region containing LineMetrics in pixel units, one entry per laid-out line.
GetLineMetrics(string, TextOptions)
Gets per-line layout metrics for the supplied text.
public static ReadOnlyMemory<LineMetrics> GetLineMetrics(string text, TextOptions options)
Parameters
textstringThe text to measure.
optionsTextOptionsThe text options. WrappingLength controls wrapping; use
-1to disable wrapping.
Returns
- ReadOnlyMemory<LineMetrics>
A read-only memory region containing LineMetrics in pixel units, one entry per laid-out line.
GetWordMetrics(ReadOnlySpan<char>, TextOptions)
Gets the positioned metrics of each Unicode word-boundary segment in pixel units.
public static ReadOnlyMemory<WordMetrics> GetWordMetrics(ReadOnlySpan<char> text, TextOptions options)
Parameters
textReadOnlySpan<char>The text.
optionsTextOptionsThe text options. WrappingLength controls wrapping; use
-1to disable wrapping.
Returns
- ReadOnlyMemory<WordMetrics>
A read-only memory region containing the per-word-boundary segment metrics entries of the text if it was to be rendered.
GetWordMetrics(string, TextOptions)
Gets the positioned metrics of each Unicode word-boundary segment in pixel units.
public static ReadOnlyMemory<WordMetrics> GetWordMetrics(string text, TextOptions options)
Parameters
textstringThe text.
optionsTextOptionsThe text options. WrappingLength controls wrapping; use
-1to disable wrapping.
Returns
- ReadOnlyMemory<WordMetrics>
A read-only memory region containing the per-word-boundary segment metrics entries of the text if it was to be rendered.
Measure(ReadOnlySpan<char>, TextOptions)
Measures the full set of layout metrics for the supplied text in a single pass.
public static TextMetrics Measure(ReadOnlySpan<char> text, TextOptions options)
Parameters
textReadOnlySpan<char>The text.
optionsTextOptionsThe text options. WrappingLength controls wrapping; use
-1to disable wrapping.
Returns
- TextMetrics
A TextMetrics instance containing every measurement for the laid-out text.
Measure(string, TextOptions)
Measures the full set of layout metrics for the supplied text in a single pass.
public static TextMetrics Measure(string text, TextOptions options)
Parameters
textstringThe text.
optionsTextOptionsThe text options. WrappingLength controls wrapping; use
-1to disable wrapping.
Returns
- TextMetrics
A TextMetrics instance containing every measurement for the laid-out text.
MeasureAdvance(TextShapingBuffer, GlyphOptions)
Measures the logical advance of shaped glyphs in pixel units.
public static FontRectangle MeasureAdvance(TextShapingBuffer buffer, GlyphOptions options)
Parameters
bufferTextShapingBufferThe buffer containing the shaped glyphs.
optionsGlyphOptionsThe glyph options supplying the shaping font, resolution, and baseline origin.
Returns
- FontRectangle
The zero-based logical advance extent of the glyphs if they were to be rendered, or Empty when no glyph participates in rendering.
MeasureAdvance(ReadOnlySpan<char>, TextOptions)
Measures the logical advance of the text in pixel units.
public static FontRectangle MeasureAdvance(ReadOnlySpan<char> text, TextOptions options)
Parameters
textReadOnlySpan<char>The text.
optionsTextOptionsThe text options. WrappingLength controls wrapping; use
-1to disable wrapping.
Returns
- FontRectangle
The logical advance rectangle of the text if it was to be rendered.
MeasureAdvance(ReadOnlySpan<ushort>, ReadOnlySpan<Vector2>, GlyphOptions)
Measures the logical advance of positioned glyphs in pixel units.
public static FontRectangle MeasureAdvance(ReadOnlySpan<ushort> glyphIds, ReadOnlySpan<Vector2> points, GlyphOptions options)
Parameters
glyphIdsReadOnlySpan<ushort>The glyph identifiers.
pointsReadOnlySpan<Vector2>The absolute glyph origins in pixel units.
optionsGlyphOptionsThe glyph options, including the font and layout mode.
Returns
- FontRectangle
The zero-based logical advance extent of the glyphs if they were to be rendered, or Empty when no glyph participates in rendering.
Remarks
Matching the text-level advance contract, the rectangle is zero-based: the extent the glyph advance cells cover at their points, reported independent of position and of TextBaseline. Glyph ids the font does not contain and glyphs that never render are skipped, matching renderer behavior.
MeasureAdvance(string, TextOptions)
Measures the logical advance of the text in pixel units.
public static FontRectangle MeasureAdvance(string text, TextOptions options)
Parameters
textstringThe text.
optionsTextOptionsThe text options. WrappingLength controls wrapping; use
-1to disable wrapping.
Returns
- FontRectangle
The logical advance rectangle of the text if it was to be rendered.
MeasureAdvance(ushort, GlyphOptions)
Measures the logical advance of a single glyph, identified by its glyph id, in pixel units.
public static FontRectangle MeasureAdvance(ushort glyphId, GlyphOptions options)
Parameters
glyphIdushortThe glyph identifier within the font face referenced by
options.optionsGlyphOptionsThe glyph options, including the font, origin, and layout mode.
Returns
- FontRectangle
The logical advance rectangle of the glyph if it was to be rendered, or Empty when the font does not contain the glyph or the glyph never renders.
Remarks
The advance is computed directly from the font's cached per-glyph metrics without decoding outlines or running the layout engine. Matching the text-level advance contract, the rectangle is zero-based: the advance width by the em height for horizontal layouts, and the advance the layout direction consumes for vertical layouts, independent of Origin and TextBaseline. Positioned geometry is reported by the bounds overloads.
MeasureBounds(TextShapingBuffer, GlyphOptions)
Measures the union of rendered bounds for shaped glyphs in pixel units.
public static FontRectangle MeasureBounds(TextShapingBuffer buffer, GlyphOptions options)
Parameters
bufferTextShapingBufferThe buffer containing the shaped glyphs.
optionsGlyphOptionsThe glyph options supplying the shaping font, resolution, and baseline origin.
Returns
- FontRectangle
The union of the rendered glyph bounds if they were to be rendered, or Empty when no glyph participates in rendering.
MeasureBounds(ReadOnlySpan<char>, TextOptions)
Measures the rendered glyph bounds of the text in pixel units.
public static FontRectangle MeasureBounds(ReadOnlySpan<char> text, TextOptions options)
Parameters
textReadOnlySpan<char>The text.
optionsTextOptionsThe text options. WrappingLength controls wrapping; use
-1to disable wrapping.
Returns
- FontRectangle
The rendered glyph bounds of the text if it was to be rendered.
MeasureBounds(ReadOnlySpan<ushort>, ReadOnlySpan<Vector2>, GlyphOptions)
Measures the union of rendered glyph bounds for positioned glyphs in pixel units.
public static FontRectangle MeasureBounds(ReadOnlySpan<ushort> glyphIds, ReadOnlySpan<Vector2> points, GlyphOptions options)
Parameters
glyphIdsReadOnlySpan<ushort>The glyph identifiers.
pointsReadOnlySpan<Vector2>The absolute glyph origins in pixel units.
optionsGlyphOptionsThe glyph options, including the font and layout mode.
Returns
- FontRectangle
The union of the rendered glyph bounds if they were to be rendered, or Empty when no glyph participates in rendering.
Remarks
Each glyph is measured at its supplied point exactly as RenderTo(IGlyphRenderer, ReadOnlySpan<ushort>, ReadOnlySpan<Vector2>, GlyphOptions) renders it; Origin is replaced per glyph and restored. The result matches the union of the bounding boxes the renderer reports for the same glyphs and options. Glyph ids the font does not contain and glyphs that never render are skipped, matching renderer behavior.
MeasureBounds(string, TextOptions)
Measures the rendered glyph bounds of the text in pixel units.
public static FontRectangle MeasureBounds(string text, TextOptions options)
Parameters
textstringThe text.
optionsTextOptionsThe text options. WrappingLength controls wrapping; use
-1to disable wrapping.
Returns
- FontRectangle
The rendered glyph bounds of the text if it was to be rendered.
MeasureBounds(ushort, GlyphOptions)
Measures the rendered bounds of a single glyph, identified by its glyph id, in pixel units.
public static FontRectangle MeasureBounds(ushort glyphId, GlyphOptions options)
Parameters
glyphIdushortThe glyph identifier within the font face referenced by
options.optionsGlyphOptionsThe glyph options, including the font, origin, and layout mode.
Returns
- FontRectangle
The rendered bounds of the glyph at Origin if it was to be rendered, or Empty when the font does not contain the glyph or the glyph never renders.
Remarks
The bounds are computed directly from the font's cached per-glyph metrics without decoding outlines or running the layout engine, and are identical to the bounding box the renderer reports for the same glyph and options through RenderTo(IGlyphRenderer, ushort, GlyphOptions).
MeasureRenderableBounds(TextShapingBuffer, GlyphOptions)
Measures the full renderable bounds of shaped glyphs in pixel units.
public static FontRectangle MeasureRenderableBounds(TextShapingBuffer buffer, GlyphOptions options)
Parameters
bufferTextShapingBufferThe buffer containing the shaped glyphs.
optionsGlyphOptionsThe glyph options supplying the shaping font, resolution, and baseline origin.
Returns
- FontRectangle
The union of the positioned advances and rendered glyph bounds, or Empty when no glyph participates in rendering.
MeasureRenderableBounds(ReadOnlySpan<char>, TextOptions)
Measures the full renderable bounds of the text in pixel units.
public static FontRectangle MeasureRenderableBounds(ReadOnlySpan<char> text, TextOptions options)
Parameters
textReadOnlySpan<char>The text.
optionsTextOptionsThe text options. WrappingLength controls wrapping; use
-1to disable wrapping.
Returns
- FontRectangle
The union of the logical advance rectangle and the rendered glyph bounds if the text was to be rendered.
MeasureRenderableBounds(ReadOnlySpan<ushort>, ReadOnlySpan<Vector2>, GlyphOptions)
Measures the full renderable bounds of positioned glyphs in pixel units.
public static FontRectangle MeasureRenderableBounds(ReadOnlySpan<ushort> glyphIds, ReadOnlySpan<Vector2> points, GlyphOptions options)
Parameters
glyphIdsReadOnlySpan<ushort>The glyph identifiers.
pointsReadOnlySpan<Vector2>The absolute glyph origins in pixel units.
optionsGlyphOptionsThe glyph options, including the font and layout mode.
Returns
- FontRectangle
The union of the advances placed at the supplied points and the rendered glyph bounds, or Empty when no glyph participates in rendering.
MeasureRenderableBounds(string, TextOptions)
Measures the full renderable bounds of the text in pixel units.
public static FontRectangle MeasureRenderableBounds(string text, TextOptions options)
Parameters
textstringThe text.
optionsTextOptionsThe text options. WrappingLength controls wrapping; use
-1to disable wrapping.
Returns
- FontRectangle
The union of the logical advance rectangle and the rendered glyph bounds if the text was to be rendered.
MeasureRenderableBounds(ushort, GlyphOptions)
Measures the full renderable bounds of a single glyph, identified by its glyph id, in pixel units.
public static FontRectangle MeasureRenderableBounds(ushort glyphId, GlyphOptions options)
Parameters
glyphIdushortThe glyph identifier within the font face referenced by
options.optionsGlyphOptionsThe glyph options, including the font, origin, and layout mode.
Returns
- FontRectangle
The union of the advance placed at Origin and the rendered bounds of the glyph if it was to be rendered, or Empty when the font does not contain the glyph or the glyph never renders.
Remarks
The bounds are computed directly from the font's cached per-glyph metrics without decoding outlines or running the layout engine.