home *** CD-ROM | disk | FTP | other *** search
/ jppd.dyndns.org / jppd.dyndns.org.tar / jppd.dyndns.org / QUERYPRO / Actualizar / Impressora_PDF / converter.exe / GPLGS / gs_dscp.ps < prev    next >
Text File  |  2002-02-22  |  4KB  |  119 lines

  1. %  Copyright (C) 2000 Artifex Software Inc.   All rights reserved.
  2. % This software is provided AS-IS with no warranty, either express or
  3. % implied.
  4. % This software is distributed under license and may not be copied,
  5. % modified or distributed except as expressly authorized under the terms
  6. % of the license contained in the file LICENSE in this distribution.
  7. % For more information about licensing, please refer to
  8. % http://www.ghostscript.com/licensing/. For information on
  9. % commercial licensing, go to http://www.artifex.com/licensing/ or
  10. % contact Artifex Software, Inc., 101 Lucas Valley Road #110,
  11. % San Rafael, CA  94903, U.S.A., +1(415)492-9861.
  12.  
  13. % $Id: gs_dscp.ps,v 1.6 2002/02/21 21:49:28 giles Exp $
  14. %  Postscript interface routines to DSC parser
  15.  
  16. /send_orientation {            % <orientation> send_orientation -
  17.     % .parse_dsc_comments returns -1 for an Orientation key with an
  18.     % unrecognized value.
  19.   dup 0 ge {
  20.     << /Orientation 2 index >> setpagedevice
  21.   } if pop
  22. } bind def
  23.  
  24. % This dictionary contains local handlers for DSC comments.
  25. % See header in zdscpars.c for more information.
  26. % <dsc_dict> handler <dsc_dict>
  27. /DSCparseprocs mark
  28.    /Orientation { dup /Orientation get send_orientation } bind
  29.    /PageOrientation { dup /PageOrientation .knownget { send_orientation }
  30.               { dup /Orientation .knownget { send_orientation } if }
  31.               ifelse } bind
  32.    /Page { dup /Orientation .knownget { send_orientation } if } bind
  33.    /NOP { } bind
  34. .dicttomark readonly def
  35.  
  36. % This procedure is called whenever a DSC comment is found by the interpreter
  37. /do_parse_dsc false def
  38. /parse_dsc {                % <file> <DSC string> [<prev proc>]
  39.                     %   parse_dsc -
  40.     % Run any previously installed parser.
  41.   0 get dup null eq { pop } { 3 copy exec pop } ifelse
  42.  
  43.   do_parse_dsc {            % Check if this parser is enabled
  44.     currentglobal true setglobal    % Go to global VM, save old state
  45.     3 1 roll                % Put old VM state under <file> <string>
  46.     dsc_dict exch            % <VM state> <file> <dict> <string>
  47.     .parse_dsc_comments            % <VM state> <file> <dict> <DSC name>
  48.     4 -1 roll                % Get old VM state from under <file> <dict> <DSC name>
  49.     setglobal                % restore previous VM state
  50.     //DSCparseprocs exch .knownget {    % Check DSC name against local handler list
  51.       exec                % execute any local handler
  52.     } if
  53.   } if
  54.   pop pop                % remove file, dict
  55. } bind def
  56.  
  57.  
  58. % Check whether the currently installed parser is the one defined in this file.
  59. /.using_parse_dsc {            % - .using_parse_dsc <proc> <using?>
  60.   currentuserparams /ProcessDSCComment get
  61.   dup null eq { pop {{//null} //parse_dsc exec} } if
  62.   dup length 3 eq {
  63.     dup dup length 1 sub get /parse_dsc load eq
  64.   } {
  65.     false
  66.   } ifelse
  67. } bind def
  68.  
  69. % Establish a binding for dsc_dict.
  70. userdict /dsc_dict null put
  71.  
  72. % - dsc_init -
  73. /dsc_init {                % Initialize DSC parser
  74.   currentglobal true setglobal
  75.   /dsc_dict 50 dict store        % Size must be large enough for all DSC values
  76.   dsc_dict .initialize_dsc_parser
  77.   .using_parse_dsc {
  78.     % Already using this parser.
  79.     pop
  80.   } {
  81.     % Encapsulate the previous parser.  We know it is in global VM:
  82.     % allocate the new one in global VM as well.
  83.     1 array astore
  84.     /parse_dsc load /exec load 3 array astore cvx readonly
  85.     << /ProcessDSCComment 3 -1 roll >>
  86.     setuserparams
  87.   } ifelse
  88.   setglobal
  89.   /do_parse_dsc true def
  90. } bind def
  91.  
  92.  
  93. % Enable the DSC parser defined in this file.
  94. % - enable_dsc -
  95. /enable_dsc {
  96.   dsc_init
  97. } bind 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. } bind def
  116.