FontFaceTextMeasurer Class

Measures text by shaping it with a font of Meziantou.Framework.Fonts: every script, ligatures, kerning and the advances of the font are taken into account.

public sealed class FontFaceTextMeasurer : ITextMeasurer

Remarks

The text is split into runs of one script; each run is shaped in the direction of its first strong character.

Implements

Constructors

NameDescription
FontFaceTextMeasurer(FontFace, FontFace?, FontFace?, FontFace?, string?)Initializes a new instance of the FontFaceTextMeasurer class.
FontFaceTextMeasurer(FontFace, FontFace?, string?)Initializes a new instance of the FontFaceTextMeasurer class.
FontFaceTextMeasurer(SceneFontCollection)Initializes a new instance of the FontFaceTextMeasurer class that measures the text with the fonts of a collection.

FontFaceTextMeasurer overloads

FontFaceTextMeasurer(FontFace, FontFace?, FontFace?, FontFace?, string?)

FontFaceTextMeasurer.cs

Initializes a new instance of the FontFaceTextMeasurer class.

public FontFaceTextMeasurer(FontFace regular, FontFace? bold, FontFace? italic, FontFace? boldItalic, string? fontFamily = null)
Parameters
regular FontFace
The face of the regular text, loaded with FontLoader.
bold FontFace?
The face of the bold text, or null to measure bold text with regular.
italic FontFace?
The face of the italic text, or null to measure italic text with regular.
boldItalic FontFace?
The face of the bold italic text, or null to measure it with bold, then italic, then regular.
fontFamily string?
The CSS font-family of the text, or null for the family name of regular.
Remarks

The measurer has no FontFaceTextMeasurer.Fonts: each renderer draws the text with its own fonts. Use FontFaceTextMeasurer so the renderers draw with the fonts that measure.

FontFaceTextMeasurer(FontFace, FontFace?, string?)

FontFaceTextMeasurer.cs

Initializes a new instance of the FontFaceTextMeasurer class.

public FontFaceTextMeasurer(FontFace regular, FontFace? bold = null, string? fontFamily = null)
Parameters
regular FontFace
The face of the regular text, loaded with FontLoader.
bold FontFace?
The face of the bold text, or null to measure bold text with regular.
fontFamily string?
The CSS font-family of the text, or null for the family name of regular.

FontFaceTextMeasurer(SceneFontCollection)

FontFaceTextMeasurer.cs

Initializes a new instance of the FontFaceTextMeasurer class that measures the text with the fonts of a collection.

public FontFaceTextMeasurer(SceneFontCollection fonts)
Parameters
fonts SceneFontCollection
The fonts. A chart or a diagram sets them as the fonts of its scene, so the renderers draw the text with them.
Remarks

The family of a text is SceneFont.Family, or SceneFontCollection.DefaultFamily. The characters its face does not have are measured with the face that draws them (SceneFontCollection). The ascent and the descent are the ones of the face of the family.

Properties

NameDescription
FontFamilyGets the font family the measured text is drawn with, as a CSS font-family value.
FontsGets the fonts the text is measured with, or null when the measurer was created from faces of Meziantou.Framework.Fonts.

Gets the font family the measured text is drawn with, as a CSS font-family value.

public string FontFamily { get; }

Property value

string

Gets the fonts the text is measured with, or null when the measurer was created from faces of Meziantou.Framework.Fonts.

public SceneFontCollection? Fonts { get; }

Property value

SceneFontCollection?

Methods

NameDescription
Measure(string, SceneFont)Measures a line of text.
Measure(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.

Measure overloads

Measure(string, SceneFont)

FontFaceTextMeasurer.cs

Measures a line of text.

public TextMetrics Measure(string text, SceneFont font)
Parameters
text string
The text, on one line.
font SceneFont
The size, the weight and the style of the font.
Returns

TextMetrics The dimensions of the text.

Measure(string, SceneFont, double, double)

FontFaceTextMeasurer.cs

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

public TextMetrics Measure(string text, SceneFont font, double letterSpacing, double wordSpacing)
Parameters
text string
The text, on one line.
font SceneFont
The size, the weight and the style of the font.
letterSpacing double
The space added after each character, in pixels.
wordSpacing double
The space added after each space (U+0020 and U+00A0), in pixels.
Returns

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

Remarks

With a letter spacing, the text is shaped without its optional ligatures, and the spacing is added after each cluster of glyphs (a character with its marks, a ligature the script requires), as the renderers draw it.