ddn.cti.text.font_source

ddn.cti.text.font_source — the font source role.

Where fonts come from and which one answers a request: the description-to-face match (fontconfig's FcFontMatch), the coverage-aware fallback the engine's loop runs on (matchText), the ordered candidate list and the family enumeration. Neutral between a system database (fontconfig), a collection (DirectWrite) and a directory scan (a pure D provider).

ProviderHandle retains optional native contexts independently of the source. Providers must retain every native parent needed by a lease and test that native lifetime; synthetic tests alone are not proof of a native library's resource behavior.

The source is injected by the application (which knows the concrete implementor); the reference declares no factory. An implementor is a struct mirroring this surface, proven by one static assert(isFontSource!MySource);.

Semantics the checker cannot enforce (doc/DDN-CTI.md section 9.2):

  • match returns the best face for the description or

    NO_MATCH when nothing matches at all.

  • matchText returns the face that covers the first covered

    code points of text; covered is at least 1 for non-empty text, so a retry loop always advances. The coverage is a hint to the engine: it is not permission to split a grapheme or a contextual shaping span, and the engine advances over missing coverage through explicit notdef handling rather than retrying forever.

  • candidates calls the sink once per candidate in fallback

    order (the primary match first) as far as the implementor knows the order, and reports complete: a platform without a full list answers false with what it has. families calls the sink once per family name.

  • Results carry portable owned bytes or path, face index,

    resolved description and stable identity (FontMatch). The optional same-provider handle is a tagged, lifetime-retaining opaque lease (ProviderHandle): valid while any lease copy is alive, independently of the source. Its identity tag is a provider-defined type, not a name hash or untyped integer interpreted by an unrelated loader.

  • Results remain valid while a consumer holds the match or its

    lease; the source cannot invalidate them by closing itself. The source is moved, never copied; one thread at a time.

Inspiration: fontconfig FcFontMatch and FcFontSort with a charset: the description-to-file match and coverage-aware fallback. DirectWrite IDWriteFontFallback::MapCharacters: the "font for the start of this text, and how many code units it covers" shape that matchText follows. Android AFontMatcher_match with its run length: the same shape in a plain C API. Core Text CTFontCreateForString and the cascade list: fallback that returns a font object, the reason FontMatch can carry a provider lease next to the portable path or bytes. fontconfig FcFontSort and the Core Text cascade list: the ordered candidates list; platforms without one return what they have and say so through complete. Skia SkFontMgr::matchFamilyStyleCharacter, Pango PangoFontset: the neutral layers that confirm the operations.

Types 1

Reference signatures of a font source. Bodiless on purpose: never instantiated, only compared against with implements (through isFontSource).

Fields
string nameImplementor name for logs and conformance tables, e.g. `"fontconfig"`; empty in the reference.
Methods
Result!(FontMatch, TextError) match(in FontDescription desc) @safe nothrow;The best face for a description.
Result!(FontMatch, TextError) matchText(in FontDescription desc, const(dchar)[] text, out size_t covered) @safe nothrow;The face that covers the start of a piece of text, and how much of it: the engine's fallback step.
Status!TextError candidates(in FontDescription desc, scope void delegate(in FontMatch) @safe nothrow sink, out bool complete) @safe nothrow;The faces that could serve a description, in fallback order.
Status!TextError families(scope void delegate(const(char)[] family) @safe nothrow sink) @safe nothrow;The family names available.