ddn.cti.text.font_face

ddn.cti.text.font_face — the face role.

A size-less parsed font: one face of one file. Opening, glyph lookup, the bytes it came from, design-scale metrics and a stable identity for caches. Everything scaled — pixel size, metrics at a size, raster, outlines — belongs to the font role (ddn, cti, text, font).

The reference is a template over the implementor's Self: open fills an out T and returns Status!TextError, the factory convention of doc/DDN-CTI.md section 9.1 (the original by-value factory failed the supported compiler's move-only feasibility check). An implementor is a struct mirroring this surface, proven by one static assert(isFontFace!MyType);.

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

  • open parses the match's bytes or path and its

    faceIndex; the face retains or copies what it needs so the match may die first. BAD_FONT for malformed bytes, IO for unreadable paths, UNSUPPORTED for formats or face indices the implementor cannot handle.

  • glyphId returns GLYPH_NOTDEF for uncovered code points —

    a success, not an error.

  • bytes and faceIndex describe exactly the face that was

    opened; bytes is borrowed for the face's lifetime.

  • unitsPerEm and designMetrics answer UNSUPPORTED rather

    than invented values when the format carries no design scale; glyphCount is always defined (a parsed face knows its glyphs). capabilities reports what the implementor can do for this face; a member answers false/UNSUPPORTED rather than failing late when a capability is absent.

  • identity is equal for two faces of the same bytes and

    index; caches key on it.

  • Lifetime: non-copyable, moved only; nothing outlives its

    bytes. Thread safety: one thread at a time per face.

Inspiration: FreeType (FT_Face before FT_Set_Pixel_Sizes): opening from memory with a face index, FT_Get_Char_Index, FT_HAS_COLOR. Skia SkTypeface, cairo cairo_font_face_t, Blend2D BLFontFace, Core Text CGFont: the size-less face as its own object, and the face/font split this module and ddn.cti.text.font follow. DirectWrite IDWriteFontFace: a face that never carries a size. libschrift: the smallest implementor; it has no collections and no outlines, which is why capabilities exists, and no design-unit calls, which its adapter answers from the head table itself. HarfBuzz hb_face_create over a blob: the reason bytes exists, so any shaper can build its font object from any face.

Types 3

One optional capability of a face and its font role.

COLOR = 1 << 0`Font.rasterize` with `ARGB32` produces colour glyphs.
OUTLINES = 1 << 1`Font.glyphOutline` works for this face.
HINTING = 1 << 2`FontOptions.hinting` is honoured.
VARIATIONS = 1 << 3`FontOptions.variations` is honoured.
COLLECTIONS = 1 << 4Multi-face collections (`FontMatch.faceIndex`) are honoured.

The capability set reported by FontFaceRef.capabilities.

structFontFaceRef(T)

Reference signatures of a font face over implementor T. Bodiless on purpose: never instantiated, only compared against with implements (through isFontFace).

Parameters

Tthe implementor type (Self).
Fields
string nameImplementor name for logs and conformance tables, e.g. `"freetype"`; empty in the reference.
Methods
Status!TextError open(out T face, in FontMatch match) static @safe nothrow;Opens the face described by a match. The factory convention (`doc/DDN-CTI.md` section 9.1): the handle is filled through the `out` parameter and failure is a status.
GlyphId glyphId(dchar codePoint) @safe nothrow @nogc const;Maps a code point to a glyph id.
const(ubyte)[] bytes() return @safe nothrow @nogc const;The font file bytes the face was parsed from.
uint faceIndex() @safe nothrow @nogc const;Returns: The index of this face within its collection, 0 for a single-face file.
Result!(uint, TextError) unitsPerEm() @safe nothrow @nogc const;Returns: Font units per em (`head.unitsPerEm`), or `UNSUPPORTED` when the format carries no design scale — never an invented value.
Result!(DesignMetrics, TextError) designMetrics() @safe nothrow @nogc const;Returns: Ascent, descent, line gap and glyph bounding box in font design units, or `UNSUPPORTED` when the format carries none.
uint glyphCount() @safe nothrow @nogc const;Returns: The number of glyphs in the face (`maxp.numGlyphs`).
FontCapabilities capabilities() @safe nothrow @nogc const;Returns: The features this implementor provides for this face: `COLOR` when `Font.rasterize` with `ARGB32` produces colour, `OUTLINES` when `Font.glyphOutline` works, `HINTING` when `FontOptions.hi...
ulong identity() @safe nothrow @nogc const;Returns: A key equal for two faces of the same bytes and index; what caches key on.