home *** CD-ROM | disk | FTP | other *** search
/ swCHIP 1991 January / swCHIP_95-1.bin / utility / gs333ini / gs3.33 / pdf_2ps.ps < prev    next >
Text File  |  1995-12-09  |  3KB  |  117 lines

  1. %    Copyright (C) 1994, 1995 Aladdin Enterprises.  All rights reserved.
  2.  
  3. % pdf_2ps.ps
  4. % PDF to PostScript additions to PDF reader.
  5.  
  6. GS_PDF_ProcSet begin
  7. pdfdict begin
  8.  
  9. /.setlanguagelevel where { pop 2 .setlanguagelevel } if
  10. .currentglobal true .setglobal
  11.  
  12. % "Wrap" all the runtime operators so they call #exec.
  13. numargsdict
  14.  { 1 index load exch 2 index exch /#exec cvx 4 packedarray cvx def
  15.  }
  16. forall
  17. /pdfmark
  18.   /pdfmark load dup type /operatortype eq { 1 packedarray cvx } if
  19.    { /pdfmark counttomark 1 sub #exec } bind
  20.   aload length 1 add packedarray cvx
  21. def
  22. % Define #exec so it also prints out its arguments.
  23. % Eventually this will move into pdf_base.
  24. /dictwrite#        % <file> <dict> dictwrite# -
  25.  { 2 copy length write=only 1 index ( dict) writestring
  26.     { exch 2 index dup ( dup ) writestring exch write#
  27.       1 index dup ( ) writestring exch write#
  28.       dup ( put) writestring
  29.     }
  30.    forall pop
  31.  } bdef
  32. /write#dict 10 dict dup begin
  33.   /arraytype
  34.    { dup xcheck { (}) ({) } { (]) ([) } ifelse
  35.      2 index length 0 eq
  36.       { 3 index exch writestring exch
  37.       }
  38.       { 3 -1 roll
  39.      { 3 index 2 index writestring 3 index exch write# pop ( ) }
  40.     forall
  41.       }
  42.      ifelse pop writestring
  43.    } bdef
  44.   /dicttype
  45.    { dictwrite#
  46.    } bdef
  47.   /marktype
  48.    { pop ([) writestring
  49.    } bdef
  50. end def
  51. /write#
  52.  { dup type //write#dict exch .knownget { exec } { write==only } ifelse
  53.  } bind def
  54.  
  55. % Rebind the procedures that conditionally write out PostScript.
  56.  
  57. /#            % <arg1> ... <argN> <opname> <N> # -
  58.  { 1 index load 3 1 roll #exec
  59.  } bdef
  60. /#exec        % <arg1> ... <argN> <proc|operator> <opname> <N> #exec -
  61.  { /PSout where
  62.     { pop -1 1 { 1 add index PSout exch write# PSout ( ) writestring } for
  63.       PSout exch write=
  64.     }
  65.     { pop pop
  66.     }
  67.    ifelse exec
  68.  } bdef
  69. /#dsc        % mark <obj1> ... #dsc -
  70.  { /PSout where
  71.     { pop counttomark
  72.        { counttomark -1 roll PSout exch write=only }
  73.       repeat pop PSout (\n) writestring
  74.     }
  75.     { cleartomark
  76.     }
  77.    ifelse
  78.  } bdef
  79.  
  80. % Rebind Is, which constructs a data source for an image.
  81. % pdf_draw already redefined it to retrieve the stream.
  82. /Is_draw /Is load def
  83. /Ie_draw /Ie load def
  84. userdict /Is_string null put    % establish a binding
  85. /Is        % <imagedict> Is <imagedict> <datasource>
  86.  { /PSout where
  87.     { dup /DataSource get string /Is_string exch store
  88.       /PStext PSout /ASCII85Encode filter def
  89.       /PSdata PStext Is_string length /RunLengthEncode filter def
  90.       Is_draw
  91.        { Is_string readstring pop PSdata 1 index writestring }
  92.       aload length 1 add packedarray cvx
  93.     }
  94.     { Is_draw
  95.     }
  96.    ifelse
  97.  } bdef
  98. /Ie
  99.  { /PSout where { pop PSdata closefile PStext closefile } { Ie_draw } ifelse
  100.  } bdef
  101.  
  102. % Rebind readfontfilter, which constructs the filter that
  103. % reads the text of an embedded Type 1 (and eventually Type 3) font.
  104. /readfontfilter_orig /readfontfilter load def
  105. /readfontfilter        % <proc> readfontfilter <filter>
  106.  { /copyfontdata cvx 2 array astore cvx
  107.    0 () /SubFileDecode filter
  108.  } bdef
  109. /copyfontdata        % <string> <origproc> copyfontdata <substring>
  110.  { exec /PSout where { pop PSout 1 index writestring } if
  111.  } bdef
  112.  
  113. end        % pdfdict
  114.  
  115. .setglobal
  116. end        % GS_PDF_ProcSet
  117.