ddn.cti.text.font

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

A face at a pixel size: scaled metrics, per-glyph metrics, per-glyph raster into a caller buffer, and glyph outlines. In typography and in Skia, cairo, Blend2D and Core Text a face at a size is a font.

The reference is a template over the implementor's Self and the associated face type: FontRef!(F, Face) declares alias Face and create fills an out F, the factory convention of doc/DDN-CTI.md section 9.1. The face accessor is mandatory so any shaper can reach the portable bytes and face index without a native fast path. An implementor is a struct mirroring this surface, proven by one static assert(isFont!(MyFont, MyFace));.

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

  • Units: metrics and offsets are 26.6 pixels (Fixed26_6) at the font's pixel size; a native library's 26.6

    values are copied as they are. options are hints an implementor may ignore, but anything that influences metrics or raster (variations, hinting, subpixel positioning) participates in cache keys.

  • face() is read-only borrowed for the font's lifetime; the

    face outlives the font; the font is moved, never copied. A new pixel size or option set is a new font.

  • rasterize writes one glyph into outBuf and reports the

    complete geometry for the same glyph, format, options and subpixel offset — including the required byte count — in the success payload. When required > outBuf.length nothing is written; otherwise outBuf[0 .. required] holds the pixels. Success uses the requested format; no silent A1/A8 substitution. UNSUPPORTED for a format the face cannot produce (check capabilities first), INVALID_GLYPH for a glyph id the face does not have.

  • glyphOutline walks one glyph's outline through the sink;

    an empty outline is a success that invokes nothing, UNSUPPORTED means the face has no outlines at all (FontCapability.OUTLINES absent), IO/PROVIDER_ERROR are backend failures. Empty glyphs, unavailable outlines and backend errors are three different answers.

  • Thread safety: one thread at a time per font. metrics and

    glyphMetrics are reads; rasterize and glyphOutline may use the implementor's scratch state.

Inspiration: Skia SkFont, cairo cairo_scaled_font_t, Blend2D BLFont, Core Text CTFont: the sized font as its own object over a face. FreeType FT_Set_Pixel_Sizes, FT_Load_Glyph, FT_Render_Glyph: per-glyph metrics and raster, 26.6 units. stb_truetype stbtt_MakeGlyphBitmapSubpixel: raster into a caller buffer with a subpixel offset. DirectWrite IDWriteGlyphRunAnalysis: the reason raster is a request with options, and hinting is a hint the implementor may ignore. libschrift sft_render: raster of one glyph into a caller image, which every library can do; its lack of outlines is why glyphOutline answers UNSUPPORTED behind capabilities. FreeType FT_Outline_Decompose, Core Text CGPathApply, DirectWrite IDWriteGeometrySink: the sink protocol of glyphOutline.

Types 4

enumHinting : ubyte

How the grid is fitted: the typographic word for hinting. A hint: an implementor that cannot honour it ignores it and says so in its conformance table.

DEFAULTThe implementor's default.
NONEUnhinted outlines.
LIGHTVertical-only hinting where supported.
FULLFull hinting where supported.
structVariation

One OpenType variation axis setting of a font (FontCapability.VARIATIONS).

Fields
char[4] tagThe four-character axis tag (`"wght"`, `"wdth"`).
Fixed16_16 valueThe axis coordinate, 16.16 fixed point (the OpenType `fvar` unit; `ddn.num.fixed_binary.Fixed16_16`).

Raster and metric options of a font. Every field is a hint an implementor may ignore; anything that changes metrics or raster output participates in cache keys, so a cache keyed on face identity, pixel size, options never mixes outputs.

Fields
Hinting hintingGrid fitting request.
bool subpixelPositioningRequest subpixel positioning (fractional advances honoured in raster offsets) where supported.
const(Variation)[] variationsVariation axis settings, in axis-tag order.
structFontRef(F, FaceT) if (isFontFace!FaceT)

Reference signatures of a font over faces of type FaceT. Bodiless on purpose: never instantiated, only compared against with implements (through isFont).

Parameters

Fthe implementor type (Self).
FaceTthe face type the font is created over.
Fields
string nameImplementor name for logs and conformance tables; empty in the reference.
Methods
Status!TextError create(out F font, ref FaceT face, uint pixelSize, in FontOptions options) static @safe nothrow;Creates a font over a face at a pixel size.
const(FaceT) face() ref return @safe nothrow @nogc const;The face the font was created over.
uint pixelSize() @safe nothrow @nogc const;Returns: The em size in pixels given to `create`.
FontOptions options() @safe nothrow @nogc const;Returns: The options given to `create`.
Result!(FontMetrics, TextError) metrics() @safe nothrow @nogc const;Returns: Ascent, descent and line gap at the pixel size, 26.6, or `UNSUPPORTED` when the face carries no such metrics.
Result!(GlyphMetrics, TextError) glyphMetrics(GlyphId glyph) @safe nothrow @nogc const;Params: glyph = the glyph id.
Result!(GlyphBitmap, TextError) rasterize(GlyphId glyph, BitmapFormat format, Fixed26_6 subpixel, scope ubyte[] outBuf) @safe nothrow @nogcRasterizes one glyph into a caller buffer.
Status!TextError glyphOutline(GlyphId glyph, scope OutlineSink sink) @safe nothrow;Walks one glyph's outline through a sink, in 26.6 at the pixel size.

Templates 1

tmplisFont(F, FaceT)

True when F implements the font role over faces of type FaceT.

Parameters

Fthe implementor type.
FaceTthe face type.