2299
|
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 |
"
|
|
12 |
"{ Package: 'stx:libview2' }"
|
|
13 |
|
|
14 |
GraphicsMedium subclass:#WinPrinterContext
|
|
15 |
instanceVariableNames:'name abort jobid printerInfo textAlign'
|
|
16 |
classVariableNames:''
|
|
17 |
poolDictionaries:''
|
|
18 |
category:'Interface-Printing'
|
|
19 |
!
|
|
20 |
|
|
21 |
!WinPrinterContext class methodsFor:'documentation'!
|
|
22 |
|
|
23 |
copyright
|
|
24 |
"
|
|
25 |
COPYRIGHT (c) 2006 by eXept Software AG
|
|
26 |
All Rights Reserved
|
|
27 |
|
|
28 |
This software is furnished under a license and may be used
|
|
29 |
only in accordance with the terms of that license and with the
|
|
30 |
inclusion of the above copyright notice. This software may not
|
|
31 |
be provided or otherwise made available to, or used by, any
|
|
32 |
other person. No title to or ownership of the software is
|
|
33 |
hereby transferred.
|
|
34 |
"
|
|
35 |
!
|
|
36 |
|
|
37 |
documentation
|
|
38 |
"
|
|
39 |
I am the mediator between the smalltalk printing protocol
|
|
40 |
(which is the same as the graphics drawing protocol) and the
|
|
41 |
windows printer.
|
|
42 |
When youopena printer, you will typically talk to me, and I will
|
|
43 |
forward the graphics commands to my printer.
|
|
44 |
|
|
45 |
[author:]
|
|
46 |
Felix Madrid (fm@exept.de)
|
|
47 |
"
|
|
48 |
! !
|
|
49 |
|
|
50 |
!WinPrinterContext class methodsFor:'instance creation'!
|
|
51 |
|
|
52 |
fromPrinterInfo: aPrinterInfo
|
|
53 |
| aPrinter hDC|
|
|
54 |
|
|
55 |
hDC := aPrinterInfo createDC.
|
|
56 |
hDC = 0 ifTrue: [ ^self error: 'Error while opening printer.' ].
|
|
57 |
|
|
58 |
aPrinter := self new.
|
|
59 |
aPrinter printerInfo: aPrinterInfo.
|
|
60 |
aPrinter setDevice:(WinPrinter on: aPrinterInfo) id:nil gcId:hDC.
|
|
61 |
aPrinter initExtent.
|
|
62 |
^aPrinter
|
|
63 |
|
|
64 |
"Created: / 03-08-2006 / 12:53:52 / fm"
|
|
65 |
"Modified: / 04-08-2006 / 12:55:01 / fm"
|
|
66 |
"Modified: / 16-04-2007 / 12:36:26 / cg"
|
|
67 |
! !
|
|
68 |
|
|
69 |
!WinPrinterContext class methodsFor:'accessing'!
|
|
70 |
|
|
71 |
default
|
|
72 |
"Answer the default Printer, or nil if none."
|
|
73 |
|
|
74 |
|defaultName|
|
|
75 |
|
|
76 |
^ (defaultName := self defaultPrinterName) isNil
|
|
77 |
ifTrue:[ nil ]
|
|
78 |
ifFalse:[ self named:defaultName ]
|
|
79 |
|
|
80 |
"
|
|
81 |
self default
|
|
82 |
"
|
|
83 |
|
|
84 |
"Created: / 27-07-2006 / 17:51:43 / fm"
|
|
85 |
"Modified: / 02-08-2006 / 17:27:09 / fm"
|
|
86 |
"Modified: / 10-10-2006 / 17:30:31 / cg"
|
|
87 |
!
|
|
88 |
|
|
89 |
defaultMargins
|
|
90 |
"Private - answer aPoint containing the default horizontal and vertical
|
|
91 |
margins for a page (units in inches)."
|
|
92 |
|
|
93 |
^ 0.5 @ 0.75
|
|
94 |
|
|
95 |
"Created: / 01-08-2006 / 16:09:31 / fm"
|
|
96 |
"Modified: / 10-10-2006 / 17:30:49 / cg"
|
|
97 |
!
|
|
98 |
|
|
99 |
defaultPrinterName
|
|
100 |
"Answer the name of the default printer, or nil if none."
|
|
101 |
|
|
102 |
|printerInfo printerName|
|
|
103 |
|
|
104 |
printerInfo := OperatingSystem getDefaultPrinterName.
|
|
105 |
printerName := (printerInfo copyFrom:1 to:(printerInfo indexOf:$,) - 1) trimBlanks.
|
|
106 |
^ printerName size == 0 ifTrue:[ nil ] ifFalse:[ printerName ]
|
|
107 |
|
|
108 |
"
|
|
109 |
PrinterContext defaultPrinterName
|
|
110 |
"
|
|
111 |
|
|
112 |
"Modified: / 02-08-2006 / 17:26:09 / fm"
|
|
113 |
"Modified: / 10-10-2006 / 17:32:45 / cg"
|
|
114 |
!
|
|
115 |
|
|
116 |
getPrinterInformation:printerNameString
|
|
117 |
" Answer the printer information for the printer named printerNameString. If no name is specified,
|
|
118 |
answer the information for the default printer."
|
|
119 |
|
|
120 |
|h|
|
|
121 |
|
|
122 |
h := OperatingSystem openPrinter:printerNameString.
|
|
123 |
^ OperatingSystem
|
|
124 |
getDocumentProperties:nil
|
|
125 |
hPrinter:h
|
|
126 |
pDeviceName:printerNameString.
|
|
127 |
|
|
128 |
"Created: / 27-07-2006 / 10:22:32 / fm"
|
|
129 |
"Modified: / 01-08-2006 / 16:01:44 / fm"
|
|
130 |
"Modified: / 10-10-2006 / 18:57:45 / cg"
|
|
131 |
!
|
|
132 |
|
|
133 |
named: aName
|
|
134 |
"Answer a new instance of Printer which represents
|
|
135 |
the printer named aName as specified in the host
|
|
136 |
Control Panel."
|
|
137 |
|
|
138 |
aName isNil ifTrue: [ ^self default ].
|
|
139 |
^self new printerInfoWithName: aName
|
|
140 |
|
|
141 |
"Created: / 27-07-2006 / 17:51:27 / fm"
|
|
142 |
"Modified: / 02-08-2006 / 17:26:29 / fm"
|
|
143 |
"Modified: / 10-10-2006 / 17:33:29 / cg"
|
|
144 |
!
|
|
145 |
|
|
146 |
printerNames
|
|
147 |
"Answer a collection of all known printer names."
|
|
148 |
|
|
149 |
^ OperatingSystem getPrintersNames
|
|
150 |
|
|
151 |
"Created: / 27-07-2006 / 17:54:45 / fm"
|
|
152 |
"Modified: / 10-10-2006 / 18:57:51 / cg"
|
|
153 |
! !
|
|
154 |
|
|
155 |
!WinPrinterContext class methodsFor:'testing & examples'!
|
|
156 |
|
|
157 |
print: aString font: aFont title: aTitle
|
|
158 |
"Open a print dialog to allow printing of the given string
|
|
159 |
using the given title & font."
|
|
160 |
|
|
161 |
self print: aString font: aFont title: aTitle wordWrap: false
|
|
162 |
|
|
163 |
"
|
|
164 |
PrinterContext print: 'Holaaaa!! (from: PrinterContext>>print:aString font:aFont title:aTitle)' font: nil title: 'Printing Test'
|
|
165 |
PrinterContext print: self printingTestString font: nil title: 'Printing Test String'
|
|
166 |
PrinterContext print: self printingTestString font: (Font family:'Arial' face:'medium' size:8) title: 'Printing Test String'
|
|
167 |
"
|
|
168 |
|
|
169 |
"Created: / 27-07-2006 / 17:52:33 / fm"
|
|
170 |
"Modified: / 03-08-2006 / 18:52:31 / fm"
|
|
171 |
"Modified: / 10-10-2006 / 17:37:49 / cg"
|
|
172 |
!
|
|
173 |
|
|
174 |
print: aString font: aFont title: aTitle wordWrap: wordWrap
|
|
175 |
"Open a print dialog to allow printing of the given string
|
|
176 |
using the given title & font."
|
|
177 |
|
|
178 |
| printerInfo printer |
|
|
179 |
|
|
180 |
printerInfo := PrintingDialog getPrinterInfo.
|
|
181 |
printerInfo isNil ifTrue:[^self].
|
|
182 |
|
|
183 |
printer := self fromPrinterInfo: printerInfo.
|
|
184 |
[
|
|
185 |
printer
|
|
186 |
print: aString
|
|
187 |
font: aFont
|
|
188 |
title: aTitle
|
|
189 |
wordWrap: wordWrap
|
|
190 |
marginsRect: nil
|
|
191 |
] forkAt: 3
|
|
192 |
|
|
193 |
"
|
|
194 |
PrinterContext print: 'Holaaaa!! (from: PrinterContext>>print:aString font:aFont title:aTitle)' font: nil title: 'Printing Test' wordWrap: true
|
|
195 |
PrinterContext print: (PrinterContext class sourceCodeAt:#'print:font:title:wordWrap:') font:nil title:'Printing Test String' wordWrap:true
|
|
196 |
PrinterContext print: (PrinterContext class sourceCodeAt:#'print:font:title:wordWrap:') font: (Font family:'Arial' face:'medium' size:8) title: 'Printing Test String' wordWrap: true
|
|
197 |
"
|
|
198 |
|
|
199 |
"Created: / 03-08-2006 / 18:51:53 / fm"
|
|
200 |
"Modified: / 10-10-2006 / 17:42:06 / cg"
|
|
201 |
!
|
|
202 |
|
|
203 |
printCircles: arrayOfPointsAndRadius
|
|
204 |
"Opens a print dialog and prints the given circles"
|
|
205 |
|
|
206 |
| printerInfo printer |
|
|
207 |
|
|
208 |
printerInfo := PrintingDialog getPrinterInfo.
|
|
209 |
printerInfo isNil ifTrue:[^self].
|
|
210 |
|
|
211 |
printer := self fromPrinterInfo: printerInfo.
|
|
212 |
[
|
|
213 |
printer startPrintJob: 'Circles'.
|
|
214 |
arrayOfPointsAndRadius
|
|
215 |
do:[:pointAndRadius |
|
|
216 |
printer displayCircle:(pointAndRadius at:1)
|
|
217 |
radius:(pointAndRadius at:2).
|
|
218 |
].
|
|
219 |
printer endPrintJob.
|
|
220 |
] forkAt: 3
|
|
221 |
|
|
222 |
"
|
|
223 |
PrinterContext printCircles:
|
|
224 |
(Array with: (Array with: 800@800 with: 600)
|
|
225 |
with: (Array with: 1500@1500 with: 1000)
|
|
226 |
with: (Array with: 4000@2500 with: 2000))
|
|
227 |
"
|
|
228 |
|
|
229 |
"Created: / 07-08-2006 / 11:46:52 / fm"
|
|
230 |
"Modified: / 10-10-2006 / 17:36:23 / cg"
|
|
231 |
!
|
|
232 |
|
|
233 |
printCirclesIn: rectangles
|
|
234 |
"Opens a print dialog and prints the given circles"
|
|
235 |
|
|
236 |
| printerInfo printer |
|
|
237 |
|
|
238 |
printerInfo := PrintingDialog getPrinterInfo.
|
|
239 |
printerInfo isNil ifTrue:[^self].
|
|
240 |
|
|
241 |
printer := self fromPrinterInfo: printerInfo.
|
|
242 |
[
|
|
243 |
printer startPrintJob: 'Circles In Rectangles'.
|
|
244 |
rectangles
|
|
245 |
do:[:rectangle |
|
|
246 |
printer displayCircleIn: rectangle.
|
|
247 |
].
|
|
248 |
printer endPrintJob.
|
|
249 |
] forkAt: 3
|
|
250 |
|
|
251 |
"
|
|
252 |
PrinterContext printCirclesIn:
|
|
253 |
(Array with: (Rectangle left:20 top:20 width:400 height:600)
|
|
254 |
with: (Rectangle left:40 top:40 width:600 height:400)
|
|
255 |
)
|
|
256 |
"
|
|
257 |
|
|
258 |
"Created: / 07-08-2006 / 11:48:46 / fm"
|
|
259 |
"Modified: / 10-10-2006 / 17:38:28 / cg"
|
|
260 |
!
|
|
261 |
|
|
262 |
printLines: pairOfPointsArray
|
|
263 |
"Opens a print dialog and prints the given lines"
|
|
264 |
|
|
265 |
| printerInfo printer |
|
|
266 |
|
|
267 |
printerInfo := PrintingDialog getPrinterInfo.
|
|
268 |
printerInfo isNil ifTrue:[^self].
|
|
269 |
|
|
270 |
printer := self fromPrinterInfo: printerInfo.
|
|
271 |
[
|
|
272 |
printer startPrintJob: 'Lines'.
|
|
273 |
printer foreground:Color black background:Color white.
|
|
274 |
pairOfPointsArray
|
|
275 |
do:[:pairOfPoints |
|
|
276 |
printer displayLineFrom: (pairOfPoints at:1) to: (pairOfPoints at:2).
|
|
277 |
].
|
|
278 |
printer endPrintJob.
|
|
279 |
] forkAt: 3
|
|
280 |
|
|
281 |
"
|
|
282 |
PrinterContext printLines:
|
|
283 |
(Array with: (Array with:10@10 with:100@10)
|
|
284 |
with: (Array with:10@10 with:35@200))
|
|
285 |
"
|
|
286 |
|
|
287 |
"Created: / 07-08-2006 / 12:09:48 / fm"
|
|
288 |
"Modified: / 07-08-2006 / 14:11:17 / fm"
|
|
289 |
"Modified: / 10-10-2006 / 17:38:44 / cg"
|
|
290 |
!
|
|
291 |
|
|
292 |
printPolygons: polygons
|
|
293 |
"Opens a print dialog and prints the given polygons"
|
|
294 |
|
|
295 |
| printerInfo printer |
|
|
296 |
|
|
297 |
printerInfo := PrintingDialog getPrinterInfo.
|
|
298 |
printerInfo isNil ifTrue:[^self].
|
|
299 |
|
|
300 |
printer := self fromPrinterInfo: printerInfo.
|
|
301 |
[
|
|
302 |
printer startPrintJob: 'Polygons'.
|
|
303 |
printer foreground:Color black background:Color white.
|
|
304 |
polygons
|
|
305 |
do:[:aPolygon |
|
|
306 |
aPolygon displayStrokedOn: printer.
|
|
307 |
].
|
|
308 |
printer endPrintJob.
|
|
309 |
] forkAt: 3
|
|
310 |
|
|
311 |
"
|
|
312 |
PrinterContext printPolygons:
|
|
313 |
(Array with: (Polygon vertices:(
|
|
314 |
Array
|
|
315 |
with:10@10
|
|
316 |
with:60@10
|
|
317 |
with:35@60)))
|
|
318 |
"
|
|
319 |
|
|
320 |
"Created: / 07-08-2006 / 12:09:48 / fm"
|
|
321 |
"Modified: / 07-08-2006 / 14:11:17 / fm"
|
|
322 |
"Modified: / 10-10-2006 / 17:39:23 / cg"
|
|
323 |
!
|
|
324 |
|
|
325 |
printRectangles: rectangles
|
|
326 |
"Opens a print dialog and prints the given rectangles"
|
|
327 |
|
|
328 |
| printerInfo printer |
|
|
329 |
|
|
330 |
printerInfo := PrintingDialog getPrinterInfo.
|
|
331 |
printerInfo isNil ifTrue:[^self].
|
|
332 |
|
|
333 |
printer := self fromPrinterInfo: printerInfo.
|
|
334 |
[
|
|
335 |
printer startPrintJob: 'Rectangles'.
|
|
336 |
rectangles
|
|
337 |
do:[:rectangle |
|
|
338 |
printer displayRectangleX: rectangle origin x
|
|
339 |
y: rectangle origin y
|
|
340 |
width: rectangle width
|
|
341 |
height: rectangle height.
|
|
342 |
].
|
|
343 |
printer endPrintJob.
|
|
344 |
] forkAt: 3
|
|
345 |
|
|
346 |
"
|
|
347 |
PrinterContext printRectangles:
|
|
348 |
(Array with: (Rectangle left:20 top:20 width:400 height:600)
|
|
349 |
with: (Rectangle left:40 top:40 width:600 height:400)
|
|
350 |
)
|
|
351 |
"
|
|
352 |
|
|
353 |
"Created: / 07-08-2006 / 11:40:48 / fm"
|
|
354 |
"Modified: / 10-10-2006 / 17:39:51 / cg"
|
|
355 |
!
|
|
356 |
|
|
357 |
printStrings: stringAndPositionsArray
|
|
358 |
"Opens a print dialog and prints the given strings"
|
|
359 |
|
|
360 |
| printerInfo printer |
|
|
361 |
|
|
362 |
printerInfo := PrintingDialog getPrinterInfo.
|
|
363 |
printerInfo isNil ifTrue:[^self].
|
|
364 |
|
|
365 |
printer := self fromPrinterInfo: printerInfo.
|
|
366 |
[
|
|
367 |
printer startPrintJob: 'Strings with Position'.
|
|
368 |
printer foreground:Color black background:Color white.
|
|
369 |
stringAndPositionsArray
|
|
370 |
do:[:pairOfPointsAndPosition |
|
|
371 |
printer displayString:(pairOfPointsAndPosition at: 1)
|
|
372 |
x:(pairOfPointsAndPosition at: 2) x
|
|
373 |
y:(pairOfPointsAndPosition at: 2) y
|
|
374 |
].
|
|
375 |
printer endPrintJob.
|
|
376 |
] forkAt: 3
|
|
377 |
|
|
378 |
"
|
|
379 |
PrinterContext printStrings:
|
|
380 |
(Array with: (Array with:'Testing printing with standart method' with:10@10)
|
|
381 |
with: (Array with:'Another test string to print' with:80@200))
|
|
382 |
"
|
|
383 |
|
|
384 |
"Created: / 07-08-2006 / 12:09:48 / fm"
|
|
385 |
"Modified: / 07-08-2006 / 14:11:17 / fm"
|
|
386 |
"Modified: / 10-10-2006 / 17:40:07 / cg"
|
|
387 |
! !
|
|
388 |
|
|
389 |
!WinPrinterContext methodsFor:'abort handling'!
|
|
390 |
|
|
391 |
abortPrintJob
|
|
392 |
"Abort the current print job."
|
|
393 |
|
|
394 |
abort := true.
|
|
395 |
jobid := nil.
|
|
396 |
|
|
397 |
"Modified: / 02-08-2006 / 15:40:26 / fm"
|
|
398 |
"Modified: / 10-10-2006 / 18:13:45 / cg"
|
|
399 |
!
|
|
400 |
|
|
401 |
aborted
|
|
402 |
"Answer whether the user aborted from PrintAbortDialog."
|
|
403 |
|
|
404 |
^ abort
|
|
405 |
|
|
406 |
"Created: / 27-07-2006 / 10:20:10 / fm"
|
|
407 |
"Modified: / 10-10-2006 / 18:13:50 / cg"
|
|
408 |
! !
|
|
409 |
|
|
410 |
!WinPrinterContext methodsFor:'accessing'!
|
|
411 |
|
|
412 |
container
|
|
413 |
|
|
414 |
^self
|
|
415 |
!
|
|
416 |
|
|
417 |
getCharHeight
|
|
418 |
"Private - answer the height of the font selected in the receiver's
|
|
419 |
device context."
|
|
420 |
|
|
421 |
|textMetrics answer|
|
|
422 |
|
|
423 |
|
|
424 |
textMetrics := Win32OperatingSystem::TextMetricsStructure new.
|
|
425 |
"/ (OperatingSystem getTextMetrics:gcId lpMetrics:textMetrics) ifFalse:[ ^ self error ].
|
|
426 |
"/ Transcript showCR: 'CHAR HEIGHT PRIM ******* ', ' ', (textMetrics tmHeight + textMetrics tmExternalLeading) printString.
|
|
427 |
"/ Transcript showCR: 'CHAR HEIGHT DEVICE ***** ', ' ', (self font heightOf:'PQWEXCZ' on:self device) printString.
|
|
428 |
answer := (self font heightOf:'PQWEXCZ' on:self device).
|
|
429 |
"/ answer := textMetrics tmHeight + textMetrics tmExternalLeading.
|
|
430 |
^answer
|
|
431 |
|
|
432 |
"Created: / 02-08-2006 / 17:47:20 / fm"
|
|
433 |
"Modified: / 03-08-2006 / 10:09:01 / fm"
|
|
434 |
"Modified: / 10-10-2006 / 18:15:17 / cg"
|
|
435 |
!
|
|
436 |
|
|
437 |
horizontalPixelsPerMeter
|
|
438 |
"Answer horizontal pixels per meter
|
|
439 |
on the screen."
|
|
440 |
^self pixelsPerInchOfScreenWidth * 39.3700787
|
|
441 |
!
|
|
442 |
|
|
443 |
name
|
|
444 |
"Answer the receiver's name from the current printerInfo."
|
|
445 |
|
|
446 |
^ self printerInfo printerName
|
|
447 |
|
|
448 |
"Modified: / 02-08-2006 / 16:55:03 / fm"
|
|
449 |
"Modified: / 10-10-2006 / 18:15:33 / cg"
|
|
450 |
!
|
|
451 |
|
|
452 |
name:aName
|
|
453 |
"Set the receiver's printer name to aName."
|
|
454 |
|
|
455 |
self printerInfo:(self class getPrinterInformation:aName)
|
|
456 |
|
|
457 |
"Modified: / 10-10-2006 / 18:15:36 / cg"
|
|
458 |
!
|
|
459 |
|
|
460 |
numberOfColorBitsPerPixel
|
|
461 |
^ OperatingSystem getDeviceCaps:gcId index:12 "Bitspixel"
|
|
462 |
|
|
463 |
"Created: / 03-08-2006 / 09:58:18 / fm"
|
|
464 |
"Modified: / 10-10-2006 / 18:15:40 / cg"
|
|
465 |
!
|
|
466 |
|
|
467 |
physicalOffsetX
|
|
468 |
|
|
469 |
"Papierhöhe in Pixels"
|
|
470 |
"Changed by K3/EEZ3-Mg, 02.03.99"
|
|
471 |
|
|
472 |
^ OperatingSystem getDeviceCaps:gcId index:112 "PhysicalOffsetX"
|
|
473 |
|
|
474 |
"Created: / 01-08-2006 / 16:28:34 / fm"
|
|
475 |
!
|
|
476 |
|
|
477 |
physicalOffsetY
|
|
478 |
|
|
479 |
"Papierhöhe in Pixels"
|
|
480 |
"Changed by K3/EEZ3-Mg, 02.03.99"
|
|
481 |
|
|
482 |
^ OperatingSystem getDeviceCaps:gcId index:113 "PhysicalOffsetY"
|
|
483 |
|
|
484 |
"Created: / 01-08-2006 / 16:28:34 / fm"
|
|
485 |
!
|
|
486 |
|
|
487 |
pixelsPerInchOfScreenHeight
|
|
488 |
^ OperatingSystem getDeviceCaps:gcId index:90 "Logpixelsy"
|
|
489 |
|
|
490 |
"Created: / 01-08-2006 / 16:29:16 / fm"
|
|
491 |
!
|
|
492 |
|
|
493 |
pixelsPerInchOfScreenWidth
|
|
494 |
^ OperatingSystem getDeviceCaps:gcId index:88 "Logpixelsx"
|
|
495 |
|
|
496 |
"Created: / 01-08-2006 / 16:28:34 / fm"
|
|
497 |
!
|
|
498 |
|
|
499 |
printerHeightArea
|
|
500 |
^ (OperatingSystem getDeviceCaps:gcId index:10)
|
|
501 |
|
|
502 |
"Modified: / 10-10-2006 / 18:18:31 / cg"
|
|
503 |
!
|
|
504 |
|
|
505 |
printerInfo
|
|
506 |
"Answer the receiver's name from the current printerInfo."
|
|
507 |
|
|
508 |
^ printerInfo
|
|
509 |
|
|
510 |
"Created: / 02-08-2006 / 16:55:17 / fm"
|
|
511 |
"Modified: / 10-10-2006 / 18:18:34 / cg"
|
|
512 |
!
|
|
513 |
|
|
514 |
printerInfo:aPrinterInfo
|
|
515 |
"Sets the receiver's printerInfo."
|
|
516 |
|
|
517 |
printerInfo := aPrinterInfo
|
|
518 |
|
|
519 |
"Created: / 02-08-2006 / 16:55:34 / fm"
|
|
520 |
"Modified: / 03-08-2006 / 13:11:19 / fm"
|
|
521 |
"Modified: / 10-10-2006 / 18:18:37 / cg"
|
|
522 |
!
|
|
523 |
|
|
524 |
printerInfoWithName:aName
|
|
525 |
"Set the receiver's printer name to aName."
|
|
526 |
|
|
527 |
self printerInfo:(self class getPrinterInformation:aName).
|
|
528 |
^ self
|
|
529 |
|
|
530 |
"Created: / 02-08-2006 / 16:55:52 / fm"
|
|
531 |
"Modified: / 10-10-2006 / 18:18:41 / cg"
|
|
532 |
!
|
|
533 |
|
|
534 |
printerPhysicalHeight
|
|
535 |
^ OperatingSystem getDeviceCaps:gcId "deviceContext" index:111 "PhysicalHeight"
|
|
536 |
|
|
537 |
"Created: / 01-08-2006 / 16:14:08 / fm"
|
|
538 |
!
|
|
539 |
|
|
540 |
printerPhysicalWidth
|
|
541 |
^ OperatingSystem getDeviceCaps:gcId "deviceContext" index:110 "PhysicalWidth"
|
|
542 |
|
|
543 |
"Created: / 01-08-2006 / 16:14:08 / fm"
|
|
544 |
!
|
|
545 |
|
|
546 |
printerUserFriendlyName
|
|
547 |
"Answer the receiver's name from the current printerInfo."
|
|
548 |
|
|
549 |
^ self printerInfo userFriendlyName
|
|
550 |
|
|
551 |
"Created: / 03-08-2006 / 12:55:57 / fm"
|
|
552 |
"Modified: / 10-10-2006 / 18:18:55 / cg"
|
|
553 |
!
|
|
554 |
|
|
555 |
printerWidthArea
|
|
556 |
^ OperatingSystem getDeviceCaps:gcId "deviceContext" index:8 "Horzres"
|
|
557 |
|
|
558 |
"Created: / 01-08-2006 / 16:14:08 / fm"
|
|
559 |
!
|
|
560 |
|
|
561 |
setPrinterFont:aFont
|
|
562 |
|
|
563 |
self font: aFont
|
|
564 |
|
|
565 |
"Created: / 27-11-2006 / 14:50:55 / User"
|
|
566 |
!
|
|
567 |
|
|
568 |
setTextAlign:aNumber
|
|
569 |
|
|
570 |
"/ OperatingSystem setTextAlign: aNumber to: gcId.
|
|
571 |
textAlign :=aNumber.
|
|
572 |
!
|
|
573 |
|
|
574 |
setViewportOrg: aPoint
|
|
575 |
|
|
576 |
^ OperatingSystem
|
|
577 |
setViewportOrg: gcId "deviceContext"
|
|
578 |
x: aPoint x
|
|
579 |
y: aPoint y
|
|
580 |
oldOrigin: nil
|
|
581 |
|
|
582 |
"Created: / 01-08-2006 / 16:14:08 / fm"
|
|
583 |
!
|
|
584 |
|
|
585 |
verticalPixelsPerMeter
|
|
586 |
"Answer vertical pixels per inch
|
|
587 |
on the screen."
|
|
588 |
|
|
589 |
^self pixelsPerInchOfScreenHeight * 39.3700787
|
|
590 |
! !
|
|
591 |
|
|
592 |
!WinPrinterContext methodsFor:'initialization & release'!
|
|
593 |
|
|
594 |
buildPrinter
|
|
595 |
"Private - create all the operating system resources needed."
|
|
596 |
|
|
597 |
self
|
|
598 |
createDC;
|
|
599 |
initExtent
|
|
600 |
|
|
601 |
"Created: / 27-07-2006 / 10:20:36 / fm"
|
|
602 |
"Modified: / 01-08-2006 / 15:57:49 / fm"
|
|
603 |
"Modified: / 10-10-2006 / 18:14:04 / cg"
|
|
604 |
!
|
|
605 |
|
|
606 |
createDC
|
|
607 |
"Private - Create a device context for the receiver"
|
|
608 |
|
|
609 |
gcId := printerInfo createDC
|
|
610 |
|
|
611 |
"Created: / 27-07-2006 / 10:21:05 / fm"
|
|
612 |
"Modified: / 02-08-2006 / 17:30:47 / fm"
|
|
613 |
"Modified: / 10-10-2006 / 18:14:28 / cg"
|
|
614 |
!
|
|
615 |
|
|
616 |
executor
|
|
617 |
|aCopy|
|
|
618 |
|
|
619 |
aCopy := WinWorkstation::PrinterDeviceContextHandle basicNew.
|
|
620 |
aCopy setDevice:device id:nil gcId:gcId.
|
|
621 |
^ aCopy
|
|
622 |
|
|
623 |
"Created: / 16-04-2007 / 12:39:02 / cg"
|
|
624 |
!
|
|
625 |
|
|
626 |
initExtent
|
|
627 |
"Private - init the width and height of GraphicsTool for the receiver."
|
|
628 |
|
|
629 |
width := self printerWidthArea.
|
|
630 |
height := self printerHeightArea.
|
|
631 |
device
|
|
632 |
width:width;
|
|
633 |
height:height.
|
|
634 |
|
|
635 |
|
|
636 |
"Modified: / 01-08-2006 / 16:14:49 / fm"
|
|
637 |
! !
|
|
638 |
|
|
639 |
!WinPrinterContext methodsFor:'printing'!
|
|
640 |
|
|
641 |
print:aString font:aFont title:aTitle wordWrap:wordWrapBoolean marginsRect:aMarginsRect
|
|
642 |
"Answer the receiver. Output the receiver string to
|
|
643 |
the printer using aFont. A Print abort dialog box will be opened
|
|
644 |
with aTitle. If collateBoolean is true, collate output, otherwise
|
|
645 |
do not. Print copiesInteger copies of the specified string. If
|
|
646 |
wordWrapBoolean is true, word wrap the lines, otherwise do not.
|
|
647 |
Left, top, right & bottom margins are specified in inches in
|
|
648 |
aMarginsRect."
|
|
649 |
|
|
650 |
|lines linesPerPage totalPage marginsRect firstPage abortDialog|
|
|
651 |
|
|
652 |
jobid isNil ifTrue:[
|
|
653 |
self startPrintJob:aTitle
|
|
654 |
].
|
|
655 |
abortDialog := PrintAbortDialog new open:aTitle printer:self.
|
|
656 |
self font:aFont.
|
|
657 |
marginsRect := self marginsRectangleFor:aMarginsRect.
|
|
658 |
lines := self
|
|
659 |
asArrayOfStringLines:aString
|
|
660 |
in:marginsRect
|
|
661 |
wordWrap:wordWrapBoolean.
|
|
662 |
linesPerPage := self linesPerPageFor: marginsRect.
|
|
663 |
totalPage := (lines size + linesPerPage - 1) // linesPerPage.
|
|
664 |
firstPage := true.
|
|
665 |
|
|
666 |
"/ collateBoolean
|
|
667 |
"/ ifTrue: [
|
|
668 |
"/ copiesInteger timesRepeat: [
|
|
669 |
|
|
670 |
1 to:totalPage do:[:page |
|
|
671 |
abort ifTrue:[ ^ self ].
|
|
672 |
firstPage ifFalse:[
|
|
673 |
self formFeed
|
|
674 |
].
|
|
675 |
abortDialog
|
|
676 |
updatePrintingPageInfo:(self class classResources
|
|
677 |
string:'Page %1/%2'
|
|
678 |
with:page printString
|
|
679 |
with:totalPage printString).
|
|
680 |
|
|
681 |
"/ self device font: printerFont.
|
|
682 |
|
|
683 |
self font:aFont.
|
|
684 |
self
|
|
685 |
printPage:page
|
|
686 |
in:marginsRect
|
|
687 |
lines:lines
|
|
688 |
linesPerPage:linesPerPage.
|
|
689 |
firstPage := false
|
|
690 |
].
|
|
691 |
|
|
692 |
"/ ]
|
|
693 |
"/ ] ifFalse: [
|
|
694 |
"/ 1 to: totalPage do: [ :page |
|
|
695 |
"/ copiesInteger timesRepeat: [
|
|
696 |
"/ abort ifTrue: [ ^self endPrintJob ].
|
|
697 |
"/ firstPage ifFalse: [ self formFeed ].
|
|
698 |
"/ self device font: printerFont.
|
|
699 |
"/ self printPage: page in: marginsRect lines: lines linesPerPage: linesPerPage.
|
|
700 |
"/ firstPage := false
|
|
701 |
"/ ]
|
|
702 |
"/ ]
|
|
703 |
"/ ].
|
|
704 |
|
|
705 |
jobid notNil ifTrue:[
|
|
706 |
self endPrintJob.
|
|
707 |
abortDialog close.
|
|
708 |
].
|
|
709 |
|
|
710 |
"/ abort ifFalse: [ abortDialog close ]
|
|
711 |
|
|
712 |
"Created: / 03-08-2006 / 16:13:33 / fm"
|
|
713 |
"Modified: / 04-08-2006 / 13:40:02 / fm"
|
|
714 |
"Modified: / 10-10-2006 / 18:16:54 / cg"
|
|
715 |
"Modified: / 12-10-2006 / 11:50:37 / User"
|
|
716 |
!
|
|
717 |
|
|
718 |
print: aString
|
|
719 |
pageHeader: aString2
|
|
720 |
font: aFont
|
|
721 |
title: aTitle
|
|
722 |
collate: collateBoolean
|
|
723 |
copies: copiesInteger
|
|
724 |
wordWrap: wordWrapBoolean
|
|
725 |
marginsRect: aMarginsRect
|
|
726 |
|
|
727 |
"Private - Answer the receiver. Output the receiver string to
|
|
728 |
the printer using aFont. A Print abort dialog box will be opened
|
|
729 |
with aTitle. If collateBoolean is true, collate output, otherwise
|
|
730 |
do not. Print copiesInteger copies of the specified string. If
|
|
731 |
wordWrapBoolean is true, word wrap the lines, otherwise do not.
|
|
732 |
Left, top, right & bottom margins are specified in inches in
|
|
733 |
aMarginsRect.
|
|
734 |
Mg: Erweitert um pageHeader"
|
|
735 |
"Changed by K3/EES5-Mg, 08.01.96"
|
|
736 |
|
|
737 |
| lines linesPerPage totalPage marginsRect firstPage charHeight printerFont headerLines|
|
|
738 |
|
|
739 |
printerFont := self setPrinterFont: aFont.
|
|
740 |
charHeight := self "pen" getCharHeight.
|
|
741 |
marginsRect := self marginsRectangleFor: aMarginsRect.
|
|
742 |
lines := self "pen" asArrayOfStringLines: aString in: marginsRect wordWrap: wordWrapBoolean.
|
|
743 |
headerLines := self "pen" asArrayOfStringLines: aString2 in: marginsRect wordWrap: wordWrapBoolean.
|
|
744 |
linesPerPage := marginsRect bottom - marginsRect top // charHeight.
|
|
745 |
|
|
746 |
linesPerPage > headerLines size
|
|
747 |
ifFalse:
|
|
748 |
[Dialog information: 'Der Dokumentenkopf ist zu groß; wird ignoriert!!'.
|
|
749 |
headerLines := #().
|
|
750 |
]
|
|
751 |
ifTrue: [linesPerPage := linesPerPage - headerLines size].
|
|
752 |
totalPage := lines size + linesPerPage - 1 // linesPerPage.
|
|
753 |
firstPage := true.
|
|
754 |
|
|
755 |
"/ collateBoolean
|
|
756 |
"/ ifTrue: [
|
|
757 |
"/ copiesInteger timesRepeat: [
|
|
758 |
|
|
759 |
1 to: totalPage do: [ :page |
|
|
760 |
abort ifTrue: [ ^self endPrintJob ].
|
|
761 |
firstPage ifFalse: [ self formFeed ].
|
|
762 |
self "pen" font: aFont "printerFont".
|
|
763 |
self printPage: page in: marginsRect lines: lines headerLines: headerLines linesPerPage: linesPerPage.
|
|
764 |
firstPage := false ]
|
|
765 |
|
|
766 |
"/ ]
|
|
767 |
"/ ]
|
|
768 |
"/ ifFalse: [
|
|
769 |
"/ 1 to: totalPage do: [ :page |
|
|
770 |
"/ copiesInteger timesRepeat: [
|
|
771 |
"/ abort ifTrue: [ ^self endPrintJob ].
|
|
772 |
"/ firstPage ifFalse: [ self formFeed ].
|
|
773 |
"/ self "pen" font: printerFont.
|
|
774 |
"/ self printPage: page in: marginsRect lines: lines headerLines: headerLines linesPerPage: linesPerPage.
|
|
775 |
"/ firstPage := false ] ] ].
|
|
776 |
|
|
777 |
"Created: / 30-11-2006 / 13:19:06 / User"
|
|
778 |
!
|
|
779 |
|
|
780 |
print:aString pageHeader:aString2 font:aFont title:aTitle wordWrap:wordWrapBoolean marginsRect:aMarginsRect
|
|
781 |
"Private - Answer the receiver. Output the receiver string to
|
|
782 |
the printer using aFont. A Print abort dialog box will be opened
|
|
783 |
with aTitle. If collateBoolean is true, collate output, otherwise
|
|
784 |
do not. Print copiesInteger copies of the specified string. If
|
|
785 |
wordWrapBoolean is true, word wrap the lines, otherwise do not.
|
|
786 |
Left, top, right & bottom margins are specified in inches in
|
|
787 |
aMarginsRect."
|
|
788 |
|
|
789 |
|lines linesPerPage totalPage marginsRect firstPage charHeight printerFont headerLines|
|
|
790 |
|
|
791 |
self font:aFont.
|
|
792 |
charHeight := self getCharHeight.
|
|
793 |
marginsRect := self marginsRectangleFor:aMarginsRect.
|
|
794 |
lines := self
|
|
795 |
asArrayOfStringLines:aString
|
|
796 |
in:marginsRect
|
|
797 |
wordWrap:wordWrapBoolean.
|
|
798 |
headerLines := self
|
|
799 |
asArrayOfStringLines:aString2
|
|
800 |
in:marginsRect
|
|
801 |
wordWrap:wordWrapBoolean.
|
|
802 |
linesPerPage := (marginsRect bottom - marginsRect top) // charHeight.
|
|
803 |
linesPerPage > headerLines size ifFalse:[
|
|
804 |
Dialog information:(self class classResources
|
|
805 |
string:'The header is too large - ignored!!').
|
|
806 |
headerLines := #().
|
|
807 |
] ifTrue:[
|
|
808 |
linesPerPage := linesPerPage - headerLines size
|
|
809 |
].
|
|
810 |
totalPage := (lines size + linesPerPage - 1) // linesPerPage.
|
|
811 |
firstPage := true.
|
|
812 |
|
|
813 |
"/ collateBoolean
|
|
814 |
"/ ifTrue: [
|
|
815 |
"/ copiesInteger timesRepeat: [
|
|
816 |
|
|
817 |
1 to:totalPage do:[:page |
|
|
818 |
abort ifTrue:[ ^ self ].
|
|
819 |
firstPage ifFalse:[
|
|
820 |
self formFeed
|
|
821 |
].
|
|
822 |
self font:printerFont.
|
|
823 |
self
|
|
824 |
printPage:page
|
|
825 |
in:marginsRect
|
|
826 |
lines:lines
|
|
827 |
headerLines:headerLines
|
|
828 |
linesPerPage:linesPerPage.
|
|
829 |
firstPage := false
|
|
830 |
]
|
|
831 |
|
|
832 |
"/ ]
|
|
833 |
"/ ] ifFalse: [
|
|
834 |
"/ 1 to: totalPage do: [ :page |
|
|
835 |
"/ copiesInteger timesRepeat: [
|
|
836 |
"/ abort ifTrue: [ ^self endPrintJob ].
|
|
837 |
"/ firstPage ifFalse: [ self formFeed ].
|
|
838 |
"/ self device font: printerFont.
|
|
839 |
"/ self printPage: page in: marginsRect lines: lines headerLines: headerLines linesPerPage: linesPerPage.
|
|
840 |
"/ firstPage := false
|
|
841 |
"/ ]
|
|
842 |
"/ ]
|
|
843 |
"/ ].
|
|
844 |
|
|
845 |
"Created: / 03-08-2006 / 16:14:10 / fm"
|
|
846 |
"Modified: / 10-10-2006 / 18:18:03 / cg"
|
|
847 |
! !
|
|
848 |
|
|
849 |
!WinPrinterContext methodsFor:'printing process'!
|
|
850 |
|
|
851 |
endPage
|
|
852 |
"Informs device that we are finished writing to a page."
|
|
853 |
|
|
854 |
(OperatingSystem endPage:gcId) > 0 ifFalse:[
|
|
855 |
self error
|
|
856 |
]
|
|
857 |
|
|
858 |
"Created: / 27-07-2006 / 18:20:48 / fm"
|
|
859 |
"Modified: / 01-08-2006 / 16:01:34 / fm"
|
|
860 |
"Modified: / 10-10-2006 / 18:14:44 / cg"
|
|
861 |
!
|
|
862 |
|
|
863 |
endPrintJob
|
|
864 |
"End the print job. Everything drawn between startPrintJob
|
|
865 |
and endPrintJob will become one entry in the print queue."
|
|
866 |
|
|
867 |
|result|
|
|
868 |
|
|
869 |
self endPage.
|
|
870 |
result := OperatingSystem endDoc:gcId.
|
|
871 |
device close.
|
|
872 |
gcId := nil.
|
|
873 |
jobid := nil.
|
|
874 |
result >= 0 ifFalse:[ self error ]
|
|
875 |
|
|
876 |
"Created: / 27-07-2006 / 18:21:04 / fm"
|
|
877 |
"Modified: / 01-08-2006 / 16:01:38 / fm"
|
|
878 |
"Modified: / 10-10-2006 / 18:50:43 / cg"
|
|
879 |
!
|
|
880 |
|
|
881 |
formFeed
|
|
882 |
"Send a form feed to the printer."
|
|
883 |
|
|
884 |
self
|
|
885 |
endPage;
|
|
886 |
startPage
|
|
887 |
|
|
888 |
"Created: / 27-07-2006 / 18:25:40 / fm"
|
|
889 |
"Modified: / 10-10-2006 / 18:15:07 / cg"
|
|
890 |
!
|
|
891 |
|
|
892 |
startPage
|
|
893 |
"Starts a page."
|
|
894 |
|
|
895 |
(OperatingSystem startPage:gcId) > 0 ifFalse:[
|
|
896 |
^ self error
|
|
897 |
].
|
|
898 |
|
|
899 |
"Created: / 27-07-2006 / 18:25:55 / fm"
|
|
900 |
"Modified: / 28-07-2006 / 18:19:04 / fm"
|
|
901 |
"Modified: / 10-10-2006 / 18:19:02 / cg"
|
|
902 |
!
|
|
903 |
|
|
904 |
startPrintJob
|
|
905 |
"Start a print job. Everything drawn between startPrintJob
|
|
906 |
and endPrintJob will become one entry in the print queue."
|
|
907 |
|
|
908 |
self startPrintJob:nil
|
|
909 |
|
|
910 |
"Created: / 27-07-2006 / 18:18:52 / fm"
|
|
911 |
"Modified: / 10-10-2006 / 18:19:05 / cg"
|
|
912 |
!
|
|
913 |
|
|
914 |
startPrintJob:aString
|
|
915 |
"Start a print job, using aString as the job title; everything
|
|
916 |
drawn between startPrintJob and endPrintJob will become
|
|
917 |
one entry in the print queue."
|
|
918 |
|
|
919 |
^ self startPrintJob:aString fileName:nil
|
|
920 |
|
|
921 |
"Created: / 27-07-2006 / 18:19:09 / fm"
|
|
922 |
"Modified: / 10-10-2006 / 18:19:12 / cg"
|
|
923 |
!
|
|
924 |
|
|
925 |
startPrintJob:aString fileName:aFileName
|
|
926 |
"Start a print job, using aString as the job title; everything
|
|
927 |
drawn between startPrintJob and endPrintJob will become
|
|
928 |
one entry in the print queue."
|
|
929 |
|
|
930 |
|docInfoStruct nameAddress title fileNameAddress|
|
|
931 |
|
|
932 |
gcId isNil ifTrue:[
|
|
933 |
self buildPrinter
|
|
934 |
].
|
|
935 |
abort := false.
|
|
936 |
title := aString ? 'Smalltalk/X'.
|
|
937 |
nameAddress := title asExternalBytes unprotectFromGC.
|
|
938 |
aFileName isNil ifFalse:[
|
|
939 |
fileNameAddress := aFileName pathName asExternalBytes unprotectFromGC
|
|
940 |
].
|
|
941 |
docInfoStruct := Win32OperatingSystem::DocInfoStructure new.
|
|
942 |
docInfoStruct
|
|
943 |
cbSize:docInfoStruct sizeInBytes;
|
|
944 |
lpszDocName:nameAddress address.
|
|
945 |
fileNameAddress isNil ifFalse:[
|
|
946 |
docInfoStruct lpszOutput:fileNameAddress address
|
|
947 |
].
|
|
948 |
jobid := OperatingSystem startDoc:gcId docInfo:docInfoStruct.
|
|
949 |
jobid > 0 ifFalse:[
|
|
950 |
jobid = -1 ifTrue:[
|
|
951 |
abort := true.
|
|
952 |
^ nil
|
|
953 |
].
|
|
954 |
^ self error
|
|
955 |
].
|
|
956 |
self startPage
|
|
957 |
|
|
958 |
"Created: / 27-07-2006 / 18:19:31 / fm"
|
|
959 |
"Modified: / 03-08-2006 / 15:11:19 / fm"
|
|
960 |
"Modified: / 10-10-2006 / 18:20:01 / cg"
|
|
961 |
! !
|
|
962 |
|
|
963 |
!WinPrinterContext methodsFor:'queries'!
|
|
964 |
|
|
965 |
supportsColor
|
|
966 |
|
|
967 |
"/ | retVal info |
|
|
968 |
"/
|
|
969 |
"/ info := (self class getPrinterInformation: self name) asUppercase.
|
|
970 |
"/ (info includesSubstring: ',PSCRIPT,')
|
|
971 |
"/ ifTrue: [
|
|
972 |
"/ retVal := (DAPASX::DapasSystemInfo getYesNoInfoApp: 'Printer' profile: 'PostScriptBlackWhite') not.
|
|
973 |
"/ ]
|
|
974 |
"/ ifFalse: [
|
|
975 |
"/ retVal := (info includesSubstring: 'PDF')
|
|
976 |
"/ ifTrue: [true]
|
|
977 |
"/ ifFalse: [self numberOfColorBitsPerPixel > 1].
|
|
978 |
"/ ].
|
|
979 |
"/
|
|
980 |
"/ ^retVal
|
|
981 |
|
|
982 |
^ false.
|
|
983 |
|
|
984 |
"Created: / 03-08-2006 / 09:55:26 / fm"
|
|
985 |
"Modified: / 04-08-2006 / 13:20:40 / fm"
|
|
986 |
"Modified: / 10-10-2006 / 18:21:07 / cg"
|
|
987 |
!
|
|
988 |
|
|
989 |
supportsGraphics
|
|
990 |
^(OperatingSystem getDeviceCaps: gcId "asParameter" index: 2 "Technology") ~= 4
|
|
991 |
|
|
992 |
"Created: / 03-08-2006 / 10:07:43 / fm"
|
|
993 |
"Modified: / 10-10-2006 / 18:21:14 / cg"
|
|
994 |
! !
|
|
995 |
|
|
996 |
!WinPrinterContext methodsFor:'text printing'!
|
|
997 |
|
|
998 |
asArrayOfStringLines:aString in:aRectangle wordWrap:wordWrapBoolean
|
|
999 |
"Private - convert aString into an array of lines; if wordWrapBoolean
|
|
1000 |
is true, also perform word wrapping on the lines, within aRectangle."
|
|
1001 |
|
|
1002 |
|line lines stream x0 x1 partialLine leftMargin rightMargin partialLineWidth index|
|
|
1003 |
|
|
1004 |
stream := ReadStream on:aString.
|
|
1005 |
lines := OrderedCollection new.
|
|
1006 |
wordWrapBoolean ifTrue:[
|
|
1007 |
leftMargin := aRectangle left.
|
|
1008 |
rightMargin := aRectangle right
|
|
1009 |
].
|
|
1010 |
[ stream atEnd ] whileFalse:[
|
|
1011 |
line := stream nextLine.
|
|
1012 |
wordWrapBoolean ifFalse:[
|
|
1013 |
lines add:line
|
|
1014 |
] ifTrue:[
|
|
1015 |
x0 := x1 := 1.
|
|
1016 |
1 to:line size do:[:i |
|
|
1017 |
((line at:i) = Character space "32"
|
|
1018 |
and:[ (partialLine := line copyFrom:x0 to:i) trimBlanks notEmpty ])
|
|
1019 |
ifTrue:[
|
|
1020 |
partialLineWidth := self stringWidthOf:partialLine.
|
|
1021 |
(leftMargin + partialLineWidth) > rightMargin ifTrue:[
|
|
1022 |
partialLine := line copyFrom:x0 to:x1.
|
|
1023 |
lines add:partialLine.
|
|
1024 |
x0 := x1 + 1
|
|
1025 |
] ifFalse:[ x1 := i ]
|
|
1026 |
].
|
|
1027 |
index := i
|
|
1028 |
].
|
|
1029 |
line isEmpty ifTrue:[
|
|
1030 |
lines add:line
|
|
1031 |
] ifFalse:[
|
|
1032 |
partialLine := line copyFrom:x0 to:index.
|
|
1033 |
partialLineWidth := self stringWidthOf:partialLine.
|
|
1034 |
(leftMargin + partialLineWidth) > rightMargin ifTrue:[
|
|
1035 |
partialLine := line copyFrom:x0 to:x1.
|
|
1036 |
lines add:partialLine.
|
|
1037 |
partialLine := line copyFrom:x1 + 1 to:index
|
|
1038 |
].
|
|
1039 |
lines add:partialLine
|
|
1040 |
]
|
|
1041 |
]
|
|
1042 |
].
|
|
1043 |
^ lines asArray
|
|
1044 |
|
|
1045 |
"Created: / 02-08-2006 / 17:56:51 / fm"
|
|
1046 |
"Modified: / 04-08-2006 / 13:39:50 / fm"
|
|
1047 |
"Modified: / 10-10-2006 / 18:14:00 / cg"
|
|
1048 |
!
|
|
1049 |
|
|
1050 |
displayString:aString at:aPoint in:aRect options:ignoredForNow adx:unknownForNow
|
|
1051 |
|x y|
|
|
1052 |
x := aPoint x.
|
|
1053 |
y := aPoint y.
|
|
1054 |
(textAlign isNil or:[textAlign == 0 ]) ifTrue:[
|
|
1055 |
self displayString:aString at:aPoint.
|
|
1056 |
^ self
|
|
1057 |
].
|
|
1058 |
(textAlign == 8 "TaBottom") ifTrue:[
|
|
1059 |
y := aPoint y - (self container font ascent) "container font ascent".
|
|
1060 |
] ifFalse:[ (textAlign == 6 "TaCenter") ifTrue:[
|
|
1061 |
#TODO.
|
|
1062 |
"/ x := aRect left + ((aRect width-(container font widthOf:aString))//2).
|
|
1063 |
] ifFalse:[ (textAlign == 2 "TaRight") ifTrue:[
|
|
1064 |
x := aRect right - (self "container font widthof:" stringWidthOf:aString).
|
|
1065 |
y := self "container font ascent" getCharHeight + aPoint y .
|
|
1066 |
] ifFalse:[ (textAlign == 14 "TaCenterBottom") ifTrue:[
|
|
1067 |
y := aRect bottom - self getCharHeight "container font ascent".
|
|
1068 |
x := aRect left + ((aRect width-(self "container font widthOf:" stringWidthOf:aString))//2).
|
|
1069 |
] ifFalse:[ (textAlign == 10) ifTrue:[
|
|
1070 |
x := aRect right - (self "container font widthof:" stringWidthOf:aString).
|
|
1071 |
y := aRect bottom "aPoint y - (self container font ascent)" - self getCharHeight.
|
|
1072 |
]]]]].
|
|
1073 |
"/ Transcript showCR: 'Original Pos: ', aPoint x printString, '@', aPoint y printString,
|
|
1074 |
"/ ' Pos: ', x printString, '@', y printString,
|
|
1075 |
"/ ' Text: ', aString.
|
|
1076 |
self displayString:aString at:(x@y).
|
|
1077 |
|
|
1078 |
"Modified: / 14-12-2006 / 12:29:13 / User"
|
|
1079 |
!
|
|
1080 |
|
|
1081 |
displayStringLines:anIndexedCollection from:startIndex to:endIndex in:aRectangle
|
|
1082 |
"Private - display Strings in anIndexedCollection starting at startIndex and
|
|
1083 |
ending at endIndex, clipped within the bounds of aRectangle."
|
|
1084 |
|
|
1085 |
|charHeight ta region ascent|
|
|
1086 |
|
|
1087 |
charHeight := self getCharHeight.
|
|
1088 |
ascent := self font ascentOn:self device.
|
|
1089 |
startIndex to:endIndex do:[:i |
|
|
1090 |
|lineToPrint|
|
|
1091 |
|
|
1092 |
lineToPrint := (anIndexedCollection at:i).
|
|
1093 |
self device
|
|
1094 |
displayString:lineToPrint
|
|
1095 |
from:1
|
|
1096 |
to:lineToPrint size
|
|
1097 |
x:aRectangle left
|
|
1098 |
y:(aRectangle top + ((i - startIndex) * charHeight))
|
|
1099 |
in:nil
|
|
1100 |
with:gcId
|
|
1101 |
opaque:false
|
|
1102 |
fontAscent:ascent.
|
|
1103 |
].
|
|
1104 |
|
|
1105 |
"/ region := self setClipRect: aRectangle.
|
|
1106 |
"/ ta := self getTextAlign.
|
|
1107 |
"/ self setTextAlign: TaTop.
|
|
1108 |
"/ startIndex to: endIndex do: [ :i |
|
|
1109 |
"/ self
|
|
1110 |
"/ displayText: ( anIndexedCollection at: i )
|
|
1111 |
"/ at: aRectangle left @ ( aRectangle top + ( i - startIndex * charHeight ) ) ].
|
|
1112 |
"/ self setTextAlign: ta.
|
|
1113 |
"/ self destroyRegion: region
|
|
1114 |
|
|
1115 |
"Created: / 03-08-2006 / 11:37:52 / fm"
|
|
1116 |
"Modified: / 03-08-2006 / 12:38:43 / fm"
|
|
1117 |
"Modified: / 10-10-2006 / 18:14:36 / cg"
|
|
1118 |
!
|
|
1119 |
|
|
1120 |
displayStringLines:anIndexedCollection in:aRectangle
|
|
1121 |
"Private - display anIndexedCollection of Strings clipped within
|
|
1122 |
the bounds of aRectangle."
|
|
1123 |
|
|
1124 |
self
|
|
1125 |
displayStringLines:anIndexedCollection
|
|
1126 |
from:1
|
|
1127 |
to:anIndexedCollection size
|
|
1128 |
in:aRectangle
|
|
1129 |
|
|
1130 |
"Created: / 03-08-2006 / 16:03:07 / fm"
|
|
1131 |
"Modified: / 10-10-2006 / 18:14:40 / cg"
|
|
1132 |
!
|
|
1133 |
|
|
1134 |
displayText: aString at: aPoint
|
|
1135 |
|
|
1136 |
self displayString:aString x:aPoint x y:aPoint y
|
|
1137 |
!
|
|
1138 |
|
|
1139 |
linesPerPageFor: aRectangle
|
|
1140 |
|
|
1141 |
|marginsRect charHeight|
|
|
1142 |
|
|
1143 |
marginsRect := aRectangle isNil
|
|
1144 |
ifTrue:[self marginsRectangleFor: nil]
|
|
1145 |
ifFalse:[aRectangle].
|
|
1146 |
|
|
1147 |
charHeight := self getCharHeight.
|
|
1148 |
^(marginsRect bottom - marginsRect top) // charHeight
|
|
1149 |
|
|
1150 |
"Created: / 12-10-2006 / 11:52:57 / User"
|
|
1151 |
!
|
|
1152 |
|
|
1153 |
marginsRectangleFor:aRectangle
|
|
1154 |
"Private - Answer a Rectangle defining margins based on aRectangle.
|
|
1155 |
Units for aRectangle are in inches, returned margins rectangle is
|
|
1156 |
in device units (pixels)."
|
|
1157 |
|
|
1158 |
|left top right bottom pixelsPerInchX pixelsPerInchY horzRes vertRes inset rectangle|
|
|
1159 |
|
|
1160 |
pixelsPerInchX := self pixelsPerInchOfScreenWidth.
|
|
1161 |
pixelsPerInchX == 0 ifTrue:[self halt].
|
|
1162 |
pixelsPerInchY := self pixelsPerInchOfScreenHeight.
|
|
1163 |
aRectangle isNil ifTrue:[
|
|
1164 |
horzRes := self printerWidthArea.
|
|
1165 |
vertRes := self printerHeightArea.
|
|
1166 |
inset := self class defaultMargins.
|
|
1167 |
left := (inset x * pixelsPerInchX) asInteger.
|
|
1168 |
top := (inset y * pixelsPerInchY) asInteger.
|
|
1169 |
right := horzRes - (inset x * pixelsPerInchX) asInteger.
|
|
1170 |
bottom := vertRes - (inset y * pixelsPerInchY) asInteger
|
|
1171 |
] ifFalse:[
|
|
1172 |
left := (aRectangle left * pixelsPerInchX) asInteger.
|
|
1173 |
top := (aRectangle top * pixelsPerInchY) asInteger.
|
|
1174 |
right := (aRectangle right * pixelsPerInchX) asInteger.
|
|
1175 |
bottom := (aRectangle bottom * pixelsPerInchY) asInteger
|
|
1176 |
].
|
|
1177 |
rectangle := left @ top corner:right @ bottom.
|
|
1178 |
^ rectangle
|
|
1179 |
|
|
1180 |
"Created: / 27-07-2006 / 18:22:57 / fm"
|
|
1181 |
"Modified: / 04-08-2006 / 13:39:45 / fm"
|
|
1182 |
"Modified: / 16-04-2007 / 11:57:21 / cg"
|
|
1183 |
!
|
|
1184 |
|
|
1185 |
printPage:pageIndex in:aRectangle lines:lines headerLines:headerLines linesPerPage:linesPerPage
|
|
1186 |
"Private - print page # pageIndex from lines, assuming
|
|
1187 |
the given number of linesPerPage."
|
|
1188 |
|
|
1189 |
|firstLine lastLine l indexString p cHeight rect hLines|
|
|
1190 |
|
|
1191 |
firstLine := (pageIndex - 1) * linesPerPage + 1.
|
|
1192 |
lastLine := (firstLine + linesPerPage - 1) min:lines size.
|
|
1193 |
rect := aRectangle deepCopy.
|
|
1194 |
hLines := headerLines deepCopy.
|
|
1195 |
headerLines size > 0 ifTrue:[
|
|
1196 |
l := hLines first.
|
|
1197 |
p := l indexOfSubCollection: "indexOfString:"'#P'.
|
|
1198 |
p = 0 ifFalse:[
|
|
1199 |
indexString := pageIndex printString , ' '.
|
|
1200 |
l := (l copyFrom:1 to:p - 1) , indexString , (l copyFrom:p + 2 to:l size).
|
|
1201 |
hLines at:1 put:l.
|
|
1202 |
].
|
|
1203 |
cHeight := self getCharHeight.
|
|
1204 |
rect top:rect top + (hLines size * cHeight).
|
|
1205 |
].
|
|
1206 |
self displayStringLines:hLines in:aRectangle.
|
|
1207 |
self
|
|
1208 |
displayStringLines:lines
|
|
1209 |
from:firstLine
|
|
1210 |
to:lastLine
|
|
1211 |
in:rect.
|
|
1212 |
|
|
1213 |
"Created: / 27-07-2006 / 18:28:00 / fm"
|
|
1214 |
"Modified: / 03-08-2006 / 16:03:15 / fm"
|
|
1215 |
"Modified: / 10-10-2006 / 18:18:15 / cg"
|
|
1216 |
"Modified: / 30-11-2006 / 13:34:44 / User"
|
|
1217 |
!
|
|
1218 |
|
|
1219 |
printPage:pageIndex in:aRectangle lines:lines linesPerPage:linesPerPage
|
|
1220 |
"Private - print page # pageIndex from lines, assuming
|
|
1221 |
the given number of linesPerPage."
|
|
1222 |
|
|
1223 |
|firstLine lastLine|
|
|
1224 |
|
|
1225 |
firstLine := (pageIndex - 1) * linesPerPage + 1.
|
|
1226 |
lastLine := (firstLine + linesPerPage - 1) min:lines size.
|
|
1227 |
self
|
|
1228 |
displayStringLines:lines
|
|
1229 |
from:firstLine
|
|
1230 |
to:lastLine
|
|
1231 |
in:aRectangle
|
|
1232 |
|
|
1233 |
"Created: / 27-07-2006 / 18:24:59 / fm"
|
|
1234 |
"Modified: / 03-08-2006 / 12:47:24 / fm"
|
|
1235 |
"Modified: / 10-10-2006 / 18:18:22 / cg"
|
|
1236 |
!
|
|
1237 |
|
|
1238 |
stringWidthOf:aString
|
|
1239 |
"Return the width of aString
|
|
1240 |
when written using the current font."
|
|
1241 |
|
|
1242 |
^ self stringWidthOf:aString at:aString size.
|
|
1243 |
|
|
1244 |
"Modified: / 03-08-2006 / 10:18:23 / fm"
|
|
1245 |
"Modified: / 10-10-2006 / 18:20:08 / cg"
|
|
1246 |
!
|
|
1247 |
|
|
1248 |
stringWidthOf:aString at:index
|
|
1249 |
"Return the width of aString up to index
|
|
1250 |
when written using the current font; expand tabs out
|
|
1251 |
to 4 spaces for calculations"
|
|
1252 |
|
|
1253 |
|answer str size spaceWidth|
|
|
1254 |
|
|
1255 |
index <= 0 ifTrue:[ ^ 0 ].
|
|
1256 |
str := index >= aString size ifTrue:[ aString ] ifFalse:[ aString copyFrom:1 to:index ].
|
|
1257 |
true "self font isNil" ifTrue:[
|
|
1258 |
"if font not set yet, calculate based on default font"
|
|
1259 |
"/ extString := str asExternalString.
|
|
1260 |
size := Win32OperatingSystem::WinPointStructure new.
|
|
1261 |
(OperatingSystem
|
|
1262 |
getTextExtentPoint:gcId
|
|
1263 |
string:str
|
|
1264 |
size:size) ifFalse:[ ^ self error ].
|
|
1265 |
answer := size x.
|
|
1266 |
"/ Transcript showCR: 'FROM PRIM ******* ', str, ' ', answer printString.
|
|
1267 |
"/ Transcript showCR: 'FROM DEVICE ***** ', str, ' ',(self font widthOf:str on:self device) printString.
|
|
1268 |
#TODO.
|
|
1269 |
] ifFalse:[
|
|
1270 |
answer := self font widthOf:str on:self device
|
|
1271 |
].
|
|
1272 |
index > aString size ifTrue:[
|
|
1273 |
spaceWidth := self font widthOf:Character space on:self device.
|
|
1274 |
answer := answer + ((index - aString size) * spaceWidth)
|
|
1275 |
].
|
|
1276 |
^ answer.
|
|
1277 |
|
|
1278 |
"Created: / 03-08-2006 / 10:27:20 / fm"
|
|
1279 |
"Modified: / 04-08-2006 / 12:27:26 / fm"
|
|
1280 |
"Modified: / 10-10-2006 / 18:20:43 / cg"
|
|
1281 |
!
|
|
1282 |
|
|
1283 |
withLineStyle:aSymbol lineWidth:lw paint:paintColor do:aBlock
|
|
1284 |
|savStyle savWidth savPaint|
|
|
1285 |
|
|
1286 |
savStyle := self lineStyle.
|
|
1287 |
savWidth := self lineWidth.
|
|
1288 |
savPaint := self paint.
|
|
1289 |
|
|
1290 |
self lineStyle:aSymbol.
|
|
1291 |
self lineWidth:lw.
|
|
1292 |
self paint:paintColor.
|
|
1293 |
aBlock value.
|
|
1294 |
self paint:savPaint.
|
|
1295 |
self lineWidth:savWidth.
|
|
1296 |
self lineStyle:savStyle.
|
|
1297 |
|
|
1298 |
"Created: / 13-09-2006 / 15:38:56 / User"
|
|
1299 |
! !
|
|
1300 |
|
|
1301 |
!WinPrinterContext class methodsFor:'documentation'!
|
|
1302 |
|
|
1303 |
version
|
|
1304 |
^ '$Header: /cvs/stx/stx/libview2/WinPrinterContext.st,v 1.1 2007-04-16 10:40:02 cg Exp $'
|
|
1305 |
! !
|