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: u32Current source line number (1-based), updated during scanning.
packing_mode: boolPacking mode for array/procedure creation (setpacking/currentpacking).
echo: boolEcho mode for %lineedit/%statementedit (PLRM echo operator).
name_cache: NameCache§stdout: Box<dyn Write>§save_stack: SaveStack§job_start_save_depth: usizeSave stack depth when the current job started (for startjob condition 3).
vm_alloc_mode: bool§object_format: i32Binary object format (0-4). Default 0.
current_operator: Option<NameId>§in_error_handler: bool§initializing: boolTrue during init script execution — relaxes access checks.
allow_ps_resolution: boolWhen 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: boolWhen 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
impl Context
Sourcepub fn exec_sync(&mut self, proc_obj: PsObject) -> Result<(), PsError>
pub fn exec_sync(&mut self, proc_obj: PsObject) -> Result<(), PsError>
Execute a PostScript procedure synchronously and return.
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new context with empty stacks and stores.
Call build_system_dict afterward to populate operators.
Sourcepub fn new_with_output(output: Box<dyn Write>) -> Self
pub fn new_with_output(output: Box<dyn Write>) -> Self
Create a context that captures stdout to a buffer (for testing).
Sourcepub fn dict_load(&mut self, key: &DictKey) -> Option<PsObject>
pub fn dict_load(&mut self, key: &DictKey) -> Option<PsObject>
Look up a name in the dictionary stack (top to bottom).
Sourcepub fn invalidate_name_cache(&mut self)
pub fn invalidate_name_cache(&mut self)
Invalidate the name resolution cache (call on begin/end/def).
Sourcepub fn dict_where(&self, key: &DictKey) -> Option<(EntityId, PsObject)>
pub fn dict_where(&self, key: &DictKey) -> Option<(EntityId, PsObject)>
Look up and return (dict_entity, value) pair.
Sourcepub fn dict_def(&mut self, key: DictKey, value: PsObject) -> Result<(), PsError>
pub fn dict_def(&mut self, key: DictKey, value: PsObject) -> Result<(), PsError>
Store in current dict (top of d_stack).
Sourcepub fn dict_store(
&mut self,
key: DictKey,
value: PsObject,
) -> Result<(), PsError>
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.
Sourcepub fn make_dict_key(&mut self, obj: &PsObject) -> Result<DictKey, PsError>
pub fn make_dict_key(&mut self, obj: &PsObject) -> Result<DictKey, PsError>
Convert a PsObject to a DictKey.
Sourcepub fn alloc_loop(&mut self, state: LoopState) -> EntityId
pub fn alloc_loop(&mut self, state: LoopState) -> EntityId
Allocate a new loop state, returning its EntityId.
Sourcepub fn get_loop_mut(&mut self, entity: EntityId) -> &mut LoopState
pub fn get_loop_mut(&mut self, entity: EntityId) -> &mut LoopState
Get a mutable loop state by EntityId.
Sourcepub fn take_display_list(&mut self) -> DisplayList
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.
Sourcepub fn current_page_dpi(&self) -> f64
pub fn current_page_dpi(&self) -> f64
Read the current page DPI from the pagedevice HWResolution, defaulting to 72.
Sourcepub fn vm_save(&mut self) -> PsObject
pub fn vm_save(&mut self) -> PsObject
Perform a save: snapshot the current VM state.
Returns a Save PsObject.
Sourcepub fn vm_restore(&mut self, save_id: u32) -> Result<(), PsError>
pub fn vm_restore(&mut self, save_id: u32) -> Result<(), PsError>
Perform a restore: revert VM to the given save state.
Sourcepub fn cow_check_string(&mut self, entity: EntityId)
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.
Sourcepub fn cow_check_array(&mut self, entity: EntityId)
pub fn cow_check_array(&mut self, entity: EntityId)
Check if an array entity needs COW before mutation.
Sourcepub fn cow_check_dict(&mut self, entity: EntityId)
pub fn cow_check_dict(&mut self, entity: EntityId)
Check if a dict entity needs COW before mutation.
Sourcepub fn token_to_object(&mut self, token: Token) -> Result<PsObject, PsError>
pub fn token_to_object(&mut self, token: Token) -> Result<PsObject, PsError>
Convert a tokenizer token into a PsObject.
Sourcepub fn reset_local_vm(&mut self)
pub fn reset_local_vm(&mut self)
Reset local VM stores (for job boundary cleanup). Full implementation deferred until job server loop is built.