home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / TP_ADV.ZIP / LIST1007.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1989-07-31  |  6.3 KB  |  190 lines

  1. Unit HpCopy;
  2.  
  3. { This unit  is designed  to dump  graphics  images produced }
  4. { by  Turbo  Pascal's  Graph  Unit to a Hewlett-Packard      }
  5. { LaserJet printer.  You must be sure to set the aspect      }
  6. { ratio with the command SetAspectRatio( 3000,5000 ); before }
  7. { drawing a circular object.                                 }
  8. { If the Aspect Ratio is NOT set, the image produced by this }
  9. { routine will appear ellipsoid.                             }
  10.  
  11. Interface
  12.  
  13. Uses
  14.   Crt, Dos, Graph;
  15.  
  16. Var
  17.    LST : Text;      { MUST Redefine because Turbo's Printer }
  18.                     { Unit does not open  LST with the File }
  19.                     { Mode as BINARY.                       }
  20.  
  21. Procedure HPHardCopy;
  22.  
  23. Implementation
  24.  
  25. Var
  26.    Width, Height : Word; { Variables used to store settings }
  27.    Vport : ViewPortType; { Used in the call GetViewSettings }
  28.  
  29. {$F+}
  30. Function LSTNoFunction ( Var F : TextRec ) : Integer;
  31. { This  function performs a NUL  operation  for a  Reset or }
  32. { Rewrite on LST.                                           }
  33.  
  34. Begin
  35.    LSTNoFunction := 0;
  36. End;
  37.  
  38. Function LSTOutPutToPrinter( Var F : TextRec ) : Integer;
  39. { LSTOutPutToPrinter  sends the output to the Printer port }
  40. { number stored in the first byte or the  UserData area of }
  41. { the Text Record.                                         }
  42.  
  43. Var
  44.    Regs : Registers;
  45.    P : Word;
  46.  
  47. Begin
  48.    With F Do
  49.    Begin
  50.       P := 0;
  51.       Regs.AH := 16;
  52.       While( P < BufPos ) and ( ( Regs.AH And 16 ) = 16 ) Do
  53.       Begin
  54.          Regs.AL := Ord( BufPtr^[P] );
  55.          Regs.AH := 0;
  56.          Regs.DX := UserData[1];
  57.          Intr( $17, Regs );
  58.          Inc( P );
  59.       End;
  60.       BufPos := 0;
  61.    End;
  62.    If( ( Regs.AH And 16 ) = 16 ) Then
  63.       LstOutPutToPrinter := 0         { No Error           }
  64.    Else
  65.       If( ( Regs.AH And 32 ) = 32 ) Then
  66.          LSTOutPutToPrinter := 159    { Out of Paper       }
  67.       Else
  68.          LSTOutPutToPrinter := 160;   { Device Write Fault }
  69. End;
  70. {$F-}
  71.  
  72. Procedure AssignLST( Port : Byte );
  73. { AssignLST both sets up the LST text file record as would }
  74. { ASSIGN, and initializes it as would a RESET.             }
  75. { The parameter  passed to this  procedure  corresponds to }
  76. { DOS's LPT  number.  It is set to 1 by  default, but  can }
  77. { easily  be  changed to any  LPT number  by  changing the }
  78. { parameter  passed  to  this  procedure  in  this  unit's }
  79. { initialization code.                                     }
  80.  
  81. Begin
  82.    With TextRec( Lst ) Do
  83.    Begin
  84.       Handle := $FFF0;
  85.       Mode := fmOutput;
  86.       BufSize := SizeOf( Buffer );
  87.       BufPtr := @Buffer;
  88.       BufPos := 0;
  89.       OpenFunc := @LSTNoFunction;
  90.       InOutFunc := @LSTOutPutToPrinter;
  91.       FlushFunc := @LSTOutPutToPrinter;
  92.       CloseFunc := @LSTOutPutToPrinter;
  93.       UserData[1] := Port - 1;
  94.    End;
  95. End;
  96.  
  97. Procedure HPHardCopy;
  98. { Unlike Graphix Toolbox procedure HardCopy, this procedure }
  99. { has no parameters, though it could easily be rewritten to }
  100. { include  resolution in dots  per inch,  starting  column, }
  101. { inverse image, etc.                                       }
  102. {                                                           }
  103.  
  104. Const
  105.   DotsPerInch  = '100';
  106.                     { 100 dots per inch  gives  full-screen }
  107.                     { width of 7.2 inches for Hercules card }
  108.                     { graphs, 6.4 inches for IBM color card }
  109.                     { and 6.4  inches  for EGA card.  Other }
  110.                     { allowable values are 75, 150, and 300.}
  111.                     { 75  dots  per  inch  will  produce  a }
  112.                     { larger full-screen graph which may be }
  113.                     { too  large to  fit  on an  8 1/2 inch }
  114.                     { page; 150 and 300  dots per inch will }
  115.                     { produce smaller graphs                }
  116.  
  117.   CursorPosition = '5';
  118.                     { Column position of left side of graph }
  119.   Esc            = #27;
  120.                     { Escape character                      }
  121.  
  122. Var
  123.   LineHeader     : String[6];
  124.                     { Line  Header used for each  line sent }
  125.                     { to the LaserJet printer.              }
  126.   LineLength     : String[2];
  127.                     { Length  in  bytes of  the  line to be }
  128.                     { sent to the LaserJet.                 }
  129.   Y              : Integer;
  130.                     { Temporary loop Varible.               }
  131.  
  132. Procedure DrawLine ( Y : Integer );
  133. { Draws a single line of dots.  No of Bytes sent to printer }
  134. { is Width + 1.  Argument of the procedure is the row no, Y }
  135.  
  136. Var
  137.   GraphStr       : String[255]; { String  used for OutPut }
  138.   Base           : Word;        { Starting   position  of }
  139.                                 { output byte.            }
  140.   BitNo,                        { Bit Number worked on    }
  141.   ByteNo,                       { Byte number worked on   }
  142.   DataByte       : Byte;        { Data Byte being built   }
  143.  
  144. Begin
  145.   FillChar( GraphStr, SizeOf( GraphStr ), #0 );
  146.   GraphStr := LineHeader;
  147.   For ByteNo := 0 to Width  Do
  148.   Begin
  149.     DataByte := 0;
  150.     Base := 8 * ByteNo;
  151.     For BitNo := 0 to 7 Do
  152.     Begin
  153.       If GetPixel( BitNo+Base, Y ) > 0 Then
  154.         DataByte := DataByte + 128 Shr BitNo;
  155.     End;
  156.     GraphStr := GraphStr + Chr (DataByte)
  157.   End;
  158.   Write (Lst, GraphStr)
  159. End; {Of Drawline}
  160.  
  161. Begin {Main procedure HPCopy}
  162.   FillChar( LineLength, SizeOf( LineLength ), #0 );
  163.   FillChar( LineHeader, SizeOf( LineHeader ), #0 );
  164.   GetViewSettings( Vport );
  165.   Width := ( Vport.X2 + 1 ) - Vport.X1;
  166.   Width := ( ( Width - 7 ) Div 8 );
  167.   Height := Vport.Y2 - Vport.Y1;
  168.   Write (Lst, Esc + 'E');                 { Reset Printer   }
  169.   Write (Lst, Esc+'*t'+DotsPerInch+'R');  { Set density in  }
  170.                                           { dots per inch   }
  171.   Write (Lst, Esc+'&a'+CursorPosition+'C');{ Move cursor to }
  172.                                           { starting col    }
  173.   Write (Lst, Esc + '*r1A');        { Begin raster graphics }
  174.  
  175.   Str (Width + 1, LineLength);
  176.   LineHeader := Esc + '*b' + LineLength + 'W';
  177.   For Y := 0 To Height + 1 Do
  178.   Begin
  179.     DrawLine ( Y );
  180.     DrawLine ( Y );
  181.   End;
  182.   Write (Lst, Esc + '*rB');           { End Raster graphics }
  183.   Write (Lst, Esc + 'E');             { Reset  printer  and }
  184.                                       { eject page          }
  185. End;
  186.  
  187. Begin
  188.    AssignLST( 2 );
  189. End.
  190.