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