Vixen
02b45cc4
csharp
public sealed class FontRegistry

What a font-family declaration names.

No guide page documents this yet — the page shows what the code says about itself.

Remarks

Registered rather than discovered. Nothing here walks the machine's font directories, and that is the decision rather than the gap: a game ships its fonts, and an interface whose text is laid out by whatever the operating system happened to have installed lays out differently on every machine it runs on. The editor will want a system enumerator; the runtime should not have one.

A face's weight and style are stated, not sniffed. They could be read from the file's OS/2 table, and that would be the same mistake in miniature as walking the font directories: a shipped asset whose metadata disagrees with what the designer meant would silently pick the wrong face, and the fix would be editing a binary. Registration says what the face is, so it is a line of the caller's code either way.

A declaration is a fallback chain, not a first-registered-wins list. Chain turns font-family: Inter, Noto Sans JP into both faces in that order and Cover hands each grapheme cluster to the first of them that can draw it — which is what CSS means by the list. Resolve answers the head of that chain, and is what something wanting one face for one purpose asks.

⚠ The chain ends in Fallbacks and then Default, so a string can still reach .notdef. Nothing here synthesises a glyph or goes looking on the machine: if no registered face has the code point, the primary draws its .notdef box. That is the honest outcome and a visible one, which is the point — a silent blank would look like a layout bug.

Fields and properties (6)

  • public const int RegularWeight

    The weight font-weight: normal names, and what a face registered without one gets.

  • public const int BoldWeight

    The weight font-weight: bold names.

  • public FontFace? Default

    The face used when a declaration names nothing that is registered.

  • public int Count

    How many families are registered.

  • public int Revision

    Bumped whenever anything registered here changes.

  • public IReadOnlyList<FontFace> Fallbacks

    The faces tried after everything a declaration names, in order.

Methods (6)

  • public void Register(string family, FontFace font, int weight = 400, FontStyle style = Normal)

    Registers a face under a family name.

  • public void AddFallback(FontFace font)

    Adds a face to the end of the chain every declaration falls back to.

  • public FontFace? Resolve(string? declaration, int weight = 400, FontStyle style = Normal)

    The face a font-family declaration resolves to.

  • public void Chain(string? declaration, int weight, FontStyle style, List<FontFace> into)

    The whole fallback chain a font-family declaration names.

  • public static void Cover(string text, IReadOnlyList<FontFace> chain, List<FontSpan> into)

    Splits a string into the stretches each face of a chain draws.

  • public IReadOnlyList<FontVariant> Variants(string family)

    The variants registered under a family name.

Used by (15)

  • FontsHelloUi
  • AdvancedFixtureVixen.Ui.Controls.Advanced.Tests
  • ControlFixtureVixen.Ui.Controls.Tests
  • ControlHarnessVixen.Ui.Controls.Tests
  • FontFallbackTestsVixen.Ui.Tests
  • FontRegistryTestsVixen.Ui.Tests
  • RasterizerTestsVixen.Ui.Testing.Tests
  • TextTestsVixen.Ui.Tests
  • TextWrapTestsVixen.Ui.Tests
  • UiDocumentVixen.Ui
  • UiElementVixen.Ui
  • ChromeFixtureVixen.Editor.Ui.Tests
  • FontsVixen.Editor.App
  • KeyChordVixen.Editor.Ui
  • ViewFixtureVixen.Editor.NodeGraph.Tests