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
| Layer | EnumPageContentStatesEx stores the one-based index of the page content layer that holds the instruction; 0 in snapshots of a bare TPDFContentProgram |
|---|---|
| InstructionIndex | Zero-based index of the instruction in its content stream |
| OperatorName | Raw operator token as written in the stream; unknown operators keep their token |
| ContentDepth | Form nesting depth of the instruction: 0 for page content, one more for each Form level entered through a Do operator |
| ContentInvocationID, ParentContentInvocationID | Identifier 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 |
| ContentStreamObjectNumber | Object 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, ParentXObjectObjectNumber | Resource name and object number of the Form XObject whose content holds the instruction; empty and 0 for page content |
| StackDepth | Number of q operators that are open, which is the depth of the saved-state stack |
| CTM | Current 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 |
| XObjectResource | Name of the XObject invoked by a Do instruction; empty for every other instruction |
| XObjectResolved | True when the name was registered with RegisterXObject; False leaves the other XObject fields empty |
| XObjectKind | Kind of the resolved XObject, a TPDFlibContentXObjectKind: cxkImage, cxkForm or cxkPostScript; cxkUnknown when the resource is unresolved or has another subtype |
| XObjectObjectNumber | Object number of the XObject stream as passed to RegisterXObject; 0 when unresolved or not given |
| XObjectBoundsKnown | True when the footprint of the XObject could be computed, which requires its matrix and its bounding box |
| XObjectBoundsExact | True when the footprint is an axis-aligned rectangle; otherwise the bounds are conservative |
| XObjectMinX, XObjectMinY, XObjectMaxX, XObjectMaxY | Axis-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, FormMatrix | Whether the /Matrix of a Form XObject is known, and the matrix; a Form without /Matrix has the identity |
| FormBBoxKnown, FormBBoxLeft, FormBBoxBottom, FormBBoxRight, FormBBoxTop | Whether 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 |
| FormHasOwnResources | True when the Form stream carries a /Resources dictionary |
| FormIsGroup, FormIsTransparencyGroup | Whether the Form has a /Group dictionary and whether its /S entry is /Transparency |
| FormIsIsolated, FormIsKnockout | The /I and /K entries of a transparency group; False when the group is absent or does not set the entry to true |
| FormIsReference | True when the Form XObject carries a /Ref dictionary |
| FormTraversalStatus | How EnumPageContentStatesEx handled the Form invoked by a Do instruction, a TPDFlibContentFormTraversalStatus; ftsNotApplicable for every other instruction and in every snapshot of a bare TPDFContentProgram |
| FormDescendantCount | Number of snapshots EnumPageContentStatesEx emitted for the content of the invoked Form; 0 when the Form was not enumerated |
| ClipBoundsKnown | True once a clip bound exists: after SetInitialClipBounds, after InitializeForm or after the first applied clip |
| ClipBoundsExact | True while the effective clip is an axis-aligned rectangle; a clip by any other path or a text clip makes it False |
| ClipIsEmpty | True when the bounds enclose no area, so nothing is visible |
| ClipMinX, ClipMinY, ClipMaxX, ClipMaxY | Axis-aligned bounds of the effective clip in page space, the intersection of all components applied so far |
| ClipPaths | Clip 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 |
| ClipPathsComplete | True 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 |
| MarkedContent | Marked-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 |
| ClipRule | Fill rule of the last clip applied: 0 for nonzero winding (W), 1 for even-odd (W*); -1 before any clip |
| PendingClipRule | Fill rule of a W or W* that waits for the next path-ending operator: 0 or 1; -1 when none is pending |
| PathBoundsKnown | True once a line, a curve or re added a point to the current path; a lone m gives a current point but no bounds |
| PathIsRectangle | True when the current path consists of one re operator whose corners map to an axis-aligned rectangle |
| PathMinX, PathMinY, PathMaxX, PathMaxY | Bounds of the current path in page space; a curve contributes its end points and its interior extrema, not its control points |
| PathSubpathCount, PathSegmentCount | Number of subpaths started by m or re, and number of segments appended by l, c, v, y and h, in the current path |
| PaintedPathSegments | Segments 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, CurrentPointY | Whether the current path has a current point, and its position in page space |
| TextClipPending | True 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, TextLineMatrix | Text matrix and text-line matrix of the current text object, both TPDFContentMatrix; BT resets both to the identity and Q does not restore them |
| LineWidth | Line width from w or /LW; 1 by default |
| LineCap, LineJoin | Line cap and line join style from J and j or /LC and /LJ, rounded and limited to 0 to 2; 0 by default |
| MiterLimit | Miter limit from M or /ML; 10 by default |
| DashArray, DashPhase | Dash array of d or /D as PDF source text, and the dash phase; [] and 0 by default |
| RenderingIntent | Name from ri or /RI; RelativeColorimetric by default |
| BlackPointCompensation | /UseBlackPtComp name of the last gs that carries it; Default by default |
| Flatness | Flatness from i or /FL; 1 by default, and /FL is limited to 0 to 100 |
| ExtGStateResource | Resource name of the most recent gs operator; empty until the first one |
| StrokeOverprint, FillOverprint | Overprint flags /OP and /op of the last gs that carries them; a gs with /OP but no op sets both |
| OverprintMode | Overprint mode /OPM, rounded and limited to 0 or 1 |
| StrokeAdjustment | Stroke adjustment flag /SA |
| BlendMode | Blend mode from /BM: the first supported name of a name or an array; Normal by default, and Compatible is reported as Normal |
| SoftMask | Soft mask from /SMask as a name, an indirect reference or a marker for a direct dictionary, stream or array; None by default |
| StrokeAlpha, FillAlpha | Stroking and nonstroking constant alpha /CA and /ca, limited to 0 to 1; 1 by default |
| AlphaIsShape, TextKnockout | Alpha source flag /AIS and text knockout flag /TK; text knockout is True by default |
| Smoothness | Smoothness from /SM, limited to 0 to 1 |
| BlackGeneration, UndercolorRemoval, TransferFunction | Black generation, undercolor removal and transfer function from /BG2 or /BG, /UCR2 or /UCR and /TR2 or /TR, in the same form as SoftMask |
| Halftone | Halftone from /HT, in the same form as SoftMask |
| StrokeColorSpace, FillColorSpace | Name set by CS and cs, or the device space implied by G, g, RG, rg, K and k; DeviceGray by default |
| StrokeColor, FillColor | Colour 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, FillPatternResource | Name 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 |
| ShadingResource | Name of the shading in a sh instruction; empty for every other instruction |
| ActiveResources | Resource dictionary of the content being traced, as assigned to the ActiveResources property of the tracker; Nil when none was assigned |
| CharSpacing, WordSpacing | Character spacing from Tc and word spacing from Tw; both are also set by the " operator. 0 by default |
| HorizontalScaling | Horizontal scaling from Tz, in percent; 100 by default |
| Leading | Text leading from TL; TD sets it to the negated vertical operand; 0 by default |
| FontResource | Name of the font selected by Tf; empty until a font is selected, and also after a gs with a /Font entry |
| FontReference | Indirect 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 |
| FontObjectNumber | Object number of the selected font; 0 when unknown |
| FontResourceScope | Resource 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 |
| FontIsType3 | True when the selected font has /Subtype /Type3; such a font adds nothing to the clip in rendering mode 4 to 7 |
| FontSize | Font size from Tf or from a /Font entry of a gs; 0 until a size is set |
| WritingMode, WritingModeResolved | Writing mode reported by the OnMeasureText callback, 0 for horizontal or 1 for vertical, and whether the callback supplied it |
| TextAdvanceX, TextAdvanceY | Displacement 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 |
| TextAdvanceResolved | True when OnMeasureText measured every string of the current show-text instruction; False without a callback |
| TextRenderingMode | Text rendering mode from Tr, rounded and limited to 0 to 7; 0 by default |
| TextRise | Text rise from Ts; 0 by default |
| InTextObject | True 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