Debian Codegraph @

Resource/Init/gs_dscp.ps

raw
1 % Copyright (C) 2001-2023 Artifex Software, Inc.
2 % All Rights Reserved.
3 %
4 % This software is provided AS-IS with no warranty, either express or
5 % implied.
6 %
7 % This software is distributed under license and may not be copied,
8 % modified or distributed except as expressly authorized under the terms
9 % of the license contained in the file LICENSE in this distribution.
10 %
11 % Refer to licensing information at http://www.artifex.com or contact
12 % Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco,
13 % CA 94129, USA, for further information.
14 %
15
16 % Postscript interface routines to DSC parser
17
18 /send_orientation { % <orientation> send_orientation -
19 % .parse_dsc_comments returns -1 for an Orientation key with an
20 % unrecognized value.
21 dup 0 ge {
22 << /Orientation 2 index >> setpagedevice
23 } if pop
24 } .internalbind def
25
26 % This dictionary contains local handlers for DSC comments.
27 % See header in zdscpars.c for more information.
28 % <dsc_dict> handler <dsc_dict>
29 /DSCparseprocs mark
30 /Orientation { dup /Orientation get send_orientation } .internalbind
31 /PageOrientation { dup /PageOrientation .knownget { send_orientation }
32 { dup /Orientation .knownget { send_orientation } if }
33 ifelse } .internalbind
34 /Page { dup /Orientation .knownget { send_orientation } if } .internalbind
35 /NOP { } .internalbind
36 .dicttomark readonly def
37
38 % This procedure is called whenever a DSC comment is found by the interpreter
39 /do_parse_dsc //false def
40 /parse_dsc { % <file> <DSC string> [<prev proc>]
41 % parse_dsc -
42 % Run any previously installed parser.
43 0 get dup //null eq { pop } { 3 copy exec pop } ifelse
44
45 do_parse_dsc { % Check if this parser is enabled
46 currentglobal //true setglobal % Go to global VM, save old state
47 3 1 roll % Put old VM state under <file> <string>
48 dsc_dict exch % <VM state> <file> <dict> <string>
49 .parse_dsc_comments % <VM state> <file> <dict> <DSC name>
50 4 -1 roll % Get old VM state from under <file> <dict> <DSC name>
51 setglobal % restore previous VM state
52 //DSCparseprocs exch .knownget { % Check DSC name against local handler list
53 exec % execute any local handler
54 } if
55 } if
56 pop pop % remove file, dict
57 } .internalbind def
58
59 % Check whether the currently installed parser is the one defined in this file.
60 /.using_parse_dsc { % - .using_parse_dsc <proc> <using?>
61 currentuserparams /ProcessDSCComment get
62 dup //null eq { pop {{//null} //parse_dsc exec} } if
63 dup length 3 eq {
64 dup dup length 1 sub get /parse_dsc load eq
65 } {
66 //false
67 } ifelse
68 } .internalbind def
69
70 % Establish a .internalbinding for dsc_dict.
71 userdict /dsc_dict //null put
72
73 % - dsc_init -
74 /dsc_init { % Initialize DSC parser
75 currentglobal //true setglobal
76 /dsc_dict 50 dict store % Size must be large enough for all DSC values
77 dsc_dict .initialize_dsc_parser
78 .using_parse_dsc {
79 % Already using this parser.
80 pop
81 } {
82 % Encapsulate the previous parser. We know it is in global VM:
83 % allocate the new one in global VM as well.
84 1 array astore
85 /parse_dsc load /exec load 3 array astore cvx readonly
86 << /ProcessDSCComment 3 -1 roll >>
87 setuserparams
88 } ifelse
89 setglobal
90 /do_parse_dsc //true def
91 } .internalbind def
92
93 % Enable the DSC parser defined in this file.
94 % - enable_dsc -
95 /enable_dsc {
96 dsc_init
97 } .internalbind def
98
99 % Disable the DSC parser defined in this file.
100 % - disable_dsc -
101 /disable_dsc {
102 % There might be another parser installed: if so, restore it.
103 % (If it has encapsulated our parser, we can't.)
104 .using_parse_dsc {
105 % Restore the parser we encapsulated.
106 0 get 0 get
107 currentglobal //true setglobal exch
108 << /ProcessDSCComment 3 -1 roll >>
109 exch setglobal setuserparams
110 } {
111 pop
112 } ifelse
113 % If we couldn't restore the old parser, at least disable ours.
114 /do_parse_dsc //false def
115 } .internalbind def