Skip to main content

GraphicsState

Struct GraphicsState 

Source
pub struct GraphicsState {
Show 22 fields pub matrix: [f64; 6], pub screen: ScreenParams, pub stroke_alpha: f64, pub fill_alpha: f64, pub pattern_stroke_alpha: f64, pub pattern_fill_alpha: f64, pub line_width: f64, pub line_cap: LineCap, pub line_join: LineJoin, pub miter_limit: f64, pub flatness: f64, pub line_dash: Vec<f64>, pub line_dash_phase: f64, pub clip: Clip, pub soft_mask: Option<Box<AnyBitmap>>, pub overprint_mode: i32, pub rgb_transfer: [TransferLut; 3], pub gray_transfer: TransferLut, pub cmyk_transfer: [TransferLut; 4], pub device_n_transfer: Vec<[u8; 256]>, pub overprint_mask: u32, pub delete_soft_mask: bool,
}
Expand description

The complete graphics state for one rendering context.

Patterns are stubbed as () for Phase 1; Phase 2 replaces them with Box<dyn Pattern>.

Fields§

§matrix: [f64; 6]

Current transformation matrix in column-vector 2-D affine form: [a, b, c, d, e, f].

§screen: ScreenParams

Halftone screen parameters controlling frequency, angle, and spot function.

§stroke_alpha: f64

Opacity for stroking operations. 0.0 = fully transparent, 1.0 = fully opaque.

§fill_alpha: f64

Opacity for fill operations. 0.0 = fully transparent, 1.0 = fully opaque.

§pattern_stroke_alpha: f64

Effective stroke alpha after multiplying in pattern alpha (used when multiply_pattern_alpha is set).

§pattern_fill_alpha: f64

Effective fill alpha after multiplying in pattern alpha (used when multiply_pattern_alpha is set).

§line_width: f64

Stroke line width in user-space units; must be ≥ 0.

§line_cap: LineCap

Style of line end caps (butt, round, or square).

§line_join: LineJoin

Style of line joins (miter, round, or bevel).

§miter_limit: f64

Maximum ratio of miter length to line width before a miter join is beveled; default 10.0.

§flatness: f64

Maximum permitted distance between the path and the approximating line segments; default 1.0.

§line_dash: Vec<f64>

Dash pattern array: alternating on/off lengths in user-space units.

§line_dash_phase: f64

Offset into the dash pattern at which stroking begins.

§clip: Clip

Active clipping region; updated by clip operators.

§soft_mask: Option<Box<AnyBitmap>>

Soft mask bitmap (None if no soft mask is active).

§overprint_mode: i32

PDF overprint mode: 0 = CompatibleOverprint, 1 = IsolatePaint.

§rgb_transfer: [TransferLut; 3]

Transfer LUTs — RGB channels (R=0, G=1, B=2).

§gray_transfer: TransferLut

Transfer LUT for the gray channel.

§cmyk_transfer: [TransferLut; 4]

Transfer LUTs — CMYK channels (C=0, M=1, Y=2, K=3).

§device_n_transfer: Vec<[u8; 256]>

Transfer LUTs — DeviceN channels (indices 0..SPOT_NCOMPS+4 = 8).

§overprint_mask: u32

Bitmask of color components that participate in overprinting; default 0xFFFF_FFFF (all).

§delete_soft_mask: bool

Whether the soft mask should be deleted on the next state restore. New states cloned for an XObject explicitly clear this so child renders do not inherit the parent’s deletion intent.

Implementations§

Source§

impl GraphicsState

Source

pub fn new(width: u32, height: u32, vector_antialias: bool) -> Self

Construct the default state for a new page.

clip is set to [0, 0, width-0.001, height-0.001] — the intentional 0.001 inset matches SplashState constructor and avoids edge-pixel issues.

§Panics

Panics (in debug builds only) if width or height is zero. A zero dimension would produce a negative clip bound (0.0 - 0.001 = -0.001), which is meaningless and almost certainly a caller bug.

Source

pub fn set_transfer( &mut self, r: &[u8; 256], g: &[u8; 256], b: &[u8; 256], gray: &[u8; 256], )

Apply new RGB and gray transfer functions, deriving CMYK and DeviceN[0..4] from the inverted current RGB/gray values before overwriting them.

Matches SplashState::setTransfer in SplashState.cc exactly.

§Derivation

CMYK uses a subtractive colour model: a CMYK value of 0 means “no ink” (full brightness) and 255 means “full ink” (zero brightness). The relationship to the existing RGB transfer LUT is therefore:

Step 1 – invert the index:   look up rgb_transfer_R at position (255 - i)
                              to obtain the complemented input value.
Step 2 – invert the result:  subtract from 255 to flip from additive to
                              subtractive space.

cmykTransferC[i] = 255 - rgb_transfer_R[255 - i]   ← C mapped from R
cmykTransferM[i] = 255 - rgb_transfer_G[255 - i]   ← M mapped from G
cmykTransferY[i] = 255 - rgb_transfer_B[255 - i]   ← Y mapped from B
cmykTransferK[i] = 255 - gray_transfer[255 - i]    ← K mapped from gray
deviceNTransfer[0..=3][i]  = same as CMYK (C/M/Y/K), respectively

Only after the CMYK/DeviceN tables have been built are rgb_transfer and gray_transfer overwritten with the new r, g, b, gray LUTs.

Source

pub fn save_clone(&self) -> Self

Clone this state for save().

Clip scanners are shared via Arc (matching C++ shared_ptr semantics). The soft mask is NOT inherited — the new state starts with soft_mask = None.

Source

pub fn transfer_set(&self) -> TransferSet<'_>

Borrow the transfer tables as a TransferSet for use in the pipe.

The returned TransferSet borrows from self and is valid for the lifetime of this GraphicsState.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.