home *** CD-ROM | disk | FTP | other *** search
- % Copyright (C) 1990, 1991, 1992, 1993, 1994 Aladdin Enterprises. All rights reserved.
- %
- % This file is part of Aladdin Ghostscript.
- %
- % Aladdin Ghostscript is distributed with NO WARRANTY OF ANY KIND. No author
- % or distributor accepts any responsibility for the consequences of using it,
- % or for whether it serves any particular purpose or works at all, unless he
- % or she says so in writing. Refer to the Aladdin Ghostscript Free Public
- % License (the "License") for full details.
- %
- % Every copy of Aladdin Ghostscript must include a copy of the License,
- % normally in a plain ASCII text file named PUBLIC. The License grants you
- % the right to copy, modify and redistribute Aladdin Ghostscript, but only
- % under certain conditions described in the License. Among other things, the
- % License requires that the copyright notice and this notice be preserved on
- % all copies.
-
- % Initialization file for Level 2 functions.
- % When this is run, systemdict is still writable,
- % but everything defined here goes into level2dict.
-
- level2dict begin
-
- % ------ Miscellaneous ------ %
-
- (<<) cvn /mark load def
- (>>) cvn /.dicttomark load odef
- /currentsystemparams { mark .currentsystemparams .dicttomark } odef
- /currentuserparams { mark .currentuserparams .dicttomark } odef
- /deviceinfo { currentdevice getdeviceprops .dicttomark } odef
- /languagelevel 2 def
- /realtime /usertime load def
- % When running in Level 2 mode, this interpreter is supposed to be
- % compatible with PostScript version 2010 (I think).
- /version (2010) def
-
- % Choose an appropriate default binary object format.
- currentsystemparams dup
- /RealFormat get (IEEE) eq { 1 } { 3 } ifelse
- exch /ByteOrder get { 1 add } if
- setobjectformat
-
- % ------ Virtual memory ------ %
-
- /currentglobal /.currentglobal load def
- /gcheck /.gcheck load def
- /setglobal /.setglobal load def
- % We can make the global dictionaries very small, because they auto-expand.
- /globaldict currentdict /shareddict .knownget not { 4 dict } if def
- /GlobalFontDirectory currentdict SharedFontDirectory .knownget not { 4 dict } if def
-
- % ------ IODevices ------ %
-
- /currentdevparams { .getdevparams .dicttomark } odef
- /setdevparams { mark { } forall counttomark 2 add -1 roll .putdevparams } odef
-
- % ------ Job control ------ %
-
- serverdict begin
-
- % We could protect the job information better, but we aren't attempting
- % (currently) to protect ourselves against maliciousness.
-
- /.jobsave null def % top-level save object
- /.jobsavelevel 0 def % save depth of job (0 if .jobsave is null,
- % 1 otherwise)
- /.adminjob true def % status of current unencapsulated job
-
- /exitserver
- { true exch startjob not { /exitserver /invalidaccess signalerror } if
- } bind def
-
- end % serverdict
-
- %**************** The definition of startjob is not complete yet, since
- % it doesn't clear the exec stack, doesn't reset stdin/stdout,
- % doesn't run the job under its own control, and doesn't reset
- % other aspects of the interpreter.
- /startjob
- { vmstatus pop pop serverdict /.jobsavelevel get eq
- 1 index .checkpassword 0 gt and
- { .checkpassword count 2 roll count 2 sub { pop } repeat
- cleardictstack
- serverdict /.jobsave get dup null eq { pop } { restore } ifelse
- exch
- { % unencapsulated job
- serverdict /.jobsave null put
- serverdict /.jobsavelevel 0 put
- serverdict /.adminjob 3 -1 roll 1 gt put
- }
- { % encapsulated job
- serverdict /.jobsave save put
- serverdict /.jobsavelevel 1 put
- pop
- }
- ifelse true
- }
- { pop pop false
- }
- ifelse
- } odef
-
- % ------ Compatibility ------ %
-
- % In Level 2 mode, the following replace the definitions that gs_statd.ps
- % installs in statusdict and serverdict.
- % Note that statusdict must be allocated in local VM.
- % We don't bother with many of these yet, and the ones defined in terms
- % of currentsystemparams are cavalier about allocating a dictionary
- % in order to retrieve a single element from it....
-
- .currentglobal false .setglobal 25 dict exch .setglobal begin
- currentsystemparams
-
- /.dict1 { exch mark 3 1 roll .dicttomark } bind def
-
- /buildtime 1 index /BuildTime get def
- /byteorder 1 index /ByteOrder get def
- /checkpassword { .checkpassword 0 gt } bind def
- /defaulttimeouts
- { currentsystemparams dup
- /JobTimeout .knownget not { 0 } if
- exch /WaitTimeout .knownget not { 0 } if
- currentpagedevice /ManualFeedTimeout .knownget not { 0 } if
- } bind def
- dup /DoStartPage known
- { /dostartpage { currentsystemparams /DoStartPage get } bind def
- /setdostartpage { /DoStartPage .dict1 setsystemparams } bind def
- } if
- dup /StartupMode known
- { /dosysstart { currentsystemparams /StartupMode get 0 ne } bind def
- /setdosysstart { { 1 } { 0 } ifelse /StartupMode .dict1 setsystemparams } bind def
- } if
- %****** Setting jobname is supposed to set userparams.JobName, too.
- /jobname { currentuserparams /JobName get } bind def
- /jobtimeout { currentuserparams /JobTimeout get } bind def
- %manualfeed
- %manualfeedtimeout
- /margins { currentpagedevice /Margins get } bind def
- %pagecount
- %pagestackorder
- /printername
- { currentsystemparams /PrinterName .knownget not { () } if exch copy
- } bind def
- %/ramsize { currentsystemparams /RamSize get } bind def
- /realformat 1 index /RealFormat get def
- /setdefaulttimeouts
- { exch mark /ManualFeedTimeout 3 -1 roll
- /Policies mark /ManualFeedTimeout 0 .dicttomark
- .dicttomark setpagedevice
- /WaitTimeout exch mark /JobTimeout 5 2 roll .dicttomark setsystemparams
- } bind def
- /setmargins { /Margins .dict1 setpagedevice } bind def
- %setpagestackorder
- dup /PrinterName known
- { /setprintername { /PrinterName .dict1 setsystemparams } bind def
- } if
- currentuserparams /WaitTimeout known
- { /waittimeout { currentuserparams /WaitTimeout get } bind def
- } if
-
- /.setpagesize { 2 array astore /PageSize .dict1 setpagedevice } bind def
-
- pop % currentsystemparams
-
- % Flag the current dictionary so it will be swapped when we
- % change language levels. (See zmisc2.c for more information.)
- /statusdict currentdict def
-
- currentdict end
- /statusdict exch def
-
- % ------ Page devices ------ %
-
- % The implementation of setpagedevice is quite complex. Currently,
- % everything but the media matching algorithm is implemented here.
- %**************** Incomplete implementation, see NEWS.
-
- % Define the parameters that require special action to merge into the
- % combined page device dictionary. The procedures are called as follows:
- % <merged> <key> <new_value> -proc- <merged> <key> <new_value'>
- /.mergespecial mark
- /InputAttributes
- { dup null eq
- { pop null
- }
- { 3 copy pop .knownget
- { dup null eq
- { pop dup length dict }
- { dup length 2 index length add dict copy }
- ifelse
- }
- { dup length dict
- }
- ifelse copy readonly
- }
- ifelse
- } bind
- /OutputAttributes 1 index
- /Policies
- { 3 copy pop .knownget
- { dup length 2 index length add dict copy }
- { dup length dict }
- ifelse copy readonly
- } bind
- .dicttomark readonly def
-
- % Define the keys used in input attribute matching.
- /.inputattrkeys [
- /PageSize /MediaColor /MediaWeight /MediaType /InsertSheet
- ] readonly def
-
- % Define the keys used in output attribute matching.
- /.outputattrkeys [
- /OutputType
- ] readonly def
-
- % Define the parameters that should not be presented to the device.
- % The procedures are called as follows:
- % <merged> <key> <value> -proc-
- % The procedure leaves all its operands on the stack and returns
- % true iff the key/value pair should be presented to .putdeviceparams.
- /.presentspecial mark
- /Name false
- /OutputDevice false
- /InputAttributes false
- .inputattrkeys { pop { 2 index /InputAttributes get null eq } } forall
- /OutputAttributes false
- .outputattrkeys { pop { 2 index /OutputAttributes get null eq } } forall
- /Install false
- /BeginPage false
- /EndPage false
- /Policies false
- .dicttomark readonly def
-
- % Define the required attributes of all page devices.
- % We don't include attributes such as PageSize, which all devices
- % are guaranteed to supply on their own.
- /.requiredattrs mark
- /InputAttributes null
- /OutputAttributes null
- /Install {.callinstall} bind
- /BeginPage {.callbeginpage} bind
- /EndPage {.callendpage} bind
- /Policies mark
- /PolicyNotFound 1
- /PageSize 0
- /PolicyReport {pop} bind
- .dicttomark readonly
- .dicttomark readonly def
-
- % Define access to device defaults.
- /.defaultdevicename
- { 0 .getdevice .devicename
- } bind def
- /.defaultdeviceparams
- { finddevice null .getdeviceparams
- } bind def
-
- % Select media (input or output).
- /.selectmedia % <orig> <request> <merged> <failed>
- % (these are retained)
- % <attrdict> <attrkeys> <mediakey> .selectmedia
- { 4 index 4 -1 roll 3 index .matchmedia
- { 4 index 3 1 roll put pop
- }
- { % Adobe's implementations have a "big hairy heuristic"
- % to choose the set of keys to report as having failed the match.
- % For the moment, we report any keys that are in the request
- % and don't have the same value as in the original dictionary.
- 3 index exch undef
- { % Stack: <orig> <request> <merged> <failed> <attrkey>
- 3 index 1 index .knownget
- { 5 index 2 index .knownget { ne } { pop true } ifelse }
- { true }
- ifelse % Stack: ... <failed> <attrkey> <report>
- { 2 copy /rangecheck put }
- if pop
- }
- forall
- }
- ifelse
- } bind def
-
- % Apply Policies to any unprocessed failed requests.
- % As we process each request entry, we replace the error name
- % in the <failed> dictionary with the policy value,
- % and we remove the key from the <merged> dictionary.
- /.applypolicies % <merged> <failed> .applypolicies <merged'> <failed'>
- { 1 index /Policies get 1 index
- { type /integertype eq
- { pop % already processed
- }
- { 2 copy .knownget not { 1 index /PolicyNotFound get } if
- % Stack: <merged> <failed> <Policies> <key> <policy>
- dup 1 ne
- { % Set errorinfo and signal a configurationerror.
- % Note that we currently treat all Policy values other than 1
- % the same as 0.
- pop dup 4 index exch get 2 array astore
- $error /errorinfo 3 -1 roll put
- cleartomark
- /setpagedevice load /configurationerror signalerror
- }
- { % Ignore the failed request.
- 3 index 2 index 3 -1 roll put
- 3 index exch undef
- }
- ifelse
- }
- ifelse
- }
- forall pop
- } bind def
-
- % Try setting the device parameters from the merged request.
- /.trysetparams % ... <merged> <(ignored)> <device> <Policies>
- % .trysetparams
- { mark 4 index dup
- { % Stack: <merged> <key> <value>
- .presentspecial 2 index .knownget
- { exec { 3 -1 roll } { pop pop } ifelse }
- { 3 -1 roll }
- ifelse
- }
- forall pop
- DEBUG { (Putting.\n) print pstack flush } if
- .putdeviceparams
- DEBUG { (Result of putting.\n) print pstack flush } if
- } bind def
-
- % Finally, define setpagedevice.
- /setpagedevice
- {
- mark exch currentpagedevice
-
- % Check whether we are changing OutputDevice;
- % also handle the case where the current device
- % is not a page device.
- % Stack: mark <request> <current>
- DEBUG { (Checking.\n) print pstack flush } if
-
- dup /OutputDevice .knownget
- { % Current device is a page device.
- 2 index /OutputDevice .knownget
- { % A specific OutputDevice was requested.
- 2 copy eq
- { pop pop null }
- { exch pop }
- ifelse
- }
- { pop null
- }
- ifelse
- }
- { % Current device is not a page device.
- % Use the default device.
- 1 index /OutputDevice .knownget not { .defaultdevicename } if
- }
- ifelse
- dup null eq
- { pop
- }
- { exch pop .defaultdeviceparams
- counttomark 2 idiv .requiredattrs length add dict
- .requiredattrs exch copy
- begin counttomark 2 idiv { def } repeat pop currentdict end
- }
- ifelse
-
- % Merge the current and requested dictionaries.
- % Stack: mark <request> <orig>
- DEBUG { (Merging.\n) print pstack flush } if
-
- exch 1 index dup length 2 index length add dict copy
- dup 2 index
- { % stack: <orig> <request> <merged> <merged> <rkey> <rvalue>
- .mergespecial 2 index .knownget { exec } if
- put dup
- }
- forall pop
-
- % Select input and output media.
- % Stack: mark <orig> <request> <merged>
- DEBUG { (Selecting.\n) print pstack flush } if
-
- 0 dict % <failed>
- 1 index /InputAttributes get .inputattrkeys (%MediaSource) cvn .selectmedia
- 1 index /OutputAttributes get .outputattrkeys (%MediaDestination) cvn .selectmedia
- .applypolicies
-
- % Construct the new device, and attempt to set its attributes.
- % Stack: mark <orig> <request> <merged> <failed>
- DEBUG { (Constructing.\n) print pstack flush } if
-
- currentdevice .devicename 2 index /OutputDevice get eq
- { currentdevice }
- { 1 index /OutputDevice get finddevice }
- ifelse
- %**************** We should copy the device here,
- %**************** but since we can't close the old device,
- %**************** we don't. This is WRONG.
- %****************copydevice
- 2 index /Policies get
- .trysetparams
- dup type /nametype eq
- { % The request failed.
- % Stack: ... <failed> <device> <Policies> <mark>
- % <name> <value> ...
- counttomark 4 add -1 roll
- counttomark 2 idiv { dup 4 -2 roll put } repeat
- exch pop 3 1 roll
- % Stack: mark ... <merged> <failed> <device> <Policies>
- 4 2 roll .applypolicies 4 -2 roll
- .trysetparams % shouldn't fail!
- dup type /booleantype ne
- { 2 { counttomark 1 add 1 roll cleartomark } repeat
- /setpagedevice load exch signalerror
- }
- if
- }
- if
-
- % The attempt succeeded. Install the new device.
- % Stack: mark ... <merged> <failed> <device> <eraseflag>
- DEBUG { (Installing.\n) print pstack flush } if
-
- pop 2 .endpage
- { 1 true .outputpage
- (>>setpagedevice, press <return> to continue<<\n) .confirm
- }
- if
- .setdevice pop
- 1 index /Install .knownget { exec } if
- erasepage initgraphics
- 1 index .setpagedevice .beginpage
-
- % Clean up, calling PolicyReport if needed.
- % Stack: mark ... <merged> <failed>
- DEBUG { (Finishing.\n) print pstack flush } if
-
- dup length 0 ne
- { 1 index /Policies get /PolicyReport get
- counttomark 1 add 2 roll cleartomark
- exec
- }
- { cleartomark
- }
- ifelse
-
- } odef
-
- %**************** setpagedevice doesn't work well enough to use yet.
- /setpagedevice { pop } odef
- statusdict /.setpagesize undef
-
- % ------ Painting ------ %
-
- % A straightforward definition of execform that doesn't actually
- % do any caching.
- /execform
- { dup /Implementation known not
- { dup /FormType get 1 ne { /rangecheck signalerror } if
- dup /Implementation null put readonly
- } if
- gsave dup /Matrix get concat
- dup /BBox get aload pop
- exch 3 index sub exch 2 index sub rectclip
- dup /PaintProc get exec
- grestore
- } odef
-
- /makepattern
- { currentglobal
- { false setglobal .buildpattern true setglobal }
- { .buildpattern }
- ifelse
- exch dup length 1 add dict copy
- dup /Implementation 4 -1 roll put
- readonly
- } odef
-
- /setpattern
- { currentcolorspace 0 get /Pattern ne
- { [ /Pattern currentcolorspace ] setcolorspace } if
- setcolor
- } odef
-
- % ------ Resources ------ %
-
- (BEGIN RESOURCES) VMDEBUG
-
- % We keep track of (global) instances with another entry in the resource
- % dictionary, an Instances dictionary. For categories with implicit
- % instances, the values in Instances are the same as the keys;
- % for other categories, the values are [instance status size].
-
- % Note that the dictionary that defines a resource category is stored
- % in global memory. The PostScript manual says that each category must
- % manage global and local instances separately. However, objects in
- % global memory can't reference objects in local memory. This means
- % that the resource category dictionary, which would otherwise be the
- % obvious place to keep track of the instances, can't be used to keep
- % track of local instances. Instead, we define a dictionary in local VM
- % called localinstancedict, in which the key is the category name and
- % the value is the analogue of Instances for local instances.
-
- % We don't currently implement automatic resource unloading.
- % When we do, it should be hooked to the garbage collector.
-
- currentglobal false setglobal systemdict begin
- /localinstancedict 5 dict def
- end setglobal
- /.emptydict 0 dict readonly def
-
- % Resource category dictionaries have the following keys (those marked with
- % * are optional):
- % Defined in the Red Book:
- % DefineResource
- % UndefineResource
- % FindResource
- % ResourceStatus
- % ResourceForAll
- % Category
- % *InstanceType
- % *ResourceFileName
- % Specific to our implementation:
- % LocalInstances
- % - LocalInstances <dict>
- % GetInstance
- % <key> GetInstance <instance> -true-
- % <key> GetInstance -false-
- % .CheckResource
- % <value> .CheckResource <ok>
- % .LoadResource
- % <key> .LoadResource - (may give an error)
- % .ResourceFile
- % <key> .ResourceFile <file> -true-
- % <key> .ResourceFile -false-
-
- % Define the Category category, except for most of the procedures.
- % The dictionary we're about to create will become the Category
- % category definition dictionary.
-
- 12 dict begin
- /Category /Category def
- /GetInstance
- { Instances exch .knownget
- } bind def
- /LocalInstances [] def
- /.CheckResource
- { dup gcheck currentglobal and
- { /DefineResource /FindResource /ResourceForAll /ResourceStatus
- /UndefineResource }
- { 2 index exch known and }
- forall exch pop
- } bind def
- /DefineResource
- { dup .CheckResource
- { dup /Category 3 index cvlit .growput readonly
- dup [ exch 0 -1 ] exch
- Instances 4 2 roll put
- }
- { /typecheck signalerror
- }
- ifelse
- } bind def
- /FindResource % (redefined below)
- { Instances exch get 0 get
- } bind def
- /Instances 25 dict def
- /InstanceType /dicttype def
-
- Instances /Category [currentdict 0 -1] put
- Instances end begin % so we can name the Category definition
-
- (END CATEGORY) VMDEBUG
-
- % Define the resource operators. I don't see how we can possibly restore
- % the stacks after an error, since the procedure may have popped and
- % pushed elements arbitrarily....
-
- mark
- /defineresource
- { /Category findresource dup begin
- /InstanceType known
- { dup type InstanceType ne
- { dup type /packedarraytype eq InstanceType /arraytype eq and
- not { /typecheck signalerror } if } if } if
- /DefineResource load stopped end { stop } if
- }
- /findresource
- { dup /Category eq
- { pop //Category 0 get } { /Category findresource } ifelse
- begin
- /FindResource load stopped end { stop } if
- }
- /resourceforall
- { /Category findresource begin
- /ResourceForAll load stopped end { stop } if
- }
- /resourcestatus
- { /Category findresource begin
- /ResourceStatus load stopped end { stop } if
- }
- /undefineresource
- { /Category findresource begin
- /UndefineResource load stopped end { stop } if
- }
- end % Instances
- counttomark 2 idiv { bind odef } repeat pop
-
- % Define the Generic category.
-
- /Generic mark
-
- /Instances 0 dict
- /LocalInstances % not a standard entry -- a shared utility
- { localinstancedict Category .knownget not { //.emptydict } if
- } bind
- /GetInstance % not a standard entry -- a shared utility
- { currentglobal
- { Instances exch .knownget }
- { LocalInstances 1 index .knownget
- { exch pop true }
- { Instances exch .knownget }
- ifelse
- }
- ifelse
- } bind
- /.CheckResource % not a standard entry
- { pop true
- } bind
- /DefineResource
- { dup .CheckResource
- { { readonly } stopped pop
- dup [ exch 0 -1 ] exch
- currentglobal
- { 2 index UndefineResource % remove local def if any
- Instances
- }
- { LocalInstances dup //.emptydict eq
- { pop 3 dict localinstancedict Category 2 index put
- }
- if
- }
- ifelse
- 4 2 roll .growput
- }
- { /typecheck signalerror
- }
- ifelse
- } bind
- /FindResource
- { dup ResourceStatus
- { pop 1 gt % not in VM
- { dup vmstatus pop exch pop exch
- .LoadResource
- vmstatus pop exch pop exch sub
- 1 index GetInstance not
- { pop /undefinedresource signalerror } % didn't load
- if
- dup 1 1 put
- 2 3 -1 roll put
- }
- if
- GetInstance pop % can't fail
- 0 get
- }
- { /undefinedresource signalerror
- }
- ifelse
- } bind
- /.LoadResource % not a standard entry; may fail
- { dup .ResourceFile
- { exch pop currentglobal
- { run }
- { true setglobal { run } stopped false setglobal { stop } if }
- ifelse
- }
- { /undefinedresource signalerror
- }
- ifelse
- } bind
- /.ResourceFile % not a standard entry; returns <file> true or false
- { currentdict /ResourceFileName known
- { mark exch 100 string { ResourceFileName }
- stopped
- { cleartomark false }
- { exch pop findlibfile
- { exch pop true }
- { pop false }
- ifelse
- }
- ifelse
- }
- { pop false }
- ifelse
- } bind
- /ResourceForAll
- { % **************** Doesn't present instance groups in
- % **************** the correct order yet.
- % We construct a new procedure so we don't have to use
- % static resources to hold the iteration state.
- 3 packedarray % template, proc, scratch
- { exch pop % stack contains: key, {template, proc, scratch}
- 2 copy 0 get .stringmatch
- { 1 index type dup /stringtype eq exch /nametype eq or
- { 2 copy 2 get cvs
- exch 1 get 3 -1 roll pop
- }
- { 1 get
- }
- ifelse exec
- }
- { pop pop
- }
- ifelse
- } /exec cvx 3 packedarray cvx
- currentglobal LocalInstances length 0 eq or not
- { % We must do local instances, and do them first.
- /forall cvx 1 index 2 packedarray cvx
- LocalInstances 3 1 roll exec
- }
- if
- Instances exch forall
- } bind
- /ResourceStatus
- { dup GetInstance
- { exch pop dup 1 get exch 2 get true }
- { .ResourceFile
- { closefile 2 -1 true }
- { false }
- ifelse
- }
- ifelse
- } bind
- /UndefineResource
- { { dup 2 index .knownget
- { dup 1 get 1 ge
- { dup 0 null put 1 2 put pop pop }
- { pop exch undef }
- ifelse
- }
- { pop pop
- }
- ifelse
- }
- currentglobal
- { 2 copy Instances exch exec
- }
- if LocalInstances exch exec
- } bind
-
- % We're still running in Level 1 mode, so dictionaries won't expand.
- % Leave room for the /Category entry.
- /Category null
-
- .dicttomark
- /Category defineresource pop
-
- % Fill in the rest of the Category category.
- /Category /Category findresource dup
- /Generic /Category findresource begin
- { /FindResource /ResourceStatus /ResourceForAll /.ResourceFile }
- { dup load put dup } forall
- pop readonly pop end
-
- (END GENERIC) VMDEBUG
-
- % Define the fixed categories.
-
- mark
- % Things other than types
- /ColorSpaceFamily
- {/CIEBasedA /CIEBasedABC /DeviceCMYK /DeviceGray /DeviceRGB
- /Indexed /Pattern /Separation
- }
- /Emulator
- {}
- /Filter
- mark systemdict
- { pop =string cvs (.filter_) anchorsearch
- { pop cvn }
- { pop }
- ifelse
- }
- forall
- .packtomark
- /IODevice
- % Loop until the .getiodevice gets a rangecheck.
- errordict /rangecheck 2 copy get
- errordict /rangecheck { pop stop } put % pop the command
- mark 0 { {dup .getiodevice exch 1 add} loop} stopped pop pop .packtomark
- 4 1 roll put
- .clearerror
- % Types
- /ColorRenderingType
- {1}
- /FMapType
- {2 3 4 5 6 7 8}
- /FontType
- [/.buildfont0 where {pop 0} if 1 3]
- /FormType
- {1}
- /HalftoneType
- {1 2 3 4 5}
- /ImageType
- {1}
- /PatternType
- {1}
- counttomark 2 idiv
- { 8 dict begin % 5 procedures, Category, Instances, LocalInstances
- /DefineResource
- { /invalidaccess signalerror } bind def
- /FindResource
- { Instances exch get } bind def
- /LocalInstances % used by ResourceForAll
- [] def
- /ResourceForAll
- /Generic /Category findresource /ResourceForAll get def
- /ResourceStatus
- { Instances exch known { 0 0 true } { false } ifelse } bind def
- /UndefineResource
- { /invalidaccess signalerror } bind def
- dup length dict dup begin exch { dup def } forall end readonly
- /Instances exch def
- currentdict end /Category defineresource pop
- } repeat pop
-
- (END FIXED) VMDEBUG
-
- % Define the other built-in categories.
-
- /.definecategory % <name> -mark- <key1> ... <valuen> .definecategory -
- { counttomark 2 idiv 2 add % Instances, Category
- /Generic /Category findresource dup maxlength 3 -1 roll add dict copy begin
- counttomark 2 idiv { def } repeat pop % pop the mark
- currentdict /Instances known not { /Instances 10 dict def } if
- currentdict end /Category defineresource pop
- } bind def
-
- /ColorRendering mark /InstanceType /dicttype .definecategory
- /ColorSpace mark /InstanceType /arraytype .definecategory
- /Form mark /InstanceType /dicttype .definecategory
- /Halftone mark /InstanceType /dicttype .definecategory
- /Pattern mark /InstanceType /dicttype .definecategory
- /ProcSet mark /InstanceType /dicttype .definecategory
-
- (END MISC) VMDEBUG
-
- % Define the Encoding category.
-
- /Encoding mark /InstanceType /arraytype
-
- % Handle lazily loaded encodings that aren't loaded yet.
-
- /Instances mark
- .encodingdict
- { length 256 eq { pop } { [null 2 -1] } ifelse
- } forall
- .dicttomark
-
- /.ResourceFileDict mark
- .encodingdict
- { dup length 256 eq { pop pop } { 0 get } ifelse
- } forall
- .dicttomark
-
- /ResourceFileName
- { exch dup .ResourceFileDict exch .knownget
- { exch pop exch copy }
- { exch pop /undefinedresource signalerror }
- ifelse
- } bind
-
- .definecategory % Encoding
-
- /.findencoding { /Encoding findresource } bind def
- /findencoding /.findencoding load odef
- /.defineencoding
- { 2 copy /Encoding defineresource pop
- //.encodingdict 3 1 roll put
- } bind def
-
- .encodingdict
- { dup length 256 eq
- { /Encoding defineresource pop }
- { pop pop }
- ifelse
- }
- forall
-
- (END ENCODING) VMDEBUG
-
- % Define the Font category.
-
- /Font mark /InstanceType /dicttype
-
- /DefineResource
- { 2 copy //definefont exch pop
- /Generic /Category findresource /DefineResource get exec
- } bind
- /.LoadResource
- { //findfont pop
- } bind
-
- .definecategory % Font
-
- % Make entries for fonts already loaded.
- /.resourceFromFontmap
- { /Font /Category findresource begin
- Fontmap
- { pop dup Instances exch known
- { pop }
- { [null 2 -1] Instances 3 1 roll .growput }
- ifelse
- }
- forall
- end
- } bind def
- .resourceFromFontmap
- /Font /Category findresource begin
- FontDirectory
- { dup .gcheck { Instances } { LocalInstances } ifelse
- 3 1 roll [exch 0 -1] .growput
- }
- forall end
-
- % Redefine font "operators".
- /.loadFontmap { //.loadFontmap exec .resourceFromFontmap } def
-
- /definefont
- { /Font defineresource } bind odef
- %**************** Don't redefine findfont yet.
- %/findfont
- % { /Font findresource } bind def % Must be a procedure, not an operator
- /undefinefont
- { /Font undefineresource } bind odef
-
- % Remove initialization utilities.
- currentdict /.definecategory undef
- currentdict /.emptydict undef
-
- end % level2dict
-