TextMeasurerExtensions Class

Extension methods for ITextMeasurer.

public static class TextMeasurerExtensions

Methods

NameDescription
Measure(ITextMeasurer, SceneText)Measures a text as the renderers draw it: its spans one after the other, with their fonts and their spacing.
Measure(ITextMeasurer, IEnumerable<SceneTextSpan>, SceneFont)Measures a text made of spans: the spans one after the other, on the same baseline.
Measure(ITextMeasurer, string, SceneFont, double, double)Measures a line of text with a letter spacing and a word spacing (SceneText.LetterSpacing, SceneText.WordSpacing), as the renderers draw it: see ITextMeasurer.Measure.
WithFontFamily(ITextMeasurer, string?)Returns a measurer whose family is fontFamily: it measures the texts that name no family (SceneFont.Family is null) as texts of that family. Use its ITextMeasurer.FontFamily as the family of the scene (Scene.FontFamily), so the renderers draw these texts with the family that measured them.

Measure overloads

Measure(ITextMeasurer, SceneText)

TextMeasurerExtensions.cs

Measures a text as the renderers draw it: its spans one after the other, with their fonts and their spacing.

public static TextMetrics Measure(this ITextMeasurer measurer, SceneText text)
Parameters
measurer ITextMeasurer
The measurer.
text SceneText
The text.
Returns

TextMetrics The sum of the widths of the spans, with their spacing, and the largest ascent and descent. A text fitted to a length (SceneText.TextLength), or whose spans are moved horizontally (SceneTextSpan.X, SceneTextSpan.Dx), has the width from the left of its leftmost span to the right of its rightmost one.

Measure(ITextMeasurer, IEnumerable<SceneTextSpan>, SceneFont)

TextMeasurerExtensions.cs

Measures a text made of spans: the spans one after the other, on the same baseline.

public static TextMetrics Measure(this ITextMeasurer measurer, IEnumerable<SceneTextSpan> spans, SceneFont font)
Parameters
measurer ITextMeasurer
The measurer.
spans IEnumerable<SceneTextSpan>
The spans.
font SceneFont
The font of the spans that set none.
Returns

TextMetrics The sum of the widths of the spans, with their spacing, and the largest ascent and descent.

Remarks

A span without spacing (SceneTextSpan.LetterSpacing, SceneTextSpan.WordSpacing) has none: measure a SceneText to apply its spacing.

Measure(ITextMeasurer, string, SceneFont, double, double)

TextMeasurerExtensions.cs

Measures a line of text with a letter spacing and a word spacing (SceneText.LetterSpacing, SceneText.WordSpacing), as the renderers draw it: see ITextMeasurer.Measure.

public static TextMetrics Measure(this ITextMeasurer measurer, string text, SceneFont font, double letterSpacing, double wordSpacing)
Parameters
measurer ITextMeasurer
The measurer.
text string
The text, on one line.
font SceneFont
The font.
letterSpacing double
The space added after each grapheme cluster, in pixels.
wordSpacing double
The space added to each space (U+0020 and U+00A0), in pixels.
Returns

TextMetrics The dimensions of the text: its width includes the spacing.

WithFontFamily(ITextMeasurer, string?)

TextMeasurerExtensions.cs

Returns a measurer whose family is fontFamily: it measures the texts that name no family (SceneFont.Family is null) as texts of that family. Use its ITextMeasurer.FontFamily as the family of the scene (Scene.FontFamily), so the renderers draw these texts with the family that measured them.

public static ITextMeasurer WithFontFamily(this ITextMeasurer measurer, string? fontFamily)

Parameters

measurer ITextMeasurer
The measurer.
fontFamily string?
The CSS font-family of the texts, or null to keep the family of the measurer.

Returns

ITextMeasurer The measurer.

Remarks

With fonts (ITextMeasurer.Fonts), the texts are measured with the first family of the list the fonts have, or their default family. A measurer without fonts, such as AfmTextMeasurer, measures every family with its own metrics.