ddn.cti.text.bidi

ddn.cti.text.bidi — the bidi role.

A paragraph of text to one embedding level per code point: the UAX #9 "resolves the levels" step (FriBidi's and SheenBidi's job, ICU's ubidi), not the reordering. The engine derives visual order from the levels (and reorders properly, rather than reversing every odd run).

An implementor is a struct mirroring this surface, proven by one static assert(isBidi!MyBidi);.

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

  • levels fills outBuf with one UAX #9 level byte per code

    point of paragraph and returns {required, written} with the shared capacity protocol: on a capacity miss (required > outBuf.length) nothing is written; on completion written == required. The resolved base direction travels in the payload whatever the capacity outcome.

  • A requested BidiBase.AUTO resolves per UAX #9 P2/P3 (first

    strong character); LTR/RTL force the paragraph level. The result's base is the resolved direction.

  • INVALID_INPUT for a malformed request, backend failures as

    errors — never as a zero count. Thread safety: one thread at a time per resolver; a resolver may be stateless and copyable.

Inspiration: FriBidi fribidi_get_par_embedding_levels_ex: levels per code point with an explicit base. SheenBidi SBParagraph: the same shape in a small C API. ICU ubidi_setPara / ubidi_getLevels: levels and resolved paragraph direction. DirectWrite IDWriteTextAnalyzer::AnalyzeBidi: levels through a sink, which is why the level array is a caller buffer here.

Types 3

The requested base direction of a paragraph. AUTO follows UAX #9 P2/P3 (first strong character); the resolved direction comes back in LevelsResult.

AUTOResolve from the first strong character (UAX #9 P2/P3).
LTRForce left to right.
RTLForce right to left.

The capacity protocol of levels plus the resolved base direction (doc/DDN-CTI.md section 9.3).

Fields
size_t requiredLevel bytes the paragraph needs; `> outBuf.length` on a capacity miss, where nothing is written.
size_t writtenLevel bytes written; equals `required` on completion, 0 on a capacity miss.
Direction baseThe resolved base direction.
structBidiRef

Reference signatures of a bidi resolver. Bodiless on purpose: never instantiated, only compared against with implements (through isBidi).

Fields
string nameImplementor name for logs and conformance tables, e.g. `"fribidi"`; empty in the reference.
Methods
Result!(LevelsResult, TextError) levels(const(dchar)[] paragraph, BidiBase base, scope ubyte[] outBuf) @safe nothrow @nogcResolves one paragraph into UAX #9 embedding levels.