author | Stefan Vogel <sv@exept.de> |
Wed, 16 Apr 2008 20:36:13 +0200 | |
changeset 2431 | 582646db0959 |
parent 2346 | e5a41923ac0c |
child 2450 | 330fb7f2b5ab |
permissions | -rw-r--r-- |
2302 | 1 |
" |
2 |
COPYRIGHT (c) 2006 by eXept Software AG |
|
3 |
All Rights Reserved |
|
4 |
||
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
2238 | 12 |
"{ Package: 'stx:libview2' }" |
13 |
||
14 |
PrinterStream subclass:#WinPrinterStream |
|
15 |
instanceVariableNames:'printerContext printJobName printFileName currentLineBuffer |
|
2248 | 16 |
currentPageBuffer cX cY colNr lineNr pageCount heightOfFont |
17 |
jobStarted pageStarted' |
|
2238 | 18 |
classVariableNames:'PrinterInfo' |
19 |
poolDictionaries:'' |
|
20 |
category:'Interface-Printing' |
|
21 |
! |
|
22 |
||
2302 | 23 |
!WinPrinterStream class methodsFor:'documentation'! |
24 |
||
25 |
copyright |
|
26 |
" |
|
27 |
COPYRIGHT (c) 2006 by eXept Software AG |
|
28 |
All Rights Reserved |
|
29 |
||
30 |
This software is furnished under a license and may be used |
|
31 |
only in accordance with the terms of that license and with the |
|
32 |
inclusion of the above copyright notice. This software may not |
|
33 |
be provided or otherwise made available to, or used by, any |
|
34 |
other person. No title to or ownership of the software is |
|
35 |
hereby transferred. |
|
36 |
" |
|
37 |
! ! |
|
2238 | 38 |
|
39 |
!WinPrinterStream class methodsFor:'instance creation'! |
|
40 |
||
41 |
new |
|
2248 | 42 |
| printerContext | |
2238 | 43 |
|
44 |
PrinterInfo := PrintingDialog getPrinterInfo. |
|
2335
e2b7bbad49f6
care for escape in printer dialog
Claus Gittinger <cg@exept.de>
parents:
2302
diff
changeset
|
45 |
PrinterInfo isNil ifTrue:[ |
e2b7bbad49f6
care for escape in printer dialog
Claus Gittinger <cg@exept.de>
parents:
2302
diff
changeset
|
46 |
"/ cancelled |
e2b7bbad49f6
care for escape in printer dialog
Claus Gittinger <cg@exept.de>
parents:
2302
diff
changeset
|
47 |
AbortSignal raiseRequest. |
e2b7bbad49f6
care for escape in printer dialog
Claus Gittinger <cg@exept.de>
parents:
2302
diff
changeset
|
48 |
^nil |
e2b7bbad49f6
care for escape in printer dialog
Claus Gittinger <cg@exept.de>
parents:
2302
diff
changeset
|
49 |
]. |
2238 | 50 |
|
2302 | 51 |
printerContext := WinPrinterContext fromPrinterInfo: PrinterInfo. |
2238 | 52 |
|
53 |
^ self basicNew printerContext:printerContext. |
|
54 |
||
2302 | 55 |
"Modified: / 12-10-2006 / 10:07:36 / fm" |
56 |
"Modified: / 16-04-2007 / 12:58:13 / cg" |
|
2238 | 57 |
! |
58 |
||
59 |
newForFile:aFileNameOrNil |
|
60 |
"return a new stream for printing into aFileName" |
|
61 |
||
62 |
|printer| |
|
63 |
||
64 |
printer := self basicNew initialize. |
|
65 |
printer setPrintFileName:aFileNameOrNil. |
|
66 |
printer startPrint. |
|
67 |
^ printer |
|
68 |
||
2302 | 69 |
"Modified: / 12-10-2006 / 14:35:09 / fm" |
70 |
"Modified: / 16-04-2007 / 12:58:18 / cg" |
|
2238 | 71 |
! |
72 |
||
73 |
newNative |
|
74 |
self halt |
|
75 |
||
76 |
"Created: / 10-10-2006 / 18:41:39 / cg" |
|
77 |
! ! |
|
78 |
||
79 |
!WinPrinterStream class methodsFor:'queries'! |
|
80 |
||
81 |
isDrivenByCommand |
|
82 |
"return true if this printer is driven via an OS-command |
|
83 |
(as opposed to writing a file or using a native printing API)" |
|
84 |
||
85 |
^ false |
|
86 |
||
87 |
"Created: / 10-10-2006 / 18:22:13 / cg" |
|
88 |
! |
|
89 |
||
90 |
printerTypeName |
|
91 |
"return a descriptive name" |
|
92 |
||
2346 | 93 |
^ 'Windows Printer' |
2238 | 94 |
|
95 |
"Created: / 10-10-2006 / 18:26:22 / cg" |
|
2346 | 96 |
"Modified: / 08-11-2007 / 12:13:59 / cg" |
2238 | 97 |
! |
98 |
||
99 |
supportsPrintingToFile |
|
100 |
^ false |
|
101 |
||
102 |
"Created: / 10-10-2006 / 18:27:16 / cg" |
|
103 |
! ! |
|
104 |
||
105 |
!WinPrinterStream methodsFor:'accessing'! |
|
106 |
||
2248 | 107 |
fontWidthForTabComputing |
2302 | 108 |
^ 120 |
2248 | 109 |
|
2302 | 110 |
"Created: / 12-10-2006 / 11:59:33 / fm" |
111 |
"Modified: / 16-04-2007 / 13:00:05 / cg" |
|
2248 | 112 |
! |
113 |
||
114 |
hasJobStarted |
|
115 |
||
2302 | 116 |
^jobStarted = true |
2248 | 117 |
|
2302 | 118 |
"Created: / 12-10-2006 / 14:38:00 / fm" |
119 |
"Modified: / 16-04-2007 / 13:00:26 / cg" |
|
2248 | 120 |
! |
121 |
||
122 |
hasPageStarted |
|
123 |
||
2302 | 124 |
^pageStarted = true |
2248 | 125 |
|
2302 | 126 |
"Created: / 12-10-2006 / 14:41:39 / fm" |
127 |
"Modified: / 16-04-2007 / 13:00:32 / cg" |
|
2248 | 128 |
! |
129 |
||
130 |
heightOfFont |
|
131 |
||
132 |
heightOfFont isNil ifTrue:[heightOfFont := printerContext getCharHeight]. |
|
133 |
^heightOfFont |
|
134 |
||
2302 | 135 |
"Created: / 12-10-2006 / 12:00:57 / fm" |
136 |
"Modified: / 16-04-2007 / 13:00:35 / cg" |
|
2248 | 137 |
! |
138 |
||
139 |
linesPerPage |
|
140 |
||
141 |
^printerContext linesPerPageFor: nil |
|
142 |
||
2302 | 143 |
"Created: / 12-10-2006 / 11:57:53 / fm" |
144 |
"Modified: / 16-04-2007 / 13:00:38 / cg" |
|
2248 | 145 |
! |
146 |
||
2238 | 147 |
printerContext:something |
148 |
printerContext := something. |
|
149 |
! ! |
|
150 |
||
151 |
!WinPrinterStream methodsFor:'open/close'! |
|
152 |
||
2248 | 153 |
endPage |
154 |
printerContext endPage. |
|
155 |
pageStarted := false. |
|
156 |
||
2302 | 157 |
"Created: / 12-10-2006 / 14:42:18 / fm" |
158 |
"Modified: / 16-04-2007 / 12:58:33 / cg" |
|
2248 | 159 |
! |
160 |
||
2238 | 161 |
endPrint |
162 |
printerContext endPrintJob. |
|
2248 | 163 |
jobStarted := false. |
2238 | 164 |
|
165 |
"Created: / 10-10-2006 / 18:50:05 / cg" |
|
2302 | 166 |
"Modified: / 12-10-2006 / 14:41:11 / fm" |
167 |
"Modified: / 16-04-2007 / 12:58:36 / cg" |
|
2248 | 168 |
! |
169 |
||
170 |
formFeed |
|
2302 | 171 |
printerContext formFeed. |
172 |
self resetPage |
|
2248 | 173 |
|
2302 | 174 |
"Created: / 12-10-2006 / 10:41:40 / fm" |
175 |
"Modified: / 12-10-2006 / 14:40:53 / fm" |
|
176 |
"Modified: / 16-04-2007 / 13:00:21 / cg" |
|
2248 | 177 |
! |
178 |
||
179 |
startPage |
|
180 |
printerContext startPage. |
|
181 |
pageStarted := true. |
|
182 |
self resetPage |
|
183 |
||
2302 | 184 |
"Created: / 12-10-2006 / 14:39:27 / fm" |
185 |
"Modified: / 16-04-2007 / 13:00:58 / cg" |
|
2238 | 186 |
! |
187 |
||
188 |
startPrint |
|
189 |
printerContext isNil ifTrue:[ |
|
190 |
PrinterInfo isNil ifTrue:[ |
|
191 |
PrinterInfo := PrintingDialog getPrinterInfo. |
|
192 |
PrinterInfo isNil ifTrue:[^self]. |
|
193 |
]. |
|
2302 | 194 |
printerContext := WinPrinterContext fromPrinterInfo: PrinterInfo. |
2238 | 195 |
]. |
2248 | 196 |
printerContext foreground:(Color black) background:(Color white). |
197 |
self resetPage. |
|
2238 | 198 |
printerContext startPrintJob: (printJobName ? 'ST/X PrintJob') fileName:printFileName. |
2248 | 199 |
pageCount := 1. |
200 |
jobStarted := true. |
|
201 |
pageStarted := true. |
|
2238 | 202 |
|
203 |
"Created: / 10-10-2006 / 18:49:55 / cg" |
|
2302 | 204 |
"Modified: / 12-10-2006 / 15:25:29 / fm" |
205 |
"Modified: / 16-04-2007 / 13:01:01 / cg" |
|
2238 | 206 |
! ! |
207 |
||
208 |
!WinPrinterStream methodsFor:'private'! |
|
209 |
||
2248 | 210 |
resetPage |
211 |
||
2302 | 212 |
cX := cY := colNr := lineNr := 0. |
2248 | 213 |
|
2302 | 214 |
"Created: / 12-10-2006 / 14:40:23 / fm" |
215 |
"Modified: / 16-04-2007 / 13:00:52 / cg" |
|
2248 | 216 |
! |
217 |
||
2238 | 218 |
setPrintFileName:something |
219 |
printFileName := something. |
|
220 |
||
221 |
"Created: / 10-10-2006 / 19:07:16 / cg" |
|
222 |
! ! |
|
223 |
||
224 |
!WinPrinterStream methodsFor:'writing'! |
|
225 |
||
226 |
cr |
|
227 |
||
2248 | 228 |
colNr := 0. |
229 |
lineNr := lineNr + 1. |
|
230 |
cX := 0 "+ self leftX". |
|
231 |
cY := cY + self heightOfFont. |
|
232 |
lineNr >= self linesPerPage ifTrue:[ |
|
233 |
pageCount := pageCount + 1. |
|
234 |
self endPage |
|
2238 | 235 |
]. |
236 |
||
2302 | 237 |
"Modified: / 12-10-2006 / 14:42:57 / fm" |
238 |
"Modified: / 16-04-2007 / 12:58:30 / cg" |
|
2238 | 239 |
! |
240 |
||
241 |
nextPut:aCharacter |
|
2248 | 242 |
|
243 |
self hasJobStarted ifFalse:[self startPrint]. |
|
244 |
self hasPageStarted ifFalse:[self startPage]. |
|
245 |
||
246 |
aCharacter asciiValue < 16r20 ifTrue:[ |
|
247 |
aCharacter == Character cr ifTrue:[ |
|
248 |
self cr. |
|
249 |
]. |
|
250 |
aCharacter == Character tab ifTrue:[ |
|
251 |
colNr := ((colNr + 8) // 8) * 8. |
|
252 |
cX := "self leftX +" (colNr * self fontWidthForTabComputing). |
|
253 |
^ self |
|
254 |
]. |
|
255 |
aCharacter == Character newPage ifTrue:[ |
|
256 |
self endPage. |
|
257 |
]. |
|
258 |
^ self. |
|
2238 | 259 |
]. |
260 |
||
2248 | 261 |
printerContext displayString:aCharacter asString x:cX y:cY. |
262 |
colNr := colNr + 1. |
|
263 |
cX := cX + (printerContext stringWidthOf: aCharacter asString). |
|
264 |
||
2302 | 265 |
"Modified: / 12-10-2006 / 15:06:14 / fm" |
266 |
"Modified: / 16-04-2007 / 13:00:44 / cg" |
|
2238 | 267 |
! |
268 |
||
269 |
nextPutAll:aString |
|
2248 | 270 |
|
271 |
self hasJobStarted ifFalse:[self startPrint]. |
|
272 |
self hasPageStarted ifFalse:[self startPage]. |
|
273 |
||
274 |
(aString contains:[:char | char asciiValue < 16r20]) ifTrue:[ |
|
275 |
super nextPutAll:aString. |
|
276 |
^ self. |
|
2238 | 277 |
]. |
278 |
||
2248 | 279 |
#TODO. "/ use aString, when problem with Text-extent is fixed... |
280 |
printerContext displayString: aString string x:cX y:cY. |
|
281 |
colNr := colNr + aString size. |
|
282 |
cX := cX + (printerContext stringWidthOf: aString string). |
|
283 |
||
2302 | 284 |
"Modified: / 12-10-2006 / 15:21:02 / fm" |
285 |
"Modified: / 16-04-2007 / 13:00:46 / cg" |
|
2238 | 286 |
! ! |
287 |
||
288 |
!WinPrinterStream class methodsFor:'documentation'! |
|
289 |
||
290 |
version |
|
2346 | 291 |
^ '$Header: /cvs/stx/stx/libview2/WinPrinterStream.st,v 1.5 2007-11-08 11:14:28 cg Exp $' |
2238 | 292 |
! ! |