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