PeachDrawing.Text

PeachDrawing.Text

FontSet Class

The fonts a piece of text can be set in: the fonts installed on the machine, plus the ones added to this set.

public sealed class FontSet

Inheritance System.Object → FontSet

Remarks

A set starts out able to see the installed fonts. A font added under the name of an installed family joins that family for this set only: it takes the place of the face with the same weight, slant, width and code point ranges, and the family’s other faces stay. Two sets never share the fonts added to them, so two callers can register different data under the same family name without one seeing the other’s.

A set is not safe for concurrent use: matching and searching fill caches that are private to it, so give each thread its own set or serialize the calls. What the machine has installed is scanned once per process and is safe to share.

Add the fonts before the set is used to match. An answer the set has already given, a match or the family found for a character, is remembered and does not change when a font is added afterwards. That keeps the measuring and the drawing of one piece of text from disagreeing about which face it is set in; a set made after the fonts are added sees them all.

Constructors  
FontSet() Creates a set that sees the installed fonts and nothing else yet.
Properties  
InstalledFamilyNames The names of the font families installed on this machine, one for each family the operating system’s fonts declare. The list is empty where fonts cannot be discovered, such as a browser or iOS.
Methods  
AddData(ReadOnlyMemory<byte>, AddOptions) Adds a font to the set.
AddFile(string, AddOptions) Adds a font that is read from a file.
AddStream(Stream, AddOptions) Adds a font that is read from a stream, which is read to its end and left open.
CreateFallback(TypefaceQuery) Makes the fallback a paragraph asks for when the typeface of a run has no glyph for a character: the face, in the family of this set that covers the character, that best matches query.
HasExplicitRanges(string) Whether any face of a family declares the code points it is used for (a unicode-range), which means text set in the family has to be resolved character by character rather than as a whole.
MatchOrFallback(string, TypefaceQuery) Finds the best face of a family for a query, with a last resort for a family the set does not have.
ResolveGeneric(GenericFamily, Func<string,bool>) Names a family for a generic family on this platform, as Chromium does.
TryFindCoveringFamily(Rune, EmojiPresentation, TypefaceFamily) Finds a family that can draw a character, for when none of the families a caller asked for can: the last-resort search of CSS Fonts 4 section 5.
TryFindFamily(string, TypefaceFamily) Looks a family up by name, ignoring case.
TryGetFontData(string, ReadOnlyMemory<byte>) Reads the data of an installed or added font by the font’s own name.