ddn.cti.text.shaper

ddn.cti.text.shaper — the shaper role.

One run of text in one font to positioned glyphs in visual order: the field's term for shaping (HarfBuzz, DirectWrite, Core Text), the run as its unit, and the shaped glyph as its output element.

The reference is a template over the implementor's Self and the font type it shapes with: create fills an out S, the factory convention of doc/DDN-CTI.md section 9.1. An implementor is a struct mirroring this surface, proven by one static assert(isShaper!(MyShaper, MyFont));.

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

  • One shaper per font; the font's tables are parsed once in

    create, and the font outlives the shaper. The shaper is moved, never copied.

  • shape fills outBuf with the run's glyphs in visual order

    and returns {required, written}: on a capacity miss (required > outBuf.length) it writes nothing and reports the required count; on completion written == required, including zero. Backend failure is an error alternative, never a zero count. A valid empty output for non-empty text is required == 0, distinct from failure. The engine sizes its buffer from required and retries within its glyph budget — no pre-shaping glyph-count estimate is a correctness bound.

  • Clusters index UTF-32 code points of TextRun.text; all

    glyphs of one cluster carry the cluster's first code point index; cluster values are monotonic in visual order (non-decreasing LTR, non-increasing RTL).

  • Advances and offsets are 26.6 at the font's pixel size.
  • direction, script, language and features are inputs

    an implementor may honour or ignore; which of them it honours is reported in its capability conformance, never silently represented as full shaping support.

  • Empty runs succeed with zero required/written counts.

    INVALID_INPUT is for contradictory runs, UNSUPPORTED for a direction/script the implementor cannot shape, LIMIT/ALLOCATION_FAILED/PROVIDER_ERROR for backend failures. Thread safety: one thread at a time per shaper.

Inspiration: HarfBuzz hb_buffer_t and hb_shape: text, direction, script, language and features in; glyph infos and positions out; cluster values monotonic in visual order. DirectWrite IDWriteTextAnalyzer::GetGlyphs and GetGlyphPlacements: the caller buffer that reports the count it needed, and the separation of shaping from font fallback. Core Text CTRun: advances and string indices per run; the reason script is an input an implementor may ignore. Blend2D BLGlyphBuffer: the minimal shaper, which is why features are a request and not a guarantee.

Types 4

structTextRun

One run of text with uniform properties: the unit a shaper consumes. text is in logical order.

Fields
const(dchar)[] textThe text, in logical order (UTF-32 code points).
Direction directionBase direction, already resolved by the bidi step.
Script scriptScript; the default `"Zzzz"` lets the shaper derive it from the text. Implementors may ignore it.
Language languageContent language. Implementors may ignore it.
const(Feature)[] featuresRequested OpenType features. Implementors may ignore them.

One positioned glyph of a shaped run, in visual (display) order.

Fields
GlyphId glyphIdThe glyph in the shaping font.
uint clusterIndex in code points of the source cluster within the run's text, so a selection or caret maps back to the logical text.
Fixed26_6 xAdvanceHorizontal advance.
Fixed26_6 yAdvanceVertical advance (vertical layouts; zero for horizontal text).
Fixed26_6 xOffsetHorizontal offset of the glyph origin.
Fixed26_6 yOffsetVertical offset of the glyph origin.

The capacity protocol of shape: how many glyphs the run needs and how many were written (doc/DDN-CTI.md section 9.3).

Fields
size_t requiredGlyphs the run needs; `> outBuf.length` on a capacity miss, where nothing is written.
size_t writtenGlyphs written; equals `required` on completion, 0 on a capacity miss.
structShaperRef(S, FontT)

Reference signatures of a shaper over fonts of type FontT. Bodiless on purpose: never instantiated, only compared against with implements (through isShaper).

Parameters

Sthe implementor type (Self).
FontTthe font type the shaper is created over.
Fields
string nameImplementor name for logs and conformance tables, e.g. `"harfbuzz"`; empty in the reference.
Methods
Status!TextError create(out S shaper, ref FontT font) static @safe nothrow;Creates a shaper over a font.
Result!(ShapeResult, TextError) shape(in TextRun run, scope ShapedGlyph[] outBuf) @safe nothrow @nogcShapes one run into a caller buffer.

Templates 1

tmplisShaper(S, FontT)

True when S implements the shaper role over fonts of type FontT.

Parameters

Sthe implementor type.
FontTthe font type.