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

  1. %    Copyright (C) 1994 Aladdin Enterprises.  All rights reserved.
  2.  
  3. % gs_pdf.ps
  4. % ProcSet for PostScript files created by the PDF to PostScript converter.
  5.  
  6. % This ProcSet is designed so that it can be used either to execute PDF
  7. % (the default) or to convert PDF to PostScript.  It records "operator"
  8. % names in a dictionary with their argument counts, so that they can
  9. % easily be redefined later to write PostScript in addition to
  10. % (or instead of) being executed.
  11. %
  12. % Currently, the ProcSet requires a Level 2 interpreter.  This is only
  13. % needed for the general case of image and imagemask; all other
  14. % Level 2 constructs revert to Level 1 equivalents if needed.
  15.  
  16. % Level 2 patches:
  17. /currentglobal false
  18. /setglobal { pop } bind
  19. /packedarray { array astore readonly } bind
  20. 3 { 1 index where { pop pop pop } { def } ifelse } repeat
  21.  
  22. currentglobal true setglobal
  23.  
  24. % Define pdfmark if needed.  Don't allow it to be bound in.
  25. systemdict wcheck { systemdict } { userdict } ifelse
  26. /pdfmark { cleartomark } bind put
  27.  
  28. userdict /GS_PDF_ProcSet 100 dict dup begin
  29.  
  30. % Abbreviations:
  31. /bdef
  32.  { bind def
  33.  } bind def
  34.  
  35. % Operator execution:
  36. /numargsdict 100 dict def
  37. /!        % <procname> <proc> <numargs> ! -
  38.  { //numargsdict 3 index 3 -1 roll put def
  39.  } bdef
  40. /~        % <procname> <opname> <numargs> ~ -
  41.  { exch load 1 packedarray cvx exch !
  42.  } bdef
  43.  
  44. % Graphics state operations:
  45. /q /gsave 0 ~ 
  46. /Q /grestore 0 ~
  47. /d /setdash 2 ~
  48. /i /setflat 1 ~
  49. /j /setlinejoin 1 ~
  50. /J /setlinecap 1 ~
  51. /M /setmiterlimit 1 ~
  52. /w /setlinewidth 1 ~
  53. /g /setgray 1 ~
  54. /rg /setrgbcolor 3 ~
  55. /k /setcmykcolor where
  56.  { pop /setcmykcolor 4 ~
  57.  }
  58.  { { 1 exch sub
  59.      4 -1 roll 1 exch sub 1 index mul
  60.      4 -1 roll 1 exch sub 2 index mul
  61.      4 -2 roll exch 1 exch sub mul
  62.      setrgbcolor
  63.    } 4 !
  64.  }
  65. ifelse
  66.  
  67. % Transformations:
  68. /ct /translate 2 ~
  69. /cs /scale 2 ~
  70. /cm /concat 1 ~
  71.  
  72. % Path creation:
  73. /p /currentpoint 0 ~
  74. /m /moveto 2 ~
  75. /l /lineto 2 ~
  76. /c /curveto 6 ~
  77. /h /closepath 0 ~
  78. /v { currentpoint 6 2 roll curveto } 4 !
  79. /y { 2 copy curveto } 4 !
  80. /re
  81.  { 4 2 roll moveto  exch dup 0 rlineto  0 3 -1 roll rlineto  neg 0 rlineto
  82.    closepath
  83.  } 4 !
  84.  
  85. % Path painting:
  86. /S_ { stroke } bdef        % don't allow S_ to get bound in
  87. /S { S_ } 0 !
  88. /f /fill 0 ~
  89. /f* /eofill 0 ~
  90. /n_ { newpath } bdef        % don't allow n_ to get bound in
  91. /n { n_ } 0 !
  92. /s { closepath S_ } 0 !
  93. /B_ { gsave fill grestore S_ } bdef
  94. /B /B_ load 0 !
  95. /b { closepath B_ } 0 !
  96. /B*_ { gsave eofill grestore S_ } bdef
  97. /B* /B*_ load 0 !
  98. /b* { closepath B*_ } 0 !
  99.  
  100. % Clipping:
  101. /Wdict 4 dict dup begin
  102. /S_ { gsave stroke grestore n_ } bdef
  103. /f { gsave fill grestore n_ } 0 !
  104. /f* { gsave eofill grestore n_ } 0 !
  105. /n_ { end clip newpath } bdef
  106. end readonly def
  107. /W { //Wdict begin } 0 !
  108. /W*dict 4 dict dup begin
  109. /S_ { gsave stroke grestore n_ } bdef
  110. /f { gsave fill grestore n_ } 0 !
  111. /f* { gsave eofill grestore n_ } 0 !
  112. /n_ { end eoclip newpath } bdef
  113. end readonly def
  114. /W* { //W*dict begin } 0 !
  115.  
  116. % Images:
  117. % We mustn't bind these now, since they are Level 2 operators.
  118. /Is        % <imagedict> Is <imagedict> <datasource>
  119.  { dup /DataSource get string
  120.    currentfile /ASCII85Decode filter /RunLengthDecode filter exch
  121.     { readstring pop }
  122.    aload length 2 add packedarray cvx
  123.  } bdef
  124. /Ie { } def    % placeholder, only needed when writing PostScript
  125. /I    % <colorspace> <imagedict> I -
  126.  { exch setcolorspace Is 1 index /DataSource 3 -1 roll put
  127.    /image cvx exec Ie
  128.  } 2 !
  129. /Im    % <imagedict> Im -
  130.  { Is 1 index /DataSource 3 -1 roll put
  131.    /imagemask cvx exec Ie
  132.  } 1 !
  133.  
  134. % Text control:
  135. /Tmatrix matrix def
  136. /BT { //Tmatrix currentmatrix pop 0 0 moveto } 0 !
  137. /ti { //Tmatrix setmatrix } 0 !
  138. /z { 0 0 moveto } 0 !
  139. /Tf { exch dup type /dicttype ne { findfont } if exch scalefont setfont } 2 !
  140. /ET { //Tmatrix setmatrix } 0 !
  141.  
  142. % Text painting:
  143. /t /show 1 ~
  144. /t1        % <xchar> <string> t1 -
  145.  { 0 exch ashow
  146.  } 2 !
  147. /t2        % <xword> <string> t2 -
  148.  { 0 exch 32 exch widthshow
  149.  } 2 !
  150. /t3        % <xword> <xchar> <string> t3 -
  151.  { 0 32 4 2 roll 0 exch awidthshow
  152.  } 3 !
  153. /T { false charpath } 1 !
  154. /T3        % <xword> <xchar> <string> T3 -
  155.  {    % Implement the combination of t3 and false charpath.
  156.    0 1 2 index length 1 sub
  157.     { 2 copy 1 getinterval false charpath
  158.       4 copy get 32 eq { add } { exch pop } ifelse 0 rmoveto
  159.     }
  160.    for pop pop pop
  161.  } 3 !
  162. /tf { currentpoint fill moveto } 0 !
  163. /tS { currentpoint stroke moveto } 0 !
  164. /tB { currentpoint gsave fill grestore stroke moveto } 0 !
  165. /tn { currentpoint newpath moveto } 0 !
  166. /x { 0 rmoveto } 1 !
  167.  
  168. end readonly put        % GS_PDF_ProcSet
  169.  
  170. setglobal
  171.