Skip to main content

Context

Struct Context 

Source
pub struct Context {
Show 66 fields pub o_stack: Stack, pub e_stack: Stack, pub d_stack: Vec<EntityId>, pub strings: DualStringStore, pub arrays: DualArrayStore, pub dicts: DualDictStore, pub names: NameTable, pub files: FileStore, pub loops: Vec<LoopState>, pub operators: Vec<OpEntry>, pub systemdict: EntityId, pub globaldict: EntityId, pub userdict: EntityId, pub errordict: EntityId, pub dollar_error: EntityId, pub rand_state: u64, pub rand_seed: i32, pub current_source_line: u32, pub packing_mode: bool, pub echo: bool, pub name_cache: NameCache, pub stdout: Box<dyn Write>, pub save_stack: SaveStack, pub job_start_save_depth: usize, pub vm_alloc_mode: bool, pub object_format: i32, pub current_operator: Option<NameId>, pub in_error_handler: bool, pub initializing: bool, pub allow_ps_resolution: bool, pub gstate: GraphicsState, pub gstate_stack: Vec<GstateEntry>, pub gstate_store: Vec<GraphicsState>, pub device: Option<Box<dyn OutputDevice>>, pub display_list: DisplayList, pub capture_display_lists: Option<Vec<(DisplayList, f64)>>, pub display_list_sender: Option<Sender<(DisplayList, f64, u32, u32, Option<Arc<Vec<u8>>>)>>, pub page_width: u32, pub page_height: u32, pub output_path: Option<String>, pub page_filter: Option<HashSet<i32>>, pub device_factory: Option<Box<dyn Fn(u32, u32) -> Box<dyn OutputDevice>>>, pub font_directory: EntityId, pub font_resource_path: Option<String>, pub next_fid: i32, pub global_resources: EntityId, pub local_resources: EntityId, pub category_registry: EntityId, pub resource_base_path: Option<String>, pub user_params: EntityId, pub system_params: EntityId, pub internaldict: Option<EntityId>, pub icc_cache: IccCache, pub exec_sync_fn: Option<ExecSyncFn>, pub char_width: Option<(f64, f64)>, pub char_width_mode1: Option<((f64, f64), (f64, f64))>, pub glyph_caches: FxHashMap<EntityId, GlyphCache>, pub char_cache_mode: Option<Type3CacheMode>, pub cshow_pending_cid: Option<i32>, pub pattern_store: Vec<PatternData>, pub form_cache: FxHashMap<EntityId, DisplayList>, pub start_time: Option<Instant>, pub dict_version: u64, pub name_resolve_cache: Vec<(u64, PsObject)>, pub interrupt_flag: Option<Arc<AtomicBool>>, pub yield_after_showpage: bool,
}

Fields§

§o_stack: Stack§e_stack: Stack§d_stack: Vec<EntityId>§strings: DualStringStore§arrays: DualArrayStore§dicts: DualDictStore§names: NameTable§files: FileStore§loops: Vec<LoopState>§operators: Vec<OpEntry>§systemdict: EntityId§globaldict: EntityId§userdict: EntityId§errordict: EntityId§dollar_error: EntityId§rand_state: u64§rand_seed: i32§current_source_line: u32

Current source line number (1-based), updated during scanning.

§packing_mode: bool

Packing mode for array/procedure creation (setpacking/currentpacking).

§echo: bool

Echo mode for %lineedit/%statementedit (PLRM echo operator).

§name_cache: NameCache§stdout: Box<dyn Write>§save_stack: SaveStack§job_start_save_depth: usize

Save stack depth when the current job started (for startjob condition 3).

§vm_alloc_mode: bool§object_format: i32

Binary object format (0-4). Default 0.

§current_operator: Option<NameId>§in_error_handler: bool§initializing: bool

True during init script execution — relaxes access checks.

§allow_ps_resolution: bool

When true, PS programs can change HWResolution via setpagedevice. Set by WASM frontend; CLI leaves false to keep DPI under user control.

§gstate: GraphicsState§gstate_stack: Vec<GstateEntry>§gstate_store: Vec<GraphicsState>

Storage for gstate objects (PsValue::Gstate indexes into this).

§device: Option<Box<dyn OutputDevice>>§display_list: DisplayList§capture_display_lists: Option<Vec<(DisplayList, f64)>>

When Some, each showpage clones the display list here before consuming it. Used by the WASM frontend to retain display lists for viewport re-rendering. Each entry is (DisplayList, dpi) where dpi is from the pagedevice HWResolution.

§display_list_sender: Option<Sender<(DisplayList, f64, u32, u32, Option<Arc<Vec<u8>>>)>>

When Some, each showpage sends a clone of the display list through this channel. Used by the CLI viewer for incremental display list delivery. Tuple: (DisplayList, dpi, page_width, page_height).

§page_width: u32§page_height: u32§output_path: Option<String>§page_filter: Option<HashSet<i32>>

Page filter: if set, only render pages in this set (1-based).

