gs_epsf.ps 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. % Copyright (C) 1989, 1996 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_epsf.ps,v 1.2 2000/09/19 18:29:11 lpd Exp $
  18. % Allow the interpreter to recognize MS-DOS EPSF file headers, and skip to
  19. % the PostScript section of the file.
  20. /.runnoepsf /run load def
  21. /.epsfheader <C5D0D3C6> def
  22. /run
  23. { dup type /filetype ne { (r) file } if
  24. % Check for MS-DOS EPSF file (see Red Book p. 729).
  25. true exch 0 1 3
  26. { % Stack: true file index
  27. 1 index read dup { pop dup .epsfheader 3 index get eq } if
  28. { pop pop } % if matched, don't need the character
  29. { % unread characters (wasn't EPSF)
  30. 2 index exch unread % unread mismatch character
  31. dup { % loop unreading backwards in .epsfheader
  32. 1 sub dup .epsfheader exch get 2 index exch unread
  33. } repeat pop
  34. exch not exch exit % change true to false
  35. }
  36. ifelse
  37. }
  38. for exch % Stack: file true/false
  39. { % This block is executed if the file is MS-DOS EPSF.
  40. % Build up the little-endian byte offset and length.
  41. 2
  42. { 1 0 4
  43. { 2 index read not { pop exit } if % if EOF, let error happen
  44. 2 index mul add exch 256 mul exch
  45. }
  46. repeat exch pop exch
  47. }
  48. repeat
  49. % Stack: offset length file
  50. % Use flushfile to skip quickly to the start of the
  51. % PostScript section.
  52. dup 4 -1 roll 12 sub () /SubFileDecode filter flushfile
  53. % Now interpret the PostScript.
  54. exch () /SubFileDecode filter cvx .runexec
  55. }
  56. { .runnoepsf
  57. }
  58. ifelse
  59. } odef