home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / ghostscript / 8.64 / Resource / Init / gs_frsd.ps < prev    next >
Encoding:
Text File  |  2009-04-17  |  2.9 KB  |  82 lines

  1. %    Copyright (C) 2000 Aladdin Enterprises.  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_frsd.ps 8954 2008-08-08 04:22:38Z ray $
  14. % Implementation of ReusableStreamDecode filter.
  15. % This file must be loaded after gs_lev2.ps and gs_res.ps.
  16.  
  17. level2dict begin
  18.  
  19. % ------ ReusableStreamDecode filter ------ %
  20.  
  21. /.reusablestreamdecode {    % <source> <dict> .reusablestreamdecode <file>
  22.                 % <source> .reusablestreamdecode <file>
  23.         % Collect the filter parameters.
  24.   dup type /dicttype eq { 2 copy } { dup 0 dict } ifelse
  25.   dup .rsdparams
  26.         % Construct the filter pipeline.
  27.         % The very first filter should use the value of CloseSource
  28.         % from the RSD dictionary; all the others should have
  29.         % CloseSource = true.
  30.         % Stack: source dict filters parms
  31.   2 index /CloseSource .knownget not { //false } if 5 -1 roll
  32.         % Stack: dict filters parms CloseSource source
  33.   0 1 5 index length 1 sub {
  34.     4 index 1 index get
  35.         % Stack: dict filters parms CloseSource source index filtname
  36.     4 index //null eq {
  37.       0 dict
  38.     } {
  39.       4 index 2 index get dup //null eq { pop } if
  40.     } ifelse
  41.     3 -1 roll pop exch filter
  42.     exch pop //true exch        % set CloseSource for further filters
  43.   } for
  44.         % If AsyncRead is true, try to create the filter directly.
  45.         % Stack: dict filters parms CloseSource source
  46.   4 index /AsyncRead .knownget not { //false } if {
  47.     1 index { .reusablestream } .internalstopped
  48.   } {
  49.     //null //true
  50.   } ifelse {
  51.     pop
  52.         % No luck.  Read the entire contents of the stream now.
  53.     dup type /filetype ne {
  54.         % Make a stream from a procedure or string data source.
  55.       0 () .subfiledecode
  56.     } if
  57.         % We must allocate the string in the same VM space as its
  58.         % source, since the reusable stream must be allocated there.
  59.  
  60.     .currentglobal 1 index gcheck .setglobal exch
  61.     currentpacking //false setpacking exch
  62.                % Stack: dict filters parms CloseSource oldglobal oldpacking file
  63.     [ exch { dup 40000 string readstring not { exit } if exch } loop
  64.       exch pop
  65.     ]
  66.                       % Stack: dict filters parms CloseSource oldglobal oldpacking [()...]
  67.     3 1 roll setpacking setglobal
  68.                       % Stack: dict filters parms CloseSource [()...]
  69.     1 index .reusablestream
  70.   } if
  71.         % We created the stream successfully: clean up.
  72.   4 { exch pop } repeat
  73.   1 index type /dicttype eq { exch pop } if exch pop
  74. } odef
  75.  
  76. filterdict /ReusableStreamDecode /.reusablestreamdecode load put
  77.  
  78. end            % level2dict
  79.