1
0

hardcopy.ps 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. %
  2. % Redefiniton of the PostScript file output operators so results go to paper.
  3. % Complicated and slow, but the implementation doesn't place many demands on
  4. % included PostScript. About all that's required is gentle treatment of the
  5. % graphics state between write calls.
  6. %
  7. /#copies 1 store
  8. /aspectratio 1 def
  9. /font /Courier def
  10. /formsperpage 1 def
  11. /landscape false def
  12. /magnification 1 def
  13. /orientation 0 def
  14. /pointsize 10 def
  15. /rotation 1 def
  16. /xoffset .1 def
  17. /yoffset .1 def
  18. /roundpage true def
  19. /useclippath true def
  20. /pagebbox [0 0 612 792] def
  21. /inch {72 mul} def
  22. /min {2 copy gt {exch} if pop} def
  23. /HardcopySetup {
  24. landscape {/orientation 90 orientation add def} if
  25. font findfont 1 1.1 div scalefont setfont
  26. pagedimensions
  27. xcenter ycenter translate
  28. orientation rotation mul rotate
  29. width 2 div neg height 2 div translate
  30. xoffset inch yoffset inch neg translate
  31. pointsize 1.1 mul dup scale
  32. magnification dup aspectratio mul scale
  33. height width div 1 min dup scale
  34. 0 -1 translate
  35. 0 0 moveto
  36. } def
  37. /pagedimensions {
  38. useclippath {
  39. /pagebbox [clippath pathbbox newpath] def
  40. roundpage currentdict /roundpagebbox known and {roundpagebbox} if
  41. } if
  42. pagebbox aload pop
  43. 4 -1 roll exch 4 1 roll 4 copy
  44. landscape {4 2 roll} if
  45. sub /width exch def
  46. sub /height exch def
  47. add 2 div /xcenter exch def
  48. add 2 div /ycenter exch def
  49. } def
  50. %
  51. % Unbind the operators in an executable array or packedarray. Leaves the
  52. % unbound array or the original object on the stack.
  53. %
  54. /Unbind {
  55. 0 index xcheck
  56. 1 index type /arraytype eq
  57. 2 index type /packedarraytype eq or and {
  58. dup length array copy cvx
  59. dup 0 exch {
  60. dup type /operatortype eq {
  61. ( ) cvs cvn cvx
  62. } if
  63. dup type /dicttype eq {
  64. dup maxlength dict exch {
  65. Unbind
  66. 3 copy put pop pop
  67. } forall
  68. } if
  69. 0 index xcheck
  70. 1 index type /arraytype eq
  71. 2 index type /packedarraytype eq or and {
  72. Unbind
  73. } if
  74. 3 copy put pop
  75. 1 add
  76. } forall
  77. pop
  78. } if
  79. } def
  80. %
  81. % New write operator - don't bind the definition! Expands tabs and backspaces,
  82. % wraps long lines, and starts a new page whenever necessary. The code that
  83. % handles newlines assumes lines are separated by one vertical unit.
  84. %
  85. /write {
  86. true exch
  87. %%case '\b':
  88. dup 8#10 eq {
  89. ( ) stringwidth pop neg 0 rmoveto
  90. currentpoint pop 0 lt {
  91. currentpoint exch pop 0 exch moveto
  92. } if
  93. exch pop false exch
  94. } if
  95. %%case '\t':
  96. dup 8#11 eq {
  97. currentpoint pop ( ) stringwidth pop div round cvi
  98. 8 mod 8 exch sub {
  99. 2 index 8#40 write
  100. } repeat
  101. exch pop false exch
  102. } if
  103. %%case '\n':
  104. dup 8#12 eq {
  105. currentpoint 0 exch 1 sub moveto pop
  106. gsave clippath pathbbox pop pop exch pop grestore
  107. currentpoint exch pop 1 sub ge {
  108. 2 index 8#14 write
  109. } if
  110. exch pop false exch
  111. } if
  112. %%case '\f':
  113. dup 8#14 eq {
  114. gsave showpage grestore
  115. 0 0 moveto
  116. exch pop false exch
  117. } if
  118. %%case '\r':
  119. dup 8#15 eq {
  120. currentpoint 0 exch moveto pop
  121. exch pop false exch
  122. } if
  123. %%case EOF:
  124. dup -1 eq {
  125. currentpoint 0 ne exch 0 ne or {
  126. 2 index 8#14 write
  127. } if
  128. exch pop false exch
  129. } if
  130. %%default:
  131. exch {
  132. dup
  133. gsave clippath pathbbox pop 3 1 roll pop pop grestore
  134. ( ) stringwidth pop currentpoint pop add le {
  135. 2 index 8#12 write
  136. } if
  137. ( ) dup 0 4 -1 roll put show
  138. } if
  139. pop % the character
  140. pop % and file object
  141. } def
  142. %
  143. % All the other file output operators call our redefined write operator.
  144. %
  145. /print {
  146. (%stdout) (w) file exch {1 index exch write} forall
  147. pop
  148. } def
  149. /writestring {
  150. {1 index exch write} forall
  151. pop
  152. } def
  153. /writehexstring {
  154. (0123456789ABCDEF) 3 1 roll {
  155. dup
  156. 3 index exch -4 bitshift 16#F and get 2 index exch write
  157. 2 index exch 16#F and get 1 index exch write
  158. } forall
  159. pop pop
  160. } def
  161. %
  162. % Unbind and redefine the remaining file output procedures.
  163. %
  164. /= dup load Unbind def
  165. /== dup load Unbind def
  166. /stack dup load Unbind def
  167. /pstack dup load Unbind def