1 % Copyright (C) 2000 Aladdin Enterprises. 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_frsd.ps,v 1.9 2005/08/25 15:34:08 ray Exp $
17 % Implementation of ReusableStreamDecode filter.
18 % This file must be loaded after gs_lev2.ps and gs_res.ps.
22 % ------ ReusableStreamDecode filter ------ %
24 /.reusablestreamdecode { % <source> <dict> .reusablestreamdecode <file>
25 % <source> .reusablestreamdecode <file>
26 % Collect the filter parameters.
27 dup type /dicttype eq { 2 copy } { dup 0 dict } ifelse
29 % Construct the filter pipeline.
30 % The very first filter should use the value of CloseSource
31 % from the RSD dictionary; all the others should have
33 % Stack: source dict filters parms
34 2 index /CloseSource .knownget not { false } if 5 -1 roll
35 % Stack: dict filters parms CloseSource source
36 0 1 5 index length 1 sub {
38 % Stack: dict filters parms CloseSource source index filtname
42 4 index 2 index get dup null eq { pop } if
44 3 -1 roll pop exch filter
45 exch pop true exch % set CloseSource for further filters
47 % If AsyncRead is true, try to create the filter directly.
48 % Stack: dict filters parms CloseSource source
49 4 index /AsyncRead .knownget not { false } if {
50 1 index { .reusablestream } .internalstopped
55 % No luck. Read the entire contents of the stream now.
56 dup type /filetype ne {
57 % Make a stream from a procedure or string data source.
61 % Stack: dict filters parms CloseSource contdict file
62 dup 64000 string readstring
63 3 index dup length 4 -1 roll put not { exit } if
65 % Concatenate the contents into one big string.
66 % Stack: dict filters parms CloseSource contdict
67 0 1 index { length exch pop add } forall
68 dup 65400 gt { .bytestring } { string } ifelse exch {
69 % Stack: dict filters parms CloseSource string index substring
70 exch 64000 mul exch 2 index 3 1 roll putinterval
72 % Now create the stream on the string.
73 1 index .reusablestream
75 % We created the stream successfully: clean up.
77 1 index type /dicttype eq { exch pop } if exch pop
80 filterdict /ReusableStreamDecode /.reusablestreamdecode load put