home *** CD-ROM | disk | FTP | other *** search
- Unit GPrint;
- {---------------------------------------------------------------}
- { This unit is designed to send graphics images to Epson }
- { Compatible and late model IBM ProPrinter Dot Matrix printers. }
- { It takes the image from the currently active view port, }
- { determined by a call to GetViewSettings, and transfers that }
- { image to the printer. }
- {---------------------------------------------------------------}
-
- Interface
-
- Uses Dos, Graph; { Link in the necessary standard units }
-
- Var
- LST : Text; { New printer file variable }
-
- Procedure HardCopy (Gmode: Integer);
- { Procedure HardCopy prints the current ViewPort to an IBM or }
- { Epson compatible graphics printer. }
- { }
- { Valid Gmode numbers are : }
- { -4 to -1 for Epson and IBM Graphic Printers }
- { 0 to 7 for Epson Printers }
-
- Implementation
-
- Procedure HardCopy {Gmode: Integer};
-
- Const
- Bits : Array [0..7] of Byte = (128,64,32,16,8,4,2,1);
- { Values of each bit within byte variable }
-
- Var
- X,Y,YOfs : Integer; { Screen location variables }
- BitData,MaxBits : Byte; { Number of Bits to transfer }
- Vport : ViewPortType;{ Used to get view settings }
- Height, Width : Word; { Size of image to transfer }
- HiBit, LoBit : Char; { Char size of image }
- LineSpacing, { Additional Info for dump }
- GraphixPrefix : String[10]; { " " " " }
- BKColor : Byte; { Value of current bk color }
-
- Begin
- LineSpacing := #27+'3'+#24; { 24/216 inch line spacing }
- Case Gmode Of
- -1: GraphixPrefix := #27+'K'; { Standard Density }
- -2: GraphixPrefix := #27+'L'; { Double Density }
- -3: GraphixPrefix := #27+'Y'; { Dbl. Density Dbl. Speed }
- -4: GraphixPrefix := #27+'Z'; { Quad. Density }
- 0..7: GraphixPrefix := #27+'*'+Chr( Gmode);{ 8-Pin Bit Img }
- Else
- Exit; { Invalid Mode Selection }
- End;
- BKColor := GetBKColor;
- GetViewSettings( Vport ); { Get size of image to be }
- Height := Vport.Y2 - Vport.Y1; { printed }
- Width := ( Vport.X2 + 1 ) - Vport.X1;
- HiBit := Chr( Hi( Width ) ); { Translate sizes to char }
- LoBit := Chr( Lo( Width ) ); { for output to printer }
- Write( LST, LineSpacing );
- Y := 0; { First Y coordinate }
- While Y < Height Do { Do not go beyond viewport }
- Begin
- Write( LST,GraphixPrefix,LoBit,HiBit );
- { Tell printer graphics info }
- For X := 0 to Width-1 Do { Go across screen lt to rt. }
- Begin
- BitData := 0; { Initialize to all off (0) }
- If y + 7 <= Height Then { Make sure there are 8 }
- MaxBits := 7 { line of info and set it }
- Else { accordingly }
- MaxBits := Height - Y;
- For YOfs := 0 to MaxBits do { Go top to bottom on line }
- If( GetPixel( X, YOfs+Y ) <> BKColor ) Then
- BitData := BitData or Bits[YOfs];
- { If pixel on, add to output }
- Write( LST, Chr( BitData ) );{ Byte is created, output it }
- End;
- WriteLn ( LST );
- Inc( Y,8 ); { Inc by 8 as each line is 8 }
- { actual scan line in height }
- End;
- Writeln ( LST, #12 + 327 + 64 );
- End;
- {---------------------------------------------------------------}
- { What follows is the code for the Text File Device Driver for }
- { the LST file variable defined above. This is necessary as }
- { Turbo opens the LST device defined in the printer unit in a }
- { "Cooked" mode. }
- {---------------------------------------------------------------}
-
- {$F+}
-
- Function LSTNoFunction( Var F: TextRec ): Integer;
- { This function performs a NUL operation on LST in case a Reset }
- { or a Rewrite is called. }
- Begin
- LSTNoFunction := 0;
- End;
-
- Function LSTOutputToPrinter( Var F: TextRec ): Integer;
- { This function sends the output to the printer port number }
- { stored in the first byte of the UserData area of the Text }
- { Record. }
- Var
- Regs: Registers;
- P : word;
- Begin
- With F do
- Begin
- P := 0;
- Regs.AH := 16;
- While( ( P < BufPos ) And ( ( Regs.AH and 16 ) = 16 ) ) Do
- Begin
- Regs.AL := Ord( BufPtr^[P] );
- Regs.AH := 0;
- Regs.DX := UserData[1];
- Intr( $17,Regs );
- Inc( P );
- end;
- BufPos := 0;
- End;
- If( Regs.AH and 16 ) = 16 Then
- LSTOutputToPrinter := 0 { No error }
- Else
- If( Regs.AH and 32 ) = 32 Then
- LSTOutputToPrinter := 159 { Out of Paper }
- Else
- LSTOutputToPrinter := 160; { Device write Fault }
- End;
-
- {$F-}
-
- Procedure AssignLST( Port:Byte );
- { This procedure sets up the LST text file record as would the }
- { Assign procedure, and initializes it as would a call to the }
- { Reset procedure. It then stores the LPT port number in the }
- { first byte of the UserData Area of the TextRec type. }
-
- Begin
- With TextRec( LST ) do
- Begin
- Handle := $FFF0;
- Mode := fmOutput;
- BufSize := SizeOf( Buffer );
- BufPtr := @Buffer;
- BufPos := 0;
- OpenFunc := @LSTNoFunction;
- InOutFunc := @LSTOutputToPrinter;
- FlushFunc := @LSTOutputToPrinter;
- CloseFunc := @LSTOutputToPrinter;
- UserData[1] := Port - 1; { Sub 1 as DOS counts from zero }
- End;
- End;
-
- Begin
- AssignLST( 1 ); { Sets output printer to LPT1 by }
- { default. Change this value to }
- { select other LPT ports. }
- End.
-