TPDFContentMeasureTextEvent

Data types, content stream editing

Description

TPDFContentMeasureTextEvent is the measurement hook of TPDFContentStateTracker, exposed there as OnMeasureText. The tracker calls it for every string a text-showing operator produces, adds the returned displacement to the text matrix, and records the result in TextAdvanceX, TextAdvanceY and TextAdvanceResolved.

The tracker also calls the handler once after a Tf with an empty Text to resolve the writing mode, so a handler must answer that probe. Vertical writing is reported as WritingMode 1, and kerning numbers inside a TJ array are applied by the tracker rather than passed to the handler.

Syntax

Delphi

TPDFContentMeasureTextEvent = Function(
  Const State: TPDFContentGraphicsState; Const Text: AnsiString;
  Out DisplacementX, DisplacementY: Double;
  Out WritingMode: Integer): Boolean Of Object;

Parameters

StateEffective graphics state at the instruction, including the font resource and scope, font size, CharSpacing, WordSpacing, HorizontalScaling and the current text matrix
TextThe string bytes to measure in the font's own encoding, or an empty string for the writing-mode probe that follows Tf
DisplacementXOut parameter: horizontal advance to add to the text matrix, in text space
DisplacementYOut parameter: vertical advance to add to the text matrix, in text space
WritingModeOut parameter: 0 for horizontal writing, 1 for vertical writing

Return values

TrueThe measurement succeeded; the advance is marked resolved and the displacement is concatenated into the text matrix
FalseThe advance is unknown; TextAdvanceResolved becomes False and the text matrix is left unchanged

Remarks

The tracker concatenates the displacement verbatim. The library's font-metrics implementation (TPDFPageContentFontMetrics.MeasureText) folds CharSpacing, WordSpacing and HorizontalScaling into what it returns, and a replacement handler has to do the same to keep advances consistent.

A WritingMode outside 0 and 1 leaves the current writing mode unchanged, and the probe after Tf accepts only those two values.

With no handler assigned the tracker cannot resolve text advances at all and leaves TextAdvanceResolved False.

See also

TPDFContentStateTracker, TraceGraphicsStates, TPDFContentProgram, GetTextRuns