GraphicsState
Graphics state (ISO 32000-1 §8.4).
Every PDF content stream runs inside a stack of graphics states. q pushes a copy; Q pops back. cm, color setters, font setters etc. mutate the top of the stack. We model this with an immutable GraphicsState data class and a stack on the side (see GraphicsStack). That is easier to reason about than a mutable struct, and it costs one small allocation per q.
Text state (Tm, Tlm, font, size, spacing) is tracked separately on TextState and lives only inside BT…ET blocks.
Constructors
Properties
Black point compensation in that conversion (ExtGState /UseBlackPtComp).
Blend mode applied to paints (ExtGState /BM).
Current non-stroke colour space (cs operator).
The components fillColor came from in fillColorSpace, or null for the initial colour of the space.
Active fill pattern, set by scn when the fill colour-space is /Pattern. When non-null, fillColor is ignored and paint operators route through the canvas's gradient/tile path. Cleared by any plain colour setter (g, rg, k, cs, sc).
Miter limit (M).
Overprint for fills and other paints (ExtGState /op).
The overprint mode (ExtGState /OPM): 1 leaves the backdrop's ink wherever a DeviceCMYK paint sets 0.
Overprint for strokes (ExtGState /OP).
The rendering intent (ri, ExtGState /RI) that colours convert through.
The CTM when softMask was set: the mask is drawn under it, never under a later cm (#67).
Per-pixel alpha multiplier for strokes (ExtGState /CA), 0..1.
Current stroke colour space (CS operator).
The components strokeColor came from in strokeColorSpace, or null for the initial colour of the space.
Active stroke pattern: same semantics as fillPattern for SCN.
Functions
Merge the non-null fields of ext into this state. Spec semantics for gs <name>: only entries present in the ExtGState override; everything else passes through.
This state with colours converting through intent, with or without black point compensation. The current colours convert again from their components, so a colour set before ri follows it, as it does in MuPDF (#201).