author | Claus Gittinger <cg@exept.de> |
Wed, 04 Jul 2007 16:37:15 +0200 | |
changeset 2335 | e2b7bbad49f6 |
parent 2302 | a36ea047f05b |
child 2346 | e5a41923ac0c |
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 |
||
93 |
^ 'windows printer' |
|
94 |
||
95 |
"Created: / 10-10-2006 / 18:26:22 / cg" |
|
96 |
! |
|
97 |
||
98 |
supportsPrintingToFile |
|
99 |
^ false |
|
100 |
||
101 |
"Created: / 10-10-2006 / 18:27:16 / cg" |
|
102 |
! ! |
|
103 |
||
104 |
!WinPrinterStream methodsFor:'accessing'! |
|
105 |
||
2248 | 106 |
fontWidthForTabComputing |
2302 | 107 |
^ 120 |
2248 | 108 |
|
2302 | 109 |
"Created: / 12-10-2006 / 11:59:33 / fm" |
110 |
"Modified: / 16-04-2007 / 13:00:05 / cg" |
|
2248 | 111 |
! |
112 |
||
113 |
hasJobStarted |
|
114 |
||
2302 | 115 |
^jobStarted = true |
2248 | 116 |
|
2302 | 117 |
"Created: / 12-10-2006 / 14:38:00 / fm" |
118 |
"Modified: / 16-04-2007 / 13:00:26 / cg" |
|
2248 | 119 |
! |
120 |
||
121 |
hasPageStarted |
|
122 |
||
2302 | 123 |
^pageStarted = true |
2248 | 124 |
|
2302 | 125 |
"Created: / 12-10-2006 / 14:41:39 / fm" |
126 |
"Modified: / 16-04-2007 / 13:00:32 / cg" |
|
2248 | 127 |
! |
128 |
||
129 |
heightOfFont |
|
130 |
||
131 |
heightOfFont isNil ifTrue:[heightOfFont := printerContext getCharHeight]. |
|
132 |
^heightOfFont |
|
133 |
||
2302 | 134 |
"Created: / 12-10-2006 / 12:00:57 / fm" |
135 |
"Modified: / 16-04-2007 / 13:00:35 / cg" |
|
2248 | 136 |
! |
137 |
||
138 |
linesPerPage |
|
139 |
||
140 |
^printerContext linesPerPageFor: nil |
|
141 |
||
2302 | 142 |
"Created: / 12-10-2006 / 11:57:53 / fm" |
143 |
"Modified: / 16-04-2007 / 13:00:38 / cg" |
|
2248 | 144 |
! |
145 |
||
2238 | 146 |
printerContext:something |
147 |
printerContext := something. |
|
148 |
! ! |
|
149 |
||
150 |
!WinPrinterStream methodsFor:'open/close'! |
|
151 |
||
2248 | 152 |
endPage |
153 |
printerContext endPage. |
|
154 |
pageStarted := false. |
|
155 |
||
2302 | 156 |
"Created: / 12-10-2006 / 14:42:18 / fm" |
157 |
"Modified: / 16-04-2007 / 12:58:33 / cg" |
|
2248 | 158 |
! |
159 |
||
2238 | 160 |
endPrint |
161 |
printerContext endPrintJob. |
|
2248 | 162 |
jobStarted := false. |
2238 | 163 |
|
164 |
"Created: / 10-10-2006 / 18:50:05 / cg" |
|
2302 | 165 |
"Modified: / 12-10-2006 / 14:41:11 / fm" |
166 |
"Modified: / 16-04-2007 / 12:58:36 / cg" |
|
2248 | 167 |
! |
168 |
||
169 |
formFeed |
|
2302 | 170 |
printerContext formFeed. |
171 |
self resetPage |
|
2248 | 172 |
|
2302 | 173 |
"Created: / 12-10-2006 / 10:41:40 / fm" |
174 |
"Modified: / 12-10-2006 / 14:40:53 / fm" |
|
175 |
"Modified: / 16-04-2007 / 13:00:21 / cg" |
|
2248 | 176 |
! |
177 |
||
178 |
startPage |
|
179 |
printerContext startPage. |
|
180 |
pageStarted := true. |
|
181 |
self resetPage |
|
182 |
||
2302 | 183 |
"Created: / 12-10-2006 / 14:39:27 / fm" |
184 |
"Modified: / 16-04-2007 / 13:00:58 / cg" |
|
2238 | 185 |
! |
186 |
||
187 |
startPrint |
|
188 |
printerContext isNil ifTrue:[ |
|
189 |
PrinterInfo isNil ifTrue:[ |
|
190 |
PrinterInfo := PrintingDialog getPrinterInfo. |
|
191 |
PrinterInfo isNil ifTrue:[^self]. |
|
192 |
]. |
|
2302 | 193 |
printerContext := WinPrinterContext fromPrinterInfo: PrinterInfo. |
2238 | 194 |
]. |
2248 | 195 |
printerContext foreground:(Color black) background:(Color white). |
196 |
self resetPage. |
|
2238 | 197 |
printerContext startPrintJob: (printJobName ? 'ST/X PrintJob') fileName:printFileName. |
2248 | 198 |
pageCount := 1. |
199 |
jobStarted := true. |
|
200 |
pageStarted := true. |
|
2238 | 201 |
|
202 |
"Created: / 10-10-2006 / 18:49:55 / cg" |
|
2302 | 203 |
"Modified: / 12-10-2006 / 15:25:29 / fm" |
204 |
"Modified: / 16-04-2007 / 13:01:01 / cg" |
|
2238 | 205 |
! ! |
206 |
||
207 |
!WinPrinterStream methodsFor:'private'! |
|
208 |
||
2248 | 209 |
resetPage |
210 |
||
2302 | 211 |
cX := cY := colNr := lineNr := 0. |
2248 | 212 |
|
2302 | 213 |
"Created: / 12-10-2006 / 14:40:23 / fm" |
214 |
"Modified: / 16-04-2007 / 13:00:52 / cg" |
|
2248 | 215 |
! |
216 |
||
2238 | 217 |
setPrintFileName:something |
218 |
printFileName := something. |
|
219 |
||
220 |
"Created: / 10-10-2006 / 19:07:16 / cg" |
|
221 |
! ! |
|
222 |
||
223 |
!WinPrinterStream methodsFor:'writing'! |
|
224 |
||
225 |
cr |
|
226 |
||
2248 | 227 |
colNr := 0. |
228 |
lineNr := lineNr + 1. |
|
229 |
cX := 0 "+ self leftX". |
|
230 |
cY := cY + self heightOfFont. |
|
231 |
lineNr >= self linesPerPage ifTrue:[ |
|
232 |
pageCount := pageCount + 1. |
|
233 |
self endPage |
|
2238 | 234 |
]. |
235 |
||
2302 | 236 |
"Modified: / 12-10-2006 / 14:42:57 / fm" |
237 |
"Modified: / 16-04-2007 / 12:58:30 / cg" |
|
2238 | 238 |
! |
239 |
||
240 |
nextPut:aCharacter |
|
2248 | 241 |
|
242 |
self hasJobStarted ifFalse:[self startPrint]. |
|
243 |
self hasPageStarted ifFalse:[self startPage]. |
|
244 |
||
245 |
aCharacter asciiValue < 16r20 ifTrue:[ |
|
246 |
aCharacter == Character cr ifTrue:[ |
|
247 |
self cr. |
|
248 |
]. |
|
249 |
aCharacter == Character tab ifTrue:[ |
|
250 |
colNr := ((colNr + 8) // 8) * 8. |
|
251 |
cX := "self leftX +" (colNr * self fontWidthForTabComputing). |
|
252 |
^ self |
|
253 |
]. |
|
254 |
aCharacter == Character newPage ifTrue:[ |
|
255 |
self endPage. |
|
256 |
]. |
|
257 |
^ self. |
|
2238 | 258 |
]. |
259 |
||
2248 | 260 |
printerContext displayString:aCharacter asString x:cX y:cY. |
261 |
colNr := colNr + 1. |
|
262 |
cX := cX + (printerContext stringWidthOf: aCharacter asString). |
|
263 |
||
2302 | 264 |
"Modified: / 12-10-2006 / 15:06:14 / fm" |
265 |
"Modified: / 16-04-2007 / 13:00:44 / cg" |
|
2238 | 266 |
! |
267 |
||
268 |
nextPutAll:aString |
|
2248 | 269 |
|
270 |
self hasJobStarted ifFalse:[self startPrint]. |
|
271 |
self hasPageStarted ifFalse:[self startPage]. |
|
272 |
||
273 |
(aString contains:[:char | char asciiValue < 16r20]) ifTrue:[ |
|
274 |
super nextPutAll:aString. |
|
275 |
^ self. |
|
2238 | 276 |
]. |
277 |
||
2248 | 278 |
#TODO. "/ use aString, when problem with Text-extent is fixed... |
279 |
printerContext displayString: aString string x:cX y:cY. |
|
280 |
colNr := colNr + aString size. |
|
281 |
cX := cX + (printerContext stringWidthOf: aString string). |
|
282 |
||
2302 | 283 |
"Modified: / 12-10-2006 / 15:21:02 / fm" |
284 |
"Modified: / 16-04-2007 / 13:00:46 / cg" |
|
2238 | 285 |
! ! |
286 |
||
287 |
!WinPrinterStream class methodsFor:'documentation'! |
|
288 |
||
289 |
version |
|
2335
e2b7bbad49f6
care for escape in printer dialog
Claus Gittinger <cg@exept.de>
parents:
2302
diff
changeset
|
290 |
^ '$Header: /cvs/stx/stx/libview2/WinPrinterStream.st,v 1.4 2007-07-04 14:37:15 cg Exp $' |
2238 | 291 |
! ! |