home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / PROG / PASCAL / MISCTI10.ZIP / TI433.ASC < prev    next >
Encoding:
Text File  |  1989-10-17  |  5.7 KB  |  171 lines

  1.  
  2. { The  following example routines are public domain programs }
  3. { that have  been uploaded to our Forum on CompuServe.  As a }
  4. { courtesy to our users that  do not have  immediate  access }
  5. { to  CompuServe,  Technical   Support   distributes   these }
  6. { routines free of charge.                                   }
  7. {                                                            }
  8. { However, because these routines are public domain programs,}
  9. { not developed  by Borland International,  we are unable to }
  10. { provide any  Technical  Support or  assistance using these }
  11. { routines. If you need assistance  using  these   routines, }
  12. { or   are   experiencing difficulties,  we  recommend  that }
  13. { you log onto CompuServe  and request  assistance  from the }
  14. { Forum members that developed  these routines.              }
  15.  
  16. Unit GraphPRN;
  17.  
  18. { This  unit is  designed to send  graphics images  to Epson }
  19. { Compatible  and  late  model  IBM  ProPrinter  Dot  Matrix }
  20. { printers.  It takes the  image from  the currently  active }
  21. { Viewport, determined  by  a call  to  GetViewSettings, and }
  22. { transfers that image to the printer.                       }
  23.  
  24. Interface
  25.  
  26. Uses Dos, Graph;     { Used to get the Image from the Screen }
  27.  
  28. Var
  29.    LST : Text;
  30.  
  31. Procedure HardCopy (Gmode: Integer);
  32. { Procedure HardCopy prints the current ViewPort    }
  33. {   To an IBM or Epson compatible graphics printer. }
  34. {                                                   }
  35. { Valid Gmode numbers are :                         }
  36. {     -4 to -1 for Epson and IBM Graphic Printers   }
  37. {      0 to 7  for Epson Printers                   }
  38.  
  39. Implementation
  40.  
  41. Procedure HardCopy {Gmode: Integer};
  42.  
  43. Const
  44.    Bits : Array [0..7] of Byte = (128,64,32,16,8,4,2,1);
  45.  
  46.  
  47. Var
  48.     X,Y,YOfs        : Integer;   { Screen  location variables }
  49.     BitData,MaxBits : Byte;      { Number of Bits to transfer }
  50.     Vport           : ViewPortType;{Used to get view settings }
  51.     Height, Width   : Word;      { Size of image  to transfer }
  52.     HiBit, LoBit    : Char;      {     Char size of image     }
  53.     LineSpacing,                 { Additional  Info for  dump }
  54.     GraphixPrefix   : String[10];{      "        "   "     "  }
  55.  
  56. Begin
  57.   LineSpacing   := #27+'3'+#24; { 24/216 inch line spacing    }
  58.   Case Gmode Of
  59.        -1: GraphixPrefix := #27+'K'; { Std. Density           }
  60.        -2: GraphixPrefix := #27+'L'; { Double Density         }
  61.        -3: GraphixPrefix := #27+'Y'; { Dbl. Density Dbl. Speed}
  62.        -4: GraphixPrefix := #27+'Z'; { Quad. Density          }
  63.      0..7: GraphixPrefix := #27+'*'+Chr(Gmode);{ 8-Pin Bit Img}
  64.     Else
  65.      Exit;                           { Invalid Mode Selection }
  66.   End;
  67.   GetViewSettings( Vport );          { Get  size  of image to }
  68.   Height := Vport.Y2 - Vport.Y1;     { be printed             }
  69.   Width  := ( Vport.X2 + 1 ) - Vport.X1;
  70.   HiBit := Chr(Hi(Width));           {Translate sizes to char }
  71.   LoBit := Chr(Lo(Width));           { for  output to printer }
  72.   Write( LST, LineSpacing );
  73.   Y := 0;
  74.   While Y < Height Do
  75.   Begin
  76.      Write( LST,GraphixPrefix,LoBit,HiBit );
  77.      For X := 0 to Width-1 Do
  78.      Begin
  79.         BitData := 0;
  80.         If y + 7 <= Height
  81.           Then MaxBits := 7
  82.         Else
  83.           MaxBits := Height - Y;
  84.         For YOfs := 0 to MaxBits do
  85.         Begin
  86.          If GetPixel( X, YOfs+Y ) > 0
  87.            Then BitData := BitData or Bits[YOfs];
  88.         End;
  89.         Write( LST, Chr(BitData) );
  90.      End;
  91.      WriteLn ( LST );
  92.      Inc(Y,8);
  93.   End;
  94. End;
  95.  
  96. {$F+}
  97.  
  98. {      LSTNoFunction performs a NUL operation for a Reset or  }
  99. { Rewrite on LST (Just in case)                               }
  100.  
  101. Function LSTNoFunction( Var F: TextRec ): integer;
  102. Begin
  103.   LSTNoFunction := 0;                    { No error           }
  104. end;
  105.  
  106. {      LSTOutputToPrinter sends the output to the Printer     }
  107. { port number stored in the first byte of the UserData area   }
  108. { of the Text Record.                                         }
  109.  
  110. Function LSTOutputToPrinter( Var F: TextRec ): integer;
  111. var
  112.   Regs: Registers;
  113.   P : word;
  114. begin
  115.   With F do
  116.   Begin
  117.     P := 0;
  118.     Regs.AH := 16;
  119.     While (P < BufPos) and ((regs.ah and 16) = 16) do
  120.     Begin
  121.       Regs.AL := Ord(BufPtr^[P]);
  122.       Regs.AH := 0;
  123.       Regs.DX := UserData[1];
  124.       Intr($17,Regs);
  125.       Inc(P);
  126.     end;
  127.     BufPos := 0;
  128.   End;
  129.   if (Regs.AH and 16) = 16 then
  130.     LSTOutputToPrinter := 0              { No error           }
  131.    else
  132.      if (Regs.AH and 32 ) = 32 then
  133.        LSTOutputToPrinter := 159         { Out of Paper       }
  134.    else
  135.        LSTOutputToPrinter := 160;        { Device write Fault }
  136. End;
  137.  
  138. {$F-}
  139.  
  140. {      AssignLST both sets up the LST text file record as     }
  141. { would ASSIGN, and initializes it as would a RESET.  It also }
  142. { stores the Port number in the first Byte of the UserData    }
  143. { area.                                                       }
  144.  
  145. Procedure AssignLST( Port:Byte );
  146. Begin
  147.   With TextRec(LST) do
  148.     begin
  149.       Handle      := $FFF0;
  150.       Mode        := fmOutput;
  151.       BufSize     := SizeOf(Buffer);
  152.       BufPtr      := @@Buffer;
  153.       BufPos      := 0;
  154.       OpenFunc    := @@LSTNoFunction;
  155.       InOutFunc   := @@LSTOutputToPrinter;
  156.       FlushFunc   := @@LSTOutputToPrinter;
  157.       CloseFunc   := @@LSTOutputToPrinter;
  158.       UserData[1] := Port - 1;  { We subtract one because }
  159.   end;                          { Dos Counts from zero.   }
  160. end;
  161.  
  162.  
  163.  
  164. Begin
  165.    AssignLST( 1 );           { Sets output printer to LPT1 by }
  166.                              { default.  Change this value to }
  167.                              { a 2 to select LPT2.            }
  168. End.                         { Note: BIOS only handles LPT1   }
  169.                              { and LPT2.                      }
  170.  
  171.