gs_frsd.ps 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. % Copyright (C) 2000 Aladdin Enterprises. All rights reserved.
  2. %
  3. % This file is part of AFPL Ghostscript.
  4. %
  5. % AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND. No author or
  6. % distributor accepts any responsibility for the consequences of using it, or
  7. % for whether it serves any particular purpose or works at all, unless he or
  8. % she says so in writing. Refer to the Aladdin Free Public License (the
  9. % "License") for full details.
  10. %
  11. % Every copy of AFPL Ghostscript must include a copy of the License, normally
  12. % in a plain ASCII text file named PUBLIC. The License grants you the right
  13. % to copy, modify and redistribute AFPL Ghostscript, but only under certain
  14. % conditions described in the License. Among other things, the License
  15. % requires that the copyright notice and this notice be preserved on all
  16. % copies.
  17. % $Id: gs_frsd.ps,v 1.4 2000/09/19 18:29:11 lpd Exp $
  18. % Implementation of ReusableStreamDecode filter.
  19. % This file must be loaded after gs_lev2.ps and gs_res.ps.
  20. level2dict begin
  21. % ------ ReusableStreamDecode filter ------ %
  22. /.reusablestreamdecode { % <source> <dict> .reusablestreamdecode <file>
  23. % <source> .reusablestreamdecode <file>
  24. % Collect the filter parameters.
  25. dup type /dicttype eq { 2 copy } { dup 0 dict } ifelse
  26. dup .rsdparams
  27. % Construct the filter pipeline.
  28. % The very first filter should use the value of CloseSource
  29. % from the RSD dictionary; all the others should have
  30. % CloseSource = true.
  31. % Stack: source dict filters parms
  32. 2 index /CloseSource .knownget not { false } if 5 -1 roll
  33. % Stack: dict filters parms CloseSource source
  34. 0 1 5 index length 1 sub {
  35. 4 index 1 index get
  36. % Stack: dict filters parms CloseSource source index filtname
  37. 4 index null eq {
  38. 0 dict
  39. } {
  40. 4 index 2 index get dup null eq { pop } if
  41. } ifelse
  42. 3 -1 roll pop exch filter
  43. exch pop true exch % set CloseSource for further filters
  44. } for
  45. % If AsyncRead is true, try to create the filter directly.
  46. % Stack: dict filters parms CloseSource source
  47. 4 index /AsyncRead .knownget not { false } if {
  48. 1 index { .reusablestream } .internalstopped
  49. } {
  50. null true
  51. } ifelse {
  52. pop
  53. % No luck. Read the entire contents of the stream now.
  54. dup type /filetype ne {
  55. % Make a stream from a procedure or string data source.
  56. 0 () .subfiledecode
  57. } if
  58. 10 dict exch {
  59. % Stack: dict filters parms CloseSource contdict file
  60. dup 1000 string readstring
  61. 3 index dup length 4 -1 roll put not { exit } if
  62. } loop pop
  63. % Concatenate the contents into one big string.
  64. % Stack: dict filters parms CloseSource contdict
  65. 0 1 index { length exch pop add } forall
  66. .bigstring exch {
  67. % Stack: dict filters parms CloseSource string index substring
  68. exch 1000 mul exch 2 index 3 1 roll putinterval
  69. } forall
  70. % Now create the stream on the string.
  71. 1 index .reusablestream
  72. } if
  73. % We created the stream successfully: clean up.
  74. 4 { exch pop } repeat
  75. 1 index type /dicttype eq { exch pop } if exch pop
  76. } odef
  77. filterdict /ReusableStreamDecode /.reusablestreamdecode load put
  78. end % level2dict