TPDFContentGraphicsState

Data types

Description

TPDFContentGraphicsState is the effective graphics and text state in which one content-stream instruction executes. The record is declared in the unit PDFlibContentModel. TPDFContentProgram returns it from GetGraphicsState, TraceGraphicsStates and TraceGraphicsStatePairs, TPDFContentStateTracker returns it from Snapshot, and TPDFContentGraphicsStateArray is the dynamic array of these records. TPDFlib publishes the same record as TPDFlibContentGraphicsState and fills it in EnumPageContentStatesEx.

Which fields carry information depends on the call. GetGraphicsState, and the two trace functions when called without a tracker, use a new tracker that starts from the default graphics state and has no resources registered: the location fields stay zero or empty, XObjects and font objects stay unresolved, text advances stay unresolved and no initial clip exists. Passing a prepared TPDFContentStateTracker to a trace function continues its state and uses the resources registered on it. EnumPageContentStatesEx prepares the tracker with the page resources, the CropBox as initial clip and font metrics, and fills the location and Form traversal fields.

Resource names are stored without the leading slash, and colour operands as PDF source text. The *Known and *Resolved members state whether the value next to them was established; check them before relying on the value.

Syntax

TPDFContentGraphicsState= Record
  Layer: Integer;
  InstructionIndex: Integer;
  OperatorName: AnsiString;
  ContentDepth: Integer;
  ContentInvocationID: Integer;
  ParentContentInvocationID: Integer;
  ContentStreamObjectNumber: Integer;
  ParentXObjectResource: AnsiString;
  ParentXObjectObjectNumber: Integer;
  StackDepth: Integer;
  CTM: TPDFContentMatrix;
  XObjectResource: AnsiString;
  XObjectResolved: Boolean;
  XObjectKind: TPDFContentXObjectKind;
  XObjectObjectNumber: Integer;
  XObjectBoundsKnown: Boolean;
  XObjectBoundsExact: Boolean;
  XObjectMinX: Double;
  XObjectMinY: Double;
  XObjectMaxX: Double;
  XObjectMaxY: Double;
  FormMatrixKnown: Boolean;
  FormMatrix: TPDFContentMatrix;
  FormBBoxKnown: Boolean;
  FormBBoxLeft: Double;
  FormBBoxBottom: Double;
  FormBBoxRight: Double;
  FormBBoxTop: Double;
  FormHasOwnResources: Boolean;
  FormIsGroup: Boolean;
  FormIsTransparencyGroup: Boolean;
  FormIsIsolated: Boolean;
  FormIsKnockout: Boolean;
  FormIsReference: Boolean;
  FormTraversalStatus: TPDFContentFormTraversalStatus;
  FormDescendantCount: Integer;
  ClipBoundsKnown: Boolean;
  ClipBoundsExact: Boolean;
  ClipIsEmpty: Boolean;
  ClipMinX: Double;
  ClipMinY: Double;
  ClipMaxX: Double;
  ClipMaxY: Double;
  ClipPaths: TPDFContentClipPathArray;
  ClipPathsComplete: Boolean;
  MarkedContent: TPDFContentMarkedFrameArray;
  ClipRule: Integer;
  PendingClipRule: Integer;
  PathBoundsKnown: Boolean;
  PathIsRectangle: Boolean;
  PathMinX: Double;
  PathMinY: Double;
  PathMaxX: Double;
  PathMaxY: Double;
  PathSubpathCount: Integer;
  PathSegmentCount: Integer;
  // Page-space segments captured only for a path-painting instruction
  PaintedPathSegments: TPDFContentClipSegmentArray;
  CurrentPointKnown: Boolean;
  CurrentPointX: Double;
  CurrentPointY: Double;
  TextClipPending: Boolean;
  TextMatrix: TPDFContentMatrix;
  TextLineMatrix: TPDFContentMatrix;
  LineWidth: Double;
  LineCap: Integer;
  LineJoin: Integer;
  MiterLimit: Double;
  DashArray: AnsiString;
  DashPhase: Double;
  RenderingIntent: AnsiString;
  BlackPointCompensation: AnsiString;
  Flatness: Double;
  ExtGStateResource: AnsiString;
  StrokeOverprint: Boolean;
  FillOverprint: Boolean;
  OverprintMode: Integer;
  StrokeAdjustment: Boolean;
  BlendMode: AnsiString;
  SoftMask: AnsiString;
  StrokeAlpha: Double;
  FillAlpha: Double;
  AlphaIsShape: Boolean;
  TextKnockout: Boolean;
  Smoothness: Double;
  BlackGeneration: AnsiString;
  UndercolorRemoval: AnsiString;
  TransferFunction: AnsiString;
  Halftone: AnsiString;
  StrokeColorSpace: AnsiString;
  FillColorSpace: AnsiString;
  StrokeColor: AnsiString;
  FillColor: AnsiString;
  StrokePatternResource: AnsiString;
  FillPatternResource: AnsiString;
  ShadingResource: AnsiString;
  ActiveResources: TPDFDictionary;
  CharSpacing: Double;
  WordSpacing: Double;
  HorizontalScaling: Double;
  Leading: Double;
  FontResource: AnsiString;
  FontReference: AnsiString;
  FontObjectNumber: Integer;
  FontResourceScope: Integer;
  // A Type 3 font adds nothing to the clipping path in modes 4 to 7
  // (ISO 32000-2 9.3.6)
  FontIsType3: Boolean;
  FontSize: Double;
  WritingMode: Integer;
  WritingModeResolved: Boolean;
  TextAdvanceX: Double;
  TextAdvanceY: Double;
  TextAdvanceResolved: Boolean;
  TextRenderingMode: Integer;
  TextRise: Double;
  InTextObject: Boolean;