§device_factory: Option<Box<dyn Fn(u32, u32) -> Box<dyn OutputDevice>>>

Factory closure for creating raster devices (registered by CLI).

§font_directory: EntityId§font_resource_path: Option<String>§next_fid: i32§global_resources: EntityId§local_resources: EntityId§category_registry: EntityId§resource_base_path: Option<String>§user_params: EntityId§system_params: EntityId§internaldict: Option<EntityId>§icc_cache: IccCache§exec_sync_fn: Option<ExecSyncFn>§char_width: Option<(f64, f64)>§char_width_mode1: Option<((f64, f64), (f64, f64))>§glyph_caches: FxHashMap<EntityId, GlyphCache>§char_cache_mode: Option<Type3CacheMode>§cshow_pending_cid: Option<i32>§pattern_store: Vec<PatternData>

Storage for pattern instances created by makepattern.

§form_cache: FxHashMap<EntityId, DisplayList>

Cache of form display lists keyed by dict EntityId.

§start_time: Option<Instant>§dict_version: u64§name_resolve_cache: Vec<(u64, PsObject)>

Name resolution cache indexed by NameId. Each entry is (dict_version, resolved_object). Public for inline cache checks in the eval loop’s hot path.

§interrupt_flag: Option<Arc<AtomicBool>>

When set, the eval loop aborts with PsError::Quit on the next iteration. Used by the interactive viewer to cancel an in-flight parse when the user drops a new file.

§yield_after_showpage: bool

When true, each successful showpage / copypage sets interrupt_flag after capturing the display list, so the eval loop yields back to the caller one page at a time. The caller clears the flag and re-enters eval to drive the next page. Used by the WASM viewer to stream multi-page PostScript documents: page 1 renders while pages 2..N are still pending interpretation. Requires interrupt_flag to be set.

Implementations§

Source§

impl Context

Source

pub fn exec_sync(&mut self, proc_obj: PsObject) -> Result<(), PsError>

Execute a PostScript procedure synchronously and return.

Source

pub fn new() -> Self

Create a new context with empty stacks and stores. Call build_system_dict afterward to populate operators.

Source

pub fn new_with_output(output: Box<dyn Write>) -> Self

Create a context that captures stdout to a buffer (for testing).

Source

pub fn dict_load(&mut self, key: &DictKey) -> Option<PsObject>

Look up a name in the dictionary stack (top to bottom).

Source

pub fn invalidate_name_cache(&mut self)

Invalidate the name resolution cache (call on begin/end/def).

Source

pub fn dict_where(&self, key: &DictKey) -> Option<(EntityId, PsObject)>

Look up and return (dict_entity, value) pair.

Source

pub fn dict_def(&mut self, key: DictKey, value: PsObject) -> Result<(), PsError>

Store in current dict (top of d_stack).

Source

pub fn dict_store( &mut self, key: DictKey, value: PsObject, ) -> Result<(), PsError>

Store in first dict that contains key, or current dict if not found.

Source

pub fn make_dict_key(&mut self, obj: &PsObject) -> Result<DictKey, PsError>

Convert a PsObject to a DictKey.

Source

pub fn alloc_loop(&mut self, state: LoopState) -> EntityId

Allocate a new loop state, returning its EntityId.

Source

pub fn get_loop(&self, entity: EntityId) -> &LoopState

Get a loop state by EntityId.

Source

pub fn get_loop_mut(&mut self, entity: EntityId) -> &mut LoopState

Get a mutable loop state by EntityId.

Source

pub fn take_display_list(&mut self) -> DisplayList

Take the display list, optionally capturing a clone for viewport re-rendering.

This replaces std::mem::take(&mut ctx.display_list) at showpage/copypage call sites. When capture_display_lists is active, a clone is saved along with the current page DPI from the pagedevice HWResolution.

Source

pub fn current_page_dpi(&self) -> f64

Read the current page DPI from the pagedevice HWResolution, defaulting to 72.

Source

pub fn vm_save(&mut self) -> PsObject

Perform a save: snapshot the current VM state. Returns a Save PsObject.

Source

pub fn vm_restore(&mut self, save_id: u32) -> Result<(), PsError>

Perform a restore: revert VM to the given save state.

Source

pub fn cow_check_string(&mut self, entity: EntityId)

Check if a string entity needs COW before mutation. If yes, creates a backup copy and records it.

Source

pub fn cow_check_array(&mut self, entity: EntityId)

Check if an array entity needs COW before mutation.

Source

pub fn cow_check_dict(&mut self, entity: EntityId)

Check if a dict entity needs COW before mutation.

Source

pub fn token_to_object(&mut self, token: Token) -> Result<PsObject, PsError>

Convert a tokenizer token into a PsObject.

Source

pub fn reset_local_vm(&mut self)

Reset local VM stores (for job boundary cleanup). Full implementation deferred until job server loop is built.

Trait Implementations§

Source§

impl Default for Context

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> Same for T

Source§

type Output = T

Should always be Self
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.