gs_frsd.ps 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. % Copyright (C) 2000 Aladdin Enterprises. All rights reserved.
  2. %
  3. % This software is provided AS-IS with no warranty, either express or
  4. % implied.
  5. %
  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.
  9. %
  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.
  15. % $Id: gs_frsd.ps,v 1.9 2005/08/25 15:34:08 ray Exp $
  16. % Implementation of ReusableStreamDecode filter.
  17. % This file must be loaded after gs_lev2.ps and gs_res.ps.
  18. level2dict begin
  19. % ------ ReusableStreamDecode filter ------ %
  20. /.reusablestreamdecode { % <source> <dict> .reusablestreamdecode <file>
  21. % <source> .reusablestreamdecode <file>
  22. % Collect the filter parameters.
  23. dup type /dicttype eq { 2 copy } { dup 0 dict } ifelse
  24. dup .rsdparams
  25. % Construct the filter pipeline.
  26. % The very first filter should use the value of CloseSource
  27. % from the RSD dictionary; all the others should have
  28. % CloseSource = true.
  29. % Stack: source dict filters parms
  30. 2 index /CloseSource .knownget not { false } if 5 -1 roll
  31. % Stack: dict filters parms CloseSource source
  32. 0 1 5 index length 1 sub {
  33. 4 index 1 index get
  34. % Stack: dict filters parms CloseSource source index filtname
  35. 4 index null eq {
  36. 0 dict
  37. } {
  38. 4 index 2 index get dup null eq { pop } if
  39. } ifelse
  40. 3 -1 roll pop exch filter
  41. exch pop true exch % set CloseSource for further filters
  42. } for
  43. % If AsyncRead is true, try to create the filter directly.
  44. % Stack: dict filters parms CloseSource source
  45. 4 index /AsyncRead .knownget not { false } if {
  46. 1 index { .reusablestream } .internalstopped
  47. } {
  48. null true
  49. } ifelse {
  50. pop
  51. % No luck. Read the entire contents of the stream now.
  52. dup type /filetype ne {
  53. % Make a stream from a procedure or string data source.
  54. 0 () .subfiledecode
  55. } if
  56. 10 dict exch {
  57. % Stack: dict filters parms CloseSource contdict file
  58. dup 64000 string readstring
  59. 3 index dup length 4 -1 roll put not { exit } if
  60. } loop pop
  61. % Concatenate the contents into one big string.
  62. % Stack: dict filters parms CloseSource contdict
  63. 0 1 index { length exch pop add } forall
  64. dup 65400 gt { .bytestring } { string } ifelse exch {
  65. % Stack: dict filters parms CloseSource string index substring
  66. exch 64000 mul exch 2 index 3 1 roll putinterval
  67. } forall
  68. % Now create the stream on the string.
  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. filterdict /ReusableStreamDecode /.reusablestreamdecode load put
  76. end % level2dict