HPDFShapeHeadlessTextSpan

function HPDFShapeHeadlessTextSpan(const Context: UnicodeString;
  FirstUnit, UnitCount: Integer; const FontBytes: SysUtils.TBytes;
  MaximumGlyphs: Integer; CancellationToken: THPDFCancellationToken;
  CharacterAdvance: Double = 0; WordAdvance: Double = 0;
  ParagraphDirection: THPDFHeadlessTextDirection = htdAuto): THPDFHeadlessShapedGlyphs;

Shapes only a selected UTF-16 span with the caller's actual OpenType font whilst retaining the complete surrounding paragraph as HarfBuzz pre-context and post-context

FirstUnit is a zero-based UTF-16 offset and UnitCount is a UTF-16 length; neither boundary may split a surrogate pair, and a span of zero length returns no glyphs

FriBidi resolves embedding levels from the complete paragraph; HarfBuzz receives the resolved script and shapes the selected items within each visual run, preserving Arabic joining forms and mirrored punctuation

Returned SourceOffset values are relative to the selected span, UnicodeText preserves every actual selected cluster, and glyph advances and offsets use 1000-unit font coordinates

CharacterAdvance applies once per shaped cluster apart from a cluster containing only Unicode directional controls; WordAdvance applies to a U+0020 cluster, and both must be finite and use the same coordinates as Advance

ParagraphDirection may preserve an existing left-to-right or right-to-left paragraph when shaping a physical wrapped line whose first strong character differs from that of the original paragraph

The existing input and glyph budgets, font coverage checks, the cancellation token and native runtime dependency requirements also apply to this function

A partial span retains joining context but does not independently position a differently styled combining mark against a base glyph from another font; use full cluster shaping when a single font covers the entire cluster

See also HPDFShapeHeadlessText, HPDFResolveHeadlessTextOrder and contextual rich text appearances