End;

Fields

LayerEnumPageContentStatesEx stores the one-based index of the page content layer that holds the instruction; 0 in snapshots of a bare TPDFContentProgram
InstructionIndexZero-based index of the instruction in its content stream
OperatorNameRaw operator token as written in the stream; unknown operators keep their token
ContentDepthForm nesting depth of the instruction: 0 for page content, one more for each Form level entered through a Do operator
ContentInvocationID, ParentContentInvocationIDIdentifier of the content stream invocation that holds the instruction and of the invocation that invoked it; page content has parent 0. The numbers are assigned per EnumPageContentStatesEx call
ContentStreamObjectNumberObject number of the stream that holds the instruction: the object number of the Form for Form content, and for a page layer the object number of its /Contents array entry, or 0 when /Contents is not an array
ParentXObjectResource, ParentXObjectObjectNumberResource name and object number of the Form XObject whose content holds the instruction; empty and 0 for page content
StackDepthNumber of q operators that are open, which is the depth of the saved-state stack
CTMCurrent transformation matrix in force, as a TPDFContentMatrix: the identity until a cm or a Form matrix is concatenated, and restored by Q to the value saved by the matching q. Coordinates described as page space below are operands mapped through CTM
XObjectResourceName of the XObject invoked by a Do instruction; empty for every other instruction
XObjectResolvedTrue when the name was registered with RegisterXObject; False leaves the other XObject fields empty
XObjectKindKind of the resolved XObject, a TPDFlibContentXObjectKind: cxkImage, cxkForm or cxkPostScript; cxkUnknown when the resource is unresolved or has another subtype
XObjectObjectNumberObject number of the XObject stream as passed to RegisterXObject; 0 when unresolved or not given
XObjectBoundsKnownTrue when the footprint of the XObject could be computed, which requires its matrix and its bounding box
XObjectBoundsExactTrue when the footprint is an axis-aligned rectangle; otherwise the bounds are conservative
XObjectMinX, XObjectMinY, XObjectMaxX, XObjectMaxYAxis-aligned bounds of the XObject footprint in page space: the unit square of an image or the /BBox of a Form, mapped through the Form matrix where one applies and through CTM
FormMatrixKnown, FormMatrixWhether the /Matrix of a Form XObject is known, and the matrix; a Form without /Matrix has the identity
FormBBoxKnown, FormBBoxLeft, FormBBoxBottom, FormBBoxRight, FormBBoxTopWhether the /BBox of a Form XObject is a readable array of four numbers, and its edges normalised so that left is not greater than right and bottom is not greater than top
FormHasOwnResourcesTrue when the Form stream carries a /Resources dictionary
FormIsGroup, FormIsTransparencyGroupWhether the Form has a /Group dictionary and whether its /S entry is /Transparency
FormIsIsolated, FormIsKnockoutThe /I and /K entries of a transparency group; False when the group is absent or does not set the entry to true
FormIsReferenceTrue when the Form XObject carries a /Ref dictionary
FormTraversalStatusHow EnumPageContentStatesEx handled the Form invoked by a Do instruction, a TPDFlibContentFormTraversalStatus; ftsNotApplicable for every other instruction and in every snapshot of a bare TPDFContentProgram
FormDescendantCountNumber of snapshots EnumPageContentStatesEx emitted for the content of the invoked Form; 0 when the Form was not enumerated
ClipBoundsKnownTrue once a clip bound exists: after SetInitialClipBounds, after InitializeForm or after the first applied clip
ClipBoundsExactTrue while the effective clip is an axis-aligned rectangle; a clip by any other path or a text clip makes it False
ClipIsEmptyTrue when the bounds enclose no area, so nothing is visible
ClipMinX, ClipMinY, ClipMaxX, ClipMaxYAxis-aligned bounds of the effective clip in page space, the intersection of all components applied so far
ClipPathsClip components in the order they were applied, each a TPDFContentClipPath: the initial page bounds, a path with its fill rule and segments, the /BBox of a Form, or a marker for a text clip
ClipPathsCompleteTrue only when ClipPaths lists the whole clip. It is False after a text clip, when the 1024-component limit was reached, and in every snapshot of a tracker that never received initial bounds
MarkedContentMarked-content frames open at the instruction, outermost first. Each TPDFContentMarkedFrame holds its tag, the index of the opening BMC or BDC, the property operand and its /MCID
ClipRuleFill rule of the last clip applied: 0 for nonzero winding (W), 1 for even-odd (W*); -1 before any clip
PendingClipRuleFill rule of a W or W* that waits for the next path-ending operator: 0 or 1; -1 when none is pending
PathBoundsKnownTrue once a line, a curve or re added a point to the current path; a lone m gives a current point but no bounds
PathIsRectangleTrue when the current path consists of one re operator whose corners map to an axis-aligned rectangle
PathMinX, PathMinY, PathMaxX, PathMaxYBounds of the current path in page space; a curve contributes its end points and its interior extrema, not its control points
PathSubpathCount, PathSegmentCountNumber of subpaths started by m or re, and number of segments appended by l, c, v, y and h, in the current path
PaintedPathSegmentsSegments of the path that a path-painting instruction is about to paint, in page space as a TPDFContentClipSegmentArray; filled only in snapshots taken before the instruction
CurrentPointKnown, CurrentPointX, CurrentPointYWhether the current path has a current point, and its position in page space
TextClipPendingTrue after text was shown in rendering mode 4 to 7 with a font that is not Type 3, until ET turns the glyphs into a clip component
TextMatrix, TextLineMatrixText matrix and text-line matrix of the current text object, both TPDFContentMatrix; BT resets both to the identity and Q does not restore them
LineWidthLine width from w or /LW; 1 by default
LineCap, LineJoinLine cap and line join style from J and j or /LC and /LJ, rounded and limited to 0 to 2; 0 by default
MiterLimitMiter limit from M or /ML; 10 by default
DashArray, DashPhaseDash array of d or /D as PDF source text, and the dash phase; [] and 0 by default
RenderingIntentName from ri or /RI; RelativeColorimetric by default
BlackPointCompensation/UseBlackPtComp name of the last gs that carries it; Default by default
FlatnessFlatness from i or /FL; 1 by default, and /FL is limited to 0 to 100
ExtGStateResourceResource name of the most recent gs operator; empty until the first one
StrokeOverprint, FillOverprintOverprint flags /OP and /op of the last gs that carries them; a gs with /OP but no op sets both
OverprintModeOverprint mode /OPM, rounded and limited to 0 or 1
StrokeAdjustmentStroke adjustment flag /SA
BlendModeBlend mode from /BM: the first supported name of a name or an array; Normal by default, and Compatible is reported as Normal
SoftMaskSoft mask from /SMask as a name, an indirect reference or a marker for a direct dictionary, stream or array; None by default
StrokeAlpha, FillAlphaStroking and nonstroking constant alpha /CA and /ca, limited to 0 to 1; 1 by default
AlphaIsShape, TextKnockoutAlpha source flag /AIS and text knockout flag /TK; text knockout is True by default
SmoothnessSmoothness from /SM, limited to 0 to 1
BlackGeneration, UndercolorRemoval, TransferFunctionBlack generation, undercolor removal and transfer function from /BG2 or /BG, /UCR2 or /UCR and /TR2 or /TR, in the same form as SoftMask
HalftoneHalftone from /HT, in the same form as SoftMask
StrokeColorSpace, FillColorSpaceName set by CS and cs, or the device space implied by G, g, RG, rg, K and k; DeviceGray by default
StrokeColor, FillColorColour operands as PDF source text, separated by single spaces. A colour space operator resets the colour to the initial value of the space, for example 0 0 0 1 for DeviceCMYK
StrokePatternResource, FillPatternResourceName of the pattern that a SCN or scn operator ends with; empty when the operator ends with no name and after a colour space or plain colour operator
ShadingResourceName of the shading in a sh instruction; empty for every other instruction
ActiveResourcesResource dictionary of the content being traced, as assigned to the ActiveResources property of the tracker; Nil when none was assigned
CharSpacing, WordSpacingCharacter spacing from Tc and word spacing from Tw; both are also set by the " operator. 0 by default
HorizontalScalingHorizontal scaling from Tz, in percent; 100 by default
LeadingText leading from TL; TD sets it to the negated vertical operand; 0 by default
FontResourceName of the font selected by Tf; empty until a font is selected, and also after a gs with a /Font entry
FontReferenceIndirect reference to the selected font as PDF source text, from the fonts registered with RegisterFont or from a /Font entry of a gs; empty when unknown
FontObjectNumberObject number of the selected font; 0 when unknown
FontResourceScopeResource scope of the selected font: the scope stored by RegisterFont, or the ResourceScope of the tracker at the Tf; 0 after a gs with a /Font entry
FontIsType3True when the selected font has /Subtype /Type3; such a font adds nothing to the clip in rendering mode 4 to 7
FontSizeFont size from Tf or from a /Font entry of a gs; 0 until a size is set
WritingMode, WritingModeResolvedWriting mode reported by the OnMeasureText callback, 0 for horizontal or 1 for vertical, and whether the callback supplied it
TextAdvanceX, TextAdvanceYDisplacement of the current show-text instruction in text space, accumulated over its strings and the adjustments of a TJ array; 0 for every other instruction and in every snapshot taken before the instruction
TextAdvanceResolvedTrue when OnMeasureText measured every string of the current show-text instruction; False without a callback
TextRenderingModeText rendering mode from Tr, rounded and limited to 0 to 7; 0 by default
TextRiseText rise from Ts; 0 by default
InTextObjectTrue between BT and the matching ET; Q does not restore it

