home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 3 / 3189 < prev    next >
Internet Message Format  |  1991-04-13  |  8KB

  1. From: rustyh@wam.umd.edu (Michael Katzmann)
  2. Newsgroups: comp.lang.postscript,alt.sources
  3. Subject: Postscript to make printer "dumb"
  4. Message-ID: <1991Apr13.152721.18571@wam.umd.edu>
  5. Date: 13 Apr 91 15:27:21 GMT
  6.  
  7.  
  8. Since I received a few e-mail requests for this, I don't think it would 
  9. be too much of a waste of bandwidth to post it.  As the description says,
  10. it is a postscript programme to make a postscript printer behave like a
  11. dumb printer.
  12.  
  13. Simply send it to the postscript device before the text to be printed.
  14.  
  15. Bugs:  Doesn't handle tabs well on proportionally spaced fonts.
  16.  
  17. Please send any enhancements or bug fixes to me ath the address below.
  18.  
  19.  
  20. --
  21. Michael Katzmann  (VK2BEA/G4NYV/NV3Z)   Please email to this address |
  22. Broadcast Sports Technology                                          |
  23. 2135 Espey Ct. #4                                                   \|/
  24. Crofton MD 21114-2442    (301) 721-5151      ...uunet!opel!vk2bea!michael
  25.  
  26. %    Postscript to print ascii text.
  27. %    [ Turn your Postscript printer into a "dumb" HP like laser printer ]
  28. %
  29. %    Written by Perry Brown 
  30. %       Trivial mods by   Michael Katzmann 
  31. %       Bug reports to:  (michael@vk2bea!opel!uunet.uu.na)
  32. %
  33. % ****  You are free to re-distribute this providing the authors name is
  34. %                                acknowedged.
  35. %    Instructions:
  36. %        Send to Postscript printer as a header 
  37. %
  38. %    These escape sequences anywhere in the text will modify printing:
  39. %
  40. %    (Escape sequences are in the form of \\X(Y) or \\XY)
  41. %
  42. %       f[RIiBbUu]    Change font to Reset, Italic, Bold or Underline
  43. %                  (lower case removes enhancement)
  44. %        i.e.      \\fBu  would make the current font Bold and remove
  45. %                            underlining.
  46. %
  47. %       p(size)      Change font point size.
  48. %        i.e.      \\p(10) would print in 10 point characters
  49. %
  50. %       t[THCS]      Change typeface to Times, Helvetica, Courier or Symbol
  51. %        i.e.      \\tH    would print in Helvetica
  52. %
  53. %       g(grey)      Change shade ( 0 black to 100 white)
  54. %        i.e.      \\g(50) would print in mid grey
  55. %
  56. %       P          Portrait mode orientation.  e.g. \\P
  57. %
  58. %       L          Landscape mode orientation. e.g. \\L
  59. %
  60. %       m(margin)      Set margin (in numbers of space widths)
  61. %        i.e.      \\m(10)  Set left margin 10 characters in.
  62. %
  63. %       
  64. /Escapes [
  65.   6 dict
  66.     dup 8#015 {        % \r
  67.       CarrageReturn
  68.     } put
  69.     dup 8#012 {        % \n
  70.       CarrageReturn
  71.       LineFeed
  72.     } put
  73.     dup 8#014 {        % \f
  74.       FormFeed
  75.     } put
  76.     dup 8#010 {        % \b
  77.       BackSpace
  78.     } put
  79.     dup 8#134 {        % \
  80.       EscEnable {
  81.         /Escaped 1 def
  82.       } {
  83.         8#134 WriteChar
  84.       } ifelse
  85.     } put
  86.     dup 8#011 {        % \t
  87.       Tab
  88.     } put
  89.  
  90.   1 dict
  91.     dup 8#134 {
  92.       /Escaped 2 def
  93.     } put
  94.  
  95.   8 dict
  96.     dup 8#146 {        % f
  97.       /Escaped 0 def
  98.       GetChar PickFont
  99.     } put
  100.     dup 8#160 {        % p
  101.       /Escaped 0 def
  102.       GetNum {
  103.         PickPoint
  104.       } if
  105.     } put
  106.     dup 8#164 {        % t
  107.       /Escaped 0 def
  108.       GetChar PickFamily
  109.     } put
  110.     dup 8#147 {        % g
  111.       /Escaped 0 def
  112.       GetNum {
  113.         100 div setgray
  114.       } if
  115.     } put
  116.     dup 8#120 {        % P
  117.       /Escaped 0 def
  118.       /Portrait true def
  119.       FormFeed
  120.     } put
  121.     dup 8#114 {        % L
  122.       /Escaped 0 def
  123.       /Portrait false def
  124.       FormFeed
  125.     } put
  126.     dup 8#041 {        % !
  127.       /Escaped 0 def
  128.       /EscEnable false def
  129.     } put
  130.     dup 8#155 {        % m
  131.       /Escaped 0 def
  132.       GetNum {
  133.         /Margin exch def
  134.       } {
  135.         /Margin 0 def
  136.       } ifelse
  137.       CarrageReturn
  138.     } put
  139. ] def
  140.  
  141. /Main {
  142.   /Stdin (%stdin) (r) file def
  143.   /NewPage true def
  144.   /Column 0 def
  145.   /CurrentFont 0 def
  146.   /PointSize 10 def
  147.   /FontFamily 8#103 def        % 'C'
  148.   /Portrait true def
  149.   /Escaped 0 def
  150.   /EscEnable true def
  151.   /Margin 10 def
  152.   /NeedMargin true def
  153.   KludgeWindow
  154.   SetRotation
  155.   SetFont
  156.   /SquareOne save def
  157.   {
  158.     GetChar PutChar
  159.   } loop
  160. } def
  161.  
  162. /KludgeWindow {
  163.   /Ty 768 def
  164.   /Tx 594 def
  165.   /By 24 def
  166.   /Bx 18 def
  167. } def
  168.  
  169. /SetRotation {
  170.   initmatrix
  171.   Portrait {
  172.     /TopMargin Ty def
  173.     /BottomMargin By def
  174.     /LeftMargin Bx def
  175.     /RightMargin Tx def
  176.   } {
  177.     90 rotate
  178.     /TopMargin Bx neg def
  179.     /BottomMargin Tx neg def
  180.     /LeftMargin By def
  181.     /RightMargin Ty def
  182.   } ifelse
  183. } def
  184.  
  185. /GetChar {
  186.   Stdin read not {
  187.     Finish
  188.   } if
  189. } def
  190.  
  191. /GetNum {
  192.   GetChar 8#050 eq {        % '('
  193.     0 {
  194.       GetChar dup dup 8#060 ge exch 8#071 le and {    % 0 .. 9
  195.         8#060 sub exch 10 mul add
  196.       } {
  197.         exit
  198.       } ifelse
  199.     } loop
  200.     8#051 eq {        % ')'
  201.       true
  202.     } {
  203.       pop false
  204.     } ifelse
  205.   } {
  206.     false
  207.   } ifelse
  208. } def
  209.  
  210. /FontMap 7 dict
  211.   dup 8#122 {        % 'R'
  212.     /CurrentFont 0 def
  213.   } put
  214.   dup 8#111 {        % 'I'
  215.     /CurrentFont CurrentFont 2#1 or def
  216.   } put
  217.   dup 8#151 {        % 'i'
  218.     /CurrentFont CurrentFont 2#1 not and def
  219.   } put
  220.   dup 8#102 {        % 'B'
  221.     /CurrentFont CurrentFont 2#10 or def
  222.   } put
  223.   dup 8#142 {        % 'b'
  224.     /CurrentFont CurrentFont 2#10 not and def
  225.   } put
  226.   dup 8#125 {        % 'U'
  227.     /CurrentFont CurrentFont 2#100 or def
  228.   } put
  229.   dup 8#165 {        % 'u'
  230.     /CurrentFont CurrentFont 2#100 not and def
  231.   } put
  232. def
  233.  
  234. /PutChar {
  235.   Escapes Escaped get exch 2 copy known {
  236.     get exec
  237.   } {
  238.     exch pop
  239.     Escaped 0 ne {
  240.       FlushEsc
  241.       /Escaped 0 def
  242.       PutChar
  243.     } {
  244.       WriteChar
  245.     } ifelse
  246.   } ifelse
  247. } def
  248.  
  249. /FlushEsc {
  250.   Escaped {
  251.     8#134 WriteChar    % '\'
  252.   } repeat
  253. } def
  254.  
  255. /PickFont {
  256.   dup FontMap exch 2 copy known {
  257.     get exec
  258.     SetFont
  259.   } {
  260.     pop pop
  261.   } ifelse
  262. } def
  263.  
  264. /PickPoint {
  265.   dup 5 gt 1 index 50 lt and {
  266.     /PointSize exch def
  267.     SetFont
  268.   } if
  269. } def
  270.  
  271. /FamilyMap 4 dict
  272.   dup 8#124 [        % 'T'
  273.     (Times-Roman)
  274.     (Times-Italic)
  275.     (Times-Bold)
  276.     (Times-BoldItalic)
  277.   ] put
  278.   dup 8#110 [        % 'H'
  279.     (Helvetica)
  280.     (Helvetica-Oblique)
  281.     (Helvetica-Bold)
  282.     (Helvetica-BoldOblique)
  283.   ] put
  284.   dup 8#103 [        % 'C'
  285.     (Courier)
  286.     (Courier-Oblique)
  287.     (Courier-Bold)
  288.     (Courier-BoldOblique)
  289.   ] put
  290.   dup 8#123 [        % 'S'
  291.     (Symbol)
  292.     dup
  293.     dup
  294.     dup
  295.   ] put
  296. def
  297.  
  298. /PickFamily {
  299.   dup FamilyMap exch known {
  300.     /FontFamily exch def
  301.     SetFont
  302.   } {
  303.     pop
  304.   } ifelse
  305. } def
  306.  
  307. /SetFont {
  308.   FamilyMap FontFamily get CurrentFont 2#011 and get findfont
  309.   PointSize scalefont
  310.   setfont
  311.   MakeCurrent
  312. } def
  313.  
  314. /MakeCurrent {
  315.   NewPage {
  316.     LeftMargin TopMargin
  317.       gsave
  318.       newpath 0 0 moveto (E) false charpath flattenpath pathbbox
  319.         exch pop exch pop exch pop 2 add sub
  320.       grestore
  321.       moveto
  322.   } if
  323. } def
  324.  
  325. /CarrageReturn {
  326.   /Column 0 def
  327.   currentpoint exch pop LeftMargin exch moveto
  328.   /NeedMargin true def
  329. } def
  330.  
  331. /WriteChar {
  332.   NeedMargin {
  333.     SetMargin
  334.   } if
  335.   ( \273) dup 0 3 index put
  336.     stringwidth pop currentpoint pop add
  337.       RightMargin ge {
  338.         (\273) show
  339.         CarrageReturn
  340.         LineFeed
  341.         SetMargin
  342.       } if
  343.   ( ) dup 0 4 -1 roll put dup show
  344.     UnderLine
  345.   /NewPage false def
  346.   /Column Column 1 add def
  347. } def
  348.  
  349. /Finish {
  350.   FlushEsc
  351.   FormFeed
  352.   stop
  353. } def
  354.  
  355. /SetMargin {
  356.   /NeedMargin false def
  357.   Margin {
  358.     ( ) show
  359.   } repeat
  360. } def
  361.  
  362. /BackSpace {
  363.   /Column Column 1 sub dup 0 lt {
  364.     pop 0
  365.   } if
  366.   def
  367.   currentpoint exch ( ) stringwidth pop sub dup
  368.     LeftMargin lt {
  369.       /Column 0 def
  370.       pop LeftMargin
  371.     } if
  372.     exch moveto
  373. } def
  374.  
  375. /LineFeed {
  376.   currentpoint PointSize sub dup PointSize 0.2 mul sub
  377.     BottomMargin lt {
  378.       pop pop
  379.       FormFeed
  380.     } {
  381.       moveto
  382.     } ifelse
  383. } def
  384.  
  385. /FormFeed {
  386.   NewPage not {
  387.     showpage
  388.   } if
  389.   currentgray EscEnable Margin CurrentFont PointSize FontFamily Escaped Portrait
  390.   SquareOne restore
  391.     [ /Portrait /Escaped /FontFamily /PointSize /CurrentFont /Margin /EscEnable ] {
  392.       exch def
  393.     } forall
  394.     /SquareOne save def
  395.     setgray
  396.     SetRotation
  397.     SetFont
  398. } def
  399.  
  400. /Tab {
  401.   {
  402.     8#040 WriteChar    % ' '
  403.     Column 8 mod 0 eq {
  404.       exit
  405.     } if
  406.   } loop
  407. } def
  408.  
  409. /UnderLine {
  410.   CurrentFont 2#100 and 0 ne {
  411.     gsave
  412.     currentpoint
  413.     newpath
  414.     moveto
  415.     0 -0.15 PointSize mul rmoveto
  416.     stringwidth pop neg 0 rlineto
  417.     0.05 PointSize mul setlinewidth
  418.     0 setlinecap
  419.     stroke
  420.     grestore
  421.   } {
  422.     pop
  423.   } ifelse
  424. } def
  425.  
  426. Main
  427.