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.
optionsare 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; theface outlives the font; the font is moved, never copied. A new pixel size or option set is a new font.
rasterizewrites one glyph intooutBufand reports thecomplete geometry for the same glyph, format, options and subpixel offset — including the required byte count — in the success payload. When
required > outBuf.lengthnothing is written; otherwiseoutBuf[0 .. required]holds the pixels. Success uses the requested format; no silentA1/A8substitution.UNSUPPORTEDfor a format the face cannot produce (checkcapabilitiesfirst),INVALID_GLYPHfor a glyph id the face does not have.glyphOutlinewalks one glyph's outline through the sink;an empty outline is a success that invokes nothing,
UNSUPPORTEDmeans the face has no outlines at all (FontCapability.OUTLINESabsent),IO/PROVIDER_ERRORare backend failures. Empty glyphs, unavailable outlines and backend errors are three different answers.- Thread safety: one thread at a time per font.
metricsandglyphMetricsare reads;rasterizeandglyphOutlinemay 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
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.
One OpenType variation axis setting of a font (FontCapability.VARIATIONS).
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.
Reference signatures of a font over faces of type FaceT. Bodiless on purpose: never instantiated, only compared against with implements (through isFont).
Parameters
F | the implementor type (Self). |
FaceT | the face type the font is created over. |
string nameImplementor name for logs and conformance tables; empty in the reference.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.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
True when F implements the font role over faces of type FaceT.
Parameters
F | the implementor type. |
FaceT | the face type. |