1 % Copyright (C) 2000 Artifex Software Inc. All rights reserved.
3 % This software is provided AS-IS with no warranty, either express or
6 % This software is distributed under license and may not be copied,
7 % modified or distributed except as expressly authorized under the terms
8 % of the license contained in the file LICENSE in this distribution.
10 % For more information about licensing, please refer to
11 % http://www.ghostscript.com/licensing/. For information on
12 % commercial licensing, go to http://www.artifex.com/licensing/ or
13 % contact Artifex Software, Inc., 101 Lucas Valley Road #110,
14 % San Rafael, CA 94903, U.S.A., +1(415)492-9861.
16 % $Id: gs_dscp.ps,v 1.6 2002/02/21 21:49:28 giles Exp $
17 % Postscript interface routines to DSC parser
19 /send_orientation { % <orientation> send_orientation -
20 % .parse_dsc_comments returns -1 for an Orientation key with an
23 << /Orientation 2 index >> setpagedevice
27 % This dictionary contains local handlers for DSC comments.
28 % See header in zdscpars.c for more information.
29 % <dsc_dict> handler <dsc_dict>
31 /Orientation { dup /Orientation get send_orientation } bind
32 /PageOrientation { dup /PageOrientation .knownget { send_orientation }
33 { dup /Orientation .knownget { send_orientation } if }
35 /Page { dup /Orientation .knownget { send_orientation } if } bind
37 .dicttomark readonly def
39 % This procedure is called whenever a DSC comment is found by the interpreter
40 /do_parse_dsc false def
41 /parse_dsc { % <file> <DSC string> [<prev proc>]
43 % Run any previously installed parser.
44 0 get dup null eq { pop } { 3 copy exec pop } ifelse
46 do_parse_dsc { % Check if this parser is enabled
47 currentglobal true setglobal % Go to global VM, save old state
48 3 1 roll % Put old VM state under <file> <string>
49 dsc_dict exch % <VM state> <file> <dict> <string>
50 .parse_dsc_comments % <VM state> <file> <dict> <DSC name>
51 4 -1 roll % Get old VM state from under <file> <dict> <DSC name>
52 setglobal % restore previous VM state
53 //DSCparseprocs exch .knownget { % Check DSC name against local handler list
54 exec % execute any local handler
57 pop pop % remove file, dict
61 % Check whether the currently installed parser is the one defined in this file.
62 /.using_parse_dsc { % - .using_parse_dsc <proc> <using?>
63 currentuserparams /ProcessDSCComment get
64 dup null eq { pop {{//null} //parse_dsc exec} } if
66 dup dup length 1 sub get /parse_dsc load eq
72 % Establish a binding for dsc_dict.
73 userdict /dsc_dict null put
76 /dsc_init { % Initialize DSC parser
77 currentglobal true setglobal
78 /dsc_dict 50 dict store % Size must be large enough for all DSC values
79 dsc_dict .initialize_dsc_parser
81 % Already using this parser.
84 % Encapsulate the previous parser. We know it is in global VM:
85 % allocate the new one in global VM as well.
87 /parse_dsc load /exec load 3 array astore cvx readonly
88 << /ProcessDSCComment 3 -1 roll >>
92 /do_parse_dsc true def
96 % Enable the DSC parser defined in this file.
102 % Disable the DSC parser defined in this file.
105 % There might be another parser installed: if so, restore it.
106 % (If it has encapsulated our parser, we can't.)
108 % Restore the parser we encapsulated.
110 currentglobal true setglobal exch
111 << /ProcessDSCComment 3 -1 roll >>
112 exch setglobal setuserparams
116 % If we couldn't restore the old parser, at least disable ours.
117 /do_parse_dsc false def