GraphicsState

data class GraphicsState(val ctm: Matrix = Matrix.IDENTITY, val strokeColor: RgbColor = RgbColor.BLACK, val fillColor: RgbColor = RgbColor.BLACK, val lineWidth: Double = 1.0, val text: TextState = TextState(), val fillColorSpace: ColorSpace = ColorSpace.DeviceGray, val strokeColorSpace: ColorSpace = ColorSpace.DeviceGray, val fillAlpha: Double = 1.0, val strokeAlpha: Double = 1.0, val blendMode: BlendMode = BlendMode.Normal, val softMask: SoftMask? = null, val fillPattern: KitePattern? = null, val strokePattern: KitePattern? = null, val dashArray: List<Double>? = null, val dashPhase: Double = 0.0, val lineCap: Int = 0, val lineJoin: Int = 0, val miterLimit: Double = 10.0)

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

Link copied to clipboard
constructor(ctm: Matrix = Matrix.IDENTITY, strokeColor: RgbColor = RgbColor.BLACK, fillColor: RgbColor = RgbColor.BLACK, lineWidth: Double = 1.0, text: TextState = TextState(), fillColorSpace: ColorSpace = ColorSpace.DeviceGray, strokeColorSpace: ColorSpace = ColorSpace.DeviceGray, fillAlpha: Double = 1.0, strokeAlpha: Double = 1.0, blendMode: BlendMode = BlendMode.Normal, softMask: SoftMask? = null, fillPattern: KitePattern? = null, strokePattern: KitePattern? = null, dashArray: List<Double>? = null, dashPhase: Double = 0.0, lineCap: Int = 0, lineJoin: Int = 0, miterLimit: Double = 10.0)

Properties

Link copied to clipboard

Blend mode applied to paints (ExtGState /BM).

Link copied to clipboard
val ctm: Matrix
Link copied to clipboard

Dash pattern (d operator): on/off lengths in user-space units; null/empty = solid.

Link copied to clipboard

Dash phase offset (d operator), user-space units.

Link copied to clipboard

Per-pixel alpha multiplier for fills (ExtGState /ca), 0..1.

Link copied to clipboard
Link copied to clipboard

Current non-stroke colour space (cs operator).

Link copied to clipboard

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).

Link copied to clipboard

Line cap (J): 0 butt, 1 round, 2 projecting square.

Link copied to clipboard

Line join (j): 0 miter, 1 round, 2 bevel.

Link copied to clipboard
Link copied to clipboard

Miter limit (M).

Link copied to clipboard

Active soft mask (ExtGState /SMask); null when none.

Link copied to clipboard

Per-pixel alpha multiplier for strokes (ExtGState /CA), 0..1.

Link copied to clipboard
Link copied to clipboard

Current stroke colour space (CS operator).

Link copied to clipboard

Active stroke pattern: same semantics as fillPattern for SCN.

Link copied to clipboard

Functions

Link copied to clipboard

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.