home *** CD-ROM | disk | FTP | other *** search
/ PC World 2001 September / PCWorld_2001-09_cd.bin / Software / Vyzkuste / rychlokurz / gs700w32.exe / gs7.00 / lib / gs_dscp.ps < prev    next >
Text File  |  2001-03-12  |  4KB  |  121 lines

  1. %  Copyright (C) 2000 Artifex Software Inc.   All rights reserved.
  2. % This file is part of AFPL Ghostscript.
  3. % AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author or
  4. % distributor accepts any responsibility for the consequences of using it, or
  5. % for whether it serves any particular purpose or works at all, unless he or
  6. % she says so in writing.  Refer to the Aladdin Free Public License (the
  7. % "License") for full details.
  8. % Every copy of AFPL Ghostscript must include a copy of the License, normally
  9. % in a plain ASCII text file named PUBLIC.  The License grants you the right
  10. % to copy, modify and redistribute AFPL Ghostscript, but only under certain
  11. % conditions described in the License.  Among other things, the License
  12. % requires that the copyright notice and this notice be preserved on all
  13. % copies.
  14.  
  15. % $Id: gs_dscp.ps,v 1.4 2001/03/12 22:41:22 dancoby Exp $
  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. } bind 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 } bind
  31.    /PageOrientation { dup /PageOrientation .knownget { send_orientation }
  32.               { dup /Orientation .knownget { send_orientation } if }
  33.               ifelse } bind
  34.    /Page { dup /Orientation .knownget { send_orientation } if } bind
  35.    /NOP { } bind
  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. } bind def
  58.  
  59.  
  60. % Check whether the currently installed parser is the one defined in this file.
  61. /.using_parse_dsc {            % - .using_parse_dsc <proc> <using?>
  62.   currentuserparams /ProcessDSCComment get
  63.   dup null eq { pop {{//null} //parse_dsc exec} } if
  64.   dup length 3 eq {
  65.     dup dup length 1 sub get /parse_dsc load eq
  66.   } {
  67.     false
  68.   } ifelse
  69. } bind def
  70.  
  71. % Establish a binding for dsc_dict.
  72. userdict /dsc_dict null put
  73.  
  74. % - dsc_init -
  75. /dsc_init {                % Initialize DSC parser
  76.   currentglobal true setglobal
  77.   /dsc_dict 50 dict store        % Size must be large enough for all DSC values
  78.   dsc_dict .initialize_dsc_parser
  79.   .using_parse_dsc {
  80.     % Already using this parser.
  81.     pop
  82.   } {
  83.     % Encapsulate the previous parser.  We know it is in global VM:
  84.     % allocate the new one in global VM as well.
  85.     1 array astore
  86.     /parse_dsc load /exec load 3 array astore cvx readonly
  87.     << /ProcessDSCComment 3 -1 roll >>
  88.     setuserparams
  89.   } ifelse
  90.   setglobal
  91.   /do_parse_dsc true def
  92. } bind def
  93.  
  94.  
  95. % Enable the DSC parser defined in this file.
  96. % - enable_dsc -
  97. /enable_dsc {
  98.   dsc_init
  99. } bind def
  100.  
  101. % Disable the DSC parser defined in this file.
  102. % - disable_dsc -
  103. /disable_dsc {
  104.     % There might be another parser installed: if so, restore it.
  105.     % (If it has encapsulated our parser, we can't.)
  106.   .using_parse_dsc {
  107.     % Restore the parser we encapsulated.
  108.     0 get 0 get
  109.     currentglobal true setglobal exch
  110.     << /ProcessDSCComment 3 -1 roll >>
  111.     exch setglobal setuserparams
  112.   } {
  113.     pop
  114.   } ifelse
  115.     % If we couldn't restore the old parser, at least disable ours.
  116.   /do_parse_dsc false def
  117. } bind def
  118.