Remarks

A snapshot taken before an instruction (AfterInstruction is False) describes the Do target and the shading of that instruction and carries PaintedPathSegments at a path-painting instruction. A snapshot taken after it describes the state the instruction left behind, with the text advance a show-text instruction produced.

The tracker keeps TextMatrix, TextLineMatrix and InTextObject across a Q, and neither q nor Q saves or restores the current path.

LineCap, LineJoin and TextRenderingMode are limited to their valid ranges. The same holds for the numeric entries of a gs dictionary: line width becomes non-negative, the miter limit at least 1, overprint mode 0 or 1, flatness 0 to 100, and smoothness and both alpha constants 0 to 1. LineWidth, MiterLimit and Flatness set by the operators w, M and i are stored as written.

At most 1024 clip components and 256 marked-content frames are kept. A clip component beyond the limit is dropped and sets ClipPathsComplete to False; a marked-content frame beyond the limit is only counted.

ActiveResources is a reference to a dictionary assigned to the tracker; the record does not own it. The tracker copies ClipPaths and MarkedContent before it appends to them, so a snapshot already handed out keeps its arrays.

See also

TPDFlibContentGraphicsState, TPDFContentGraphicsStateArray, TPDFContentStateTracker, TPDFContentProgram, GetGraphicsState, EnumPageContentStatesEx, TPDFContentMatrix, TPDFContentClipSegmentArray