TPDFContentStateTracker

Content stream editing

Description

Applies parsed content instructions to one persistent effective graphics state and a complete q/Q stack

Reuse one tracker across consecutive TPDFContentProgram instances when a page stores its logical content sequence in several streams

Syntax

Delphi

TPDFContentStateTracker = Class Procedure Reset; Procedure ClearExtGStates; Procedure ClearXObjects; Procedure ClearFonts; Function RegisterExtGState(Const ResourceName: AnsiString; Dictionary: TPDFDictionary): Boolean; Function RegisterXObject(Const ResourceName: AnsiString; XObjectStream: TPDFStream; ObjectNumber: Integer = 0): Boolean; Function RegisterFont(Const ResourceName: AnsiString; FontObject: TPDFObject; ResourceScope: Integer): Boolean; Procedure InitializeForm(Const ParentState: TPDFContentGraphicsState; Const FormMatrix: TPDFContentMatrix; MatrixKnown: Boolean; BBoxLeft, BBoxBottom, BBoxRight, BBoxTop: Double); Procedure SetInitialClipBounds(Left, Bottom, Right, Top: Double); Procedure Apply(Inst: TPDFContentInstruction); Function Snapshot: TPDFContentGraphicsState; Property StackDepth: Integer; Property RestoreUnderflowCount: Integer; Property ResourceScope: Integer; Property OnMeasureText: TPDFContentMeasureTextEvent; End;

Remarks

RegisterExtGState validates and precompiles one external graphics-state dictionary so repeated gs operators do not rescan the PDF resource tree

RegisterXObject precompiles Image, Form and PostScript stream metadata so repeated Do operators resolve in constant-time name lookups; Form bounds use the form matrix, active CTM and all four /BBox corners

RegisterFont binds a resource name to its indirect object and resource scope so identical names in nested content do not collide

InitializeForm seeds a child tracker from the invoking state, concatenates the Form matrix and intersects clipping with the transformed /BBox

External parameters apply cumulatively and are included in complete q/Q save and restore operations

SetInitialClipBounds establishes the page boundary for standalone tracing; path construction is transformed immediately, W and W* remain pending until the next path-ending operator, and q/Q restores clipping without restoring the current path

OnMeasureText supplies exact font displacement and writing mode for Tj, TJ, ' and "; without it, text anchors remain unchanged and the snapshot reports unresolved displacement

RestoreUnderflowCount reports unmatched Q operators without corrupting the current state

The tracker owns no instructions or PDF dictionaries and may be reused after Reset