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

  1. PRODUCT  :  TURBO PASCAL                           NUMBER  :  432
  2. VERSION  :  4.0
  3.      OS  :  PC-DOS 2.X, 3.X
  4.    DATE  :  MAY 3, 1988
  5.  
  6.   TITLE  :  PRINTING GRAPHICS TO A HEWLETT-PACKARD LASERJET
  7.  
  8. { The  following example routines are public domain programs }
  9. { that have  been uploaded to our Forum on CompuServe.  As a }
  10. { courtesy to our users that  do not have  immediate  access }
  11. { to  CompuServe,  Technical   Support   distributes   these }
  12. { routines free of charge.                                   }
  13. {                                                            }
  14. { However, because these routines are public domain programs,}
  15. { not developed  by Borland International,  we are unable to }
  16. { provide any  Technical  Support or  assistance using these }
  17. { routines. If you need assistance  using  these   routines, }
  18. { or   are   experiencing difficulties,  we  recommend  that }
  19. { you log onto CompuServe  and request  assistance  from the }
  20. { Forum members that developed  the routines.                }
  21.  
  22. Unit HpCopy;
  23. { This unit  is designed  to dump  graphics  images produced }
  24. { by  Turbo  Pascal  4.0's  Graph  Unit to a Hewlett-Packard }
  25. { LaserJet printer.                                          }
  26. {                                                            }
  27. { You  MUST set the  Aspect Ratio to 4950  before  drawing a }
  28. { circular object on the screen. The procedure to accomplish }
  29. { this is also contained in this handout.                    }
  30. {                                                            }
  31. { If the Aspect Ratio is NOT set, the image produced by this }
  32. { routine will appear ellipsoid.                             }
  33.  
  34. Interface
  35.  
  36. Uses Crt, Dos, Graph;
  37.  
  38. Var
  39.    LST : Text;      { MUST Redefine because Turbo's Printer }
  40.                     { Unit does not open  LST with the File }
  41.                     { Mode as BINARY.                       }
  42.  
  43. Procedure HPHardCopy;
  44. { Procedure to be  called when  the desired image is on the }
  45. { screen.                                                   }
  46.  
  47. Procedure SetAspectRatio( NewAspect : Word );
  48. { Procedure to be called to set the aspect  ratio such that }
  49. { circular  objects will  appear correctly on the  printout }
  50. { generated  by  HpHardCopy.  NOTE that  the  image on  the }
  51. { screen WILL appear ellipsoid.  This is NORMAL!            }
  52.  
  53. Function GetAspectX : Word;
  54. { This Function will return the  currently set aspect ratio }
  55. { to allow the user  to save  the default ratio,  set it to }
  56. { the ratio  required by HpHardCopy (4950) and then restore }
  57. { it to the default value.                                  }
  58.  
  59. Implementation
  60.  
  61. Var
  62.    Width, Height : Word; { Variables used to store settings }
  63.    Vport : ViewPortType; { Used in the call GetViewSettings }
  64.  
  65. {$F+}
  66. Function LSTNoFunction ( Var F : TextRec ) : Integer;
  67. { This  function performs a NUL  operation  for a  Reset or }
  68. { Rewrite on LST.                                           }
  69.  
  70. Begin
  71.    LSTNoFunction := 0;
  72. End;
  73.  
  74. Function LSTOutPutToPrinter( Var F : TextRec ) : Integer;
  75. { LSTOutPutToPrinter  sends the output to the Printer port }
  76. { number stored in the first byte of the  UserData area of }
  77. { the Text Record.                                         }
  78.  
  79. Var
  80.    Regs : Registers;
  81.    P : Word;
  82.  
  83. Begin
  84.    With F Do
  85.    Begin
  86.       P := 0;
  87.       Regs.AH := 16;
  88.       While( P < BufPos ) and ( ( Regs.AH And 16 ) = 16 ) Do
  89.       Begin
  90.          Regs.AL := Ord( BufPtr^[P] );
  91.          Regs.AH := 0;
  92.          Regs.DX := UserData[1];
  93.          Intr( $17, Regs );
  94.          Inc( P );
  95.       End;
  96.       BufPos := 0;
  97.    End;
  98.    If( ( Regs.AH And 16 ) = 16 ) Then
  99.       LstOutPutToPrinter := 0         { No Error           }
  100.    Else
  101.       If( ( Regs.AH And 32 ) = 32 ) Then
  102.          LSTOutPutToPrinter := 159    { Out of Paper       }
  103.       Else
  104.          LSTOutPutToPrinter := 160;   { Device Write Fault }
  105. End;
  106. {$F-}
  107.  
  108. Procedure AssignLST( Port : Byte );
  109. { AssignLST both sets up the LST text file record as would }
  110. { ASSIGN, and initializes it as would a RESET.             }
  111. {                                                          }
  112. { The parameter  passed to this  procedure  corresponds to }
  113. { DOS's  LPT  number.  It is set  to 1 by default, but can }
  114. { easily be  changed to any  LPT  number by  changing  the }
  115. { parameter  passed  to  this  procedure  in  this  unit's }
  116. { initialization code.                                     }
  117.  
  118. Begin
  119.    With TextRec( Lst ) Do
  120.    Begin
  121.       Handle := $FFF0;
  122.       Mode := fmOutput;
  123.       BufSize := SizeOf( Buffer );
  124.       BufPtr := @@Buffer;
  125.       BufPos := 0;
  126.       OpenFunc := @@LSTNoFunction;
  127.       InOutFunc := @@LSTOutPutToPrinter;
  128.       FlushFunc := @@LSTOutPutToPrinter;
  129.       CloseFunc := @@LSTOutPutToPrinter;
  130.       UserData[1] := Port - 1;
  131.    End;
  132. End;
  133.  
  134. Function GetAspectX : Word;
  135.  
  136. Begin
  137.    GetAspectX := Word( Ptr( Seg( GraphFreeMemPtr ),
  138.                        Ofs( GraphFreeMemPtr ) + 277 ) ^ );
  139. End;
  140.  
  141. Procedure SetAspectRatio{ NewAspect : Word };
  142.  
  143. Begin
  144.    Word( Ptr( Seg( GraphFreeMemPtr ),
  145.          Ofs( GraphFreeMemPtr ) + 277 ) ^ ) := NewAspect;
  146. End;
  147.  
  148. Procedure HPHardCopy;
  149. { Produces hard copy of a graph on Hewlett-Packard Laserjet }
  150. { printer By Joseph J. Hansen 9-15-87                       }
  151. { Modified Extensively for compatibility with Version 4.0's }
  152. { Graph Unit By Gary Stoker                                 }
  153. {                                                           }
  154. { Unlike Graphix Toolbox procedure HardCopy, this procedure }
  155. { has no parameters, though it could easily be rewritten to }
  156. { include  resolution in dots  per inch,  starting  column, }
  157. { inverse image, etc.                                       }
  158. {                                                           }
  159.  
  160. Const DotsPerInch  = '100';
  161.                     { 100 dots per inch  gives  full-screen }
  162.                     { width of 7.2 inches for Hercules card }
  163.                     { graphs, 6.4 inches for IBM color card }
  164.                     { and 6.4  inches  for EGA card.  Other }
  165.                     { allowable values are 75, 150, and 300.}
  166.                     { 75  dots  per  inch  will  produce  a }
  167.                     { larger full-screen graph which may be }
  168.                     { too  large to  fit  on an  8 1/2 inch }
  169.                     { page; 150 and 300  dots per inch will }
  170.                     { produce smaller graphs                }
  171.  
  172.       CursorPosition = '5';
  173.                     { Column position of left side of graph }
  174.       Esc            = #27;
  175.                     { Escape character                      }
  176.  
  177. Var LineHeader     : String[6];
  178.                     { Line  Header used for each  line sent }
  179.                     { to the LaserJet printer.              }
  180.     LineLength     : String[2];
  181.                     { Length  in  bytes of  the  line to be }
  182.                     { sent to the LaserJet.                 }
  183.     Y              : Integer;
  184.                     { Temporary loop Varible.               }
  185.  
  186. Procedure DrawLine ( Y : Integer );
  187. { Draws a single line of dots.  No of Bytes sent to printer }
  188. { is Width + 1.  Argument of the procedure is the row no, Y }
  189.  
  190. Var GraphStr       : String[255]; { String  used for OutPut }
  191.     Base           : Word;        { Starting   position  of }
  192.                                   { output byte.            }
  193.     BitNo,                        { Bit Number worked on    }
  194.     ByteNo,                       { Byte number worked on   }
  195.     DataByte       : Byte;        { Data Byte being built   }
  196.  
  197. Begin
  198.   FillChar( GraphStr, SizeOf( GraphStr ), #0 );
  199.   GraphStr := LineHeader;
  200.   For ByteNo := 0 to Width  Do
  201.   Begin
  202.     DataByte := 0;
  203.     Base := 8 * ByteNo;
  204.     For BitNo := 0 to 7 Do
  205.     Begin
  206.       If GetPixel( BitNo+Base, Y ) > 0
  207.          Then
  208.            Begin
  209.               DataByte := DataByte + 128 Shr BitNo;
  210.            End;
  211.     End;
  212.     GraphStr := GraphStr + Chr (DataByte)
  213.   End;
  214.  
  215.   Write (Lst, GraphStr)
  216.  
  217. End; {Of Drawline}
  218.  
  219. Begin {Main procedure HPCopy}
  220.   FillChar( LineLength, SizeOf( LineLength ), #0 );
  221.   FillChar( LineHeader, SizeOf( LineHeader ), #0 );
  222.  
  223.   GetViewSettings( Vport );
  224.   Width := ( Vport.X2 + 1 ) - Vport.X1;
  225.   Width := ( ( Width - 7 ) Div 8 );
  226.   Height := Vport.Y2 - Vport.Y1;
  227.  
  228.   Write (Lst, Esc + 'E');                 { Reset Printer   }
  229.   Write (Lst, Esc+'*t'+DotsPerInch+'R');  { Set density in  }
  230.                                           { dots per inch   }
  231.   Write (Lst, Esc+'&a'+CursorPosition+'C');{ Move cursor to }
  232.                                           { starting col    }
  233.   Write (Lst, Esc + '*r1A');        { Begin raster graphics }
  234.  
  235.   Str (Width + 1, LineLength);
  236.   LineHeader := Esc + '*b' + LineLength + 'W';
  237.  
  238.  
  239.   For Y := 0 To Height + 1 Do
  240.   Begin
  241.     DrawLine ( Y );
  242.     DrawLine ( Y );
  243.   End;
  244.  
  245.   Write (Lst, Esc + '*rB');           { End Raster graphics }
  246.   Write (Lst, Esc + 'E');             { Reset  printer  and }
  247.                                       { eject page          }
  248. End;
  249.  
  250. Begin
  251.    AssignLST( 1 );        { This is the parameter to change }
  252.                           { if you  want  the output  to be }
  253.                           { directed  to  a  different  LST }
  254.                           { device.                         }
  255. End.
  256.  
  257.