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. shapefillsoutBufwith the run's glyphs in visual orderand returns
{required, written}: on a capacity miss (required > outBuf.length) it writes nothing and reports the required count; on completionwritten == required, including zero. Backend failure is an error alternative, never a zero count. A valid empty output for non-empty text isrequired == 0, distinct from failure. The engine sizes its buffer fromrequiredand retries within its glyph budget — no pre-shaping glyph-count estimate is a correctness bound.- Clusters index UTF-32 code points of
TextRun.text; allglyphs 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,languageandfeaturesare inputsan 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_INPUTis for contradictory runs,UNSUPPORTEDfor a direction/script the implementor cannot shape,LIMIT/ALLOCATION_FAILED/PROVIDER_ERRORfor 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
One run of text with uniform properties: the unit a shaper consumes. text is in logical order.
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.
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).
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.Reference signatures of a shaper over fonts of type FontT. Bodiless on purpose: never instantiated, only compared against with implements (through isShaper).
Parameters
S | the implementor type (Self). |
FontT | the font type the shaper is created over. |
string nameImplementor name for logs and conformance tables, e.g. `"harfbuzz"`; empty in the reference.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
True when S implements the shaper role over fonts of type FontT.
Parameters
S | the implementor type. |
FontT | the font type. |