author | Claus Gittinger <cg@exept.de> |
Tue, 10 Oct 2006 17:55:30 +0200 | |
changeset 2235 | 0df6bda4b353 |
parent 2184 | c108f1291023 |
child 2236 | 76291d984db9 |
permissions | -rw-r--r-- |
2184 | 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 |
" |
|
2143 | 12 |
"{ Package: 'stx:libview2' }" |
13 |
||
14 |
GraphicsMedium subclass:#PrinterContext |
|
15 |
instanceVariableNames:'name abort jobid printerInfo' |
|
16 |
classVariableNames:'' |
|
17 |
poolDictionaries:'' |
|
18 |
category:'Interface-Printing' |
|
19 |
! |
|
20 |
||
2184 | 21 |
!PrinterContext 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 |
" |
|
2235
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
35 |
! |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
36 |
|
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
37 |
documentation |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
38 |
" |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
39 |
I am the mediator between the smalltalk printing protocol |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
40 |
(which is the same as the graphics drawing protocol) and the |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
41 |
windows printer. |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
42 |
When youopena printer, you will typically talk to me, and I will |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
43 |
forward the graphics commands to my printer. |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
44 |
|
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
45 |
[author:] |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
46 |
Felix Madrid (fm@exept.de) |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
47 |
" |
2184 | 48 |
! ! |
2143 | 49 |
|
50 |
!PrinterContext class methodsFor:'instance creation'! |
|
51 |
||
52 |
fromPrinterInfo: aPrinterInfo |
|
2235
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
53 |
"Private - Answer a Printer object given an hDC" |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
54 |
|
2143 | 55 |
| aPrinter hDC| |
56 |
||
57 |
hDC := aPrinterInfo createDC. |
|
58 |
hDC = 0 ifTrue: [ ^self error: 'Error while opening printer.' ]. |
|
59 |
aPrinter := self new. |
|
60 |
aPrinter printerInfo: aPrinterInfo. |
|
61 |
aPrinter setDevice:(WinPrinter on: aPrinterInfo) id:nil gcId:hDC. |
|
62 |
aPrinter initExtent. |
|
63 |
^aPrinter |
|
64 |
||
65 |
"Created: / 03-08-2006 / 12:53:52 / fm" |
|
66 |
"Modified: / 04-08-2006 / 12:55:01 / fm" |
|
2235
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
67 |
"Modified: / 10-10-2006 / 17:32:59 / cg" |
2143 | 68 |
! |
69 |
||
70 |
printWith: aRecordingPen |
|
71 |
"Print the contents of aRecordingPen on |
|
72 |
the system printer." |
|
73 |
self new drawUsing: aRecordingPen |
|
74 |
||
75 |
"Created: / 27-07-2006 / 17:53:59 / fm" |
|
76 |
! ! |
|
77 |
||
78 |
!PrinterContext class methodsFor:'accessing'! |
|
79 |
||
80 |
default |
|
2235
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
81 |
"Answer the default Printer, or nil if none." |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
82 |
|
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
83 |
|defaultName| |
2143 | 84 |
|
2235
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
85 |
^ (defaultName := self defaultPrinterName) isNil |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
86 |
ifTrue:[ nil ] |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
87 |
ifFalse:[ self named:defaultName ] |
2143 | 88 |
|
2235
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
89 |
" |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
90 |
self default |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
91 |
" |
2143 | 92 |
|
93 |
"Created: / 27-07-2006 / 17:51:43 / fm" |
|
94 |
"Modified: / 02-08-2006 / 17:27:09 / fm" |
|
2235
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
95 |
"Modified: / 10-10-2006 / 17:30:31 / cg" |
2143 | 96 |
! |
97 |
||
98 |
defaultMargins |
|
2235
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
99 |
"Private - answer aPoint containing the default horizontal and vertical |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
100 |
margins for a page (units in inches)." |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
101 |
|
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
102 |
^ 0.5 @ 0.75 |
2143 | 103 |
|
104 |
"Created: / 01-08-2006 / 16:09:31 / fm" |
|
2235
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
105 |
"Modified: / 10-10-2006 / 17:30:49 / cg" |
2143 | 106 |
! |
107 |
||
108 |
defaultPrinterName |
|
2235
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
109 |
"Answer the name of the default printer, or nil if none." |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
110 |
|
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
111 |
|printerInfo printerName| |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
112 |
|
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
113 |
printerInfo := OperatingSystem getDefaultPrinterName. |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
114 |
printerName := (printerInfo copyFrom:1 to:(printerInfo indexOf:$,) - 1) trimBlanks. |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
115 |
^ printerName size == 0 ifTrue:[ nil ] ifFalse:[ printerName ] |
2143 | 116 |
|
117 |
" |
|
118 |
PrinterContext defaultPrinterName |
|
2235
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
119 |
" |
2143 | 120 |
|
121 |
"Modified: / 02-08-2006 / 17:26:09 / fm" |
|
2235
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
122 |
"Modified: / 10-10-2006 / 17:32:45 / cg" |
2143 | 123 |
! |
124 |
||
125 |
getPrinterInformation: printerNameString |
|
2235
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
126 |
" Answer the printer information for the printer named printerNameString. If no name is specified, |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
127 |
answer the information for the default printer. " |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
128 |
|
2143 | 129 |
| h | |
130 |
||
131 |
h := OperatingSystem openPrinter: printerNameString. |
|
132 |
^OperatingSystem getDocumentProperties:nil hPrinter:h pDeviceName: printerNameString . |
|
133 |
||
134 |
"Created: / 27-07-2006 / 10:22:32 / fm" |
|
135 |
"Modified: / 01-08-2006 / 16:01:44 / fm" |
|
2235
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
136 |
"Modified: / 10-10-2006 / 17:33:07 / cg" |
2143 | 137 |
! |
138 |
||
139 |
named: aName |
|
2235
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
140 |
"Answer a new instance of Printer which represents |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
141 |
the printer named aName as specified in the host |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
142 |
Control Panel." |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
143 |
|
2143 | 144 |
aName isNil ifTrue: [ ^self default ]. |
2235
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
145 |
^self new printerInfoWithName: aName |
2143 | 146 |
|
147 |
"Created: / 27-07-2006 / 17:51:27 / fm" |
|
148 |
"Modified: / 02-08-2006 / 17:26:29 / fm" |
|
2235
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
149 |
"Modified: / 10-10-2006 / 17:33:29 / cg" |
2143 | 150 |
! |
151 |
||
152 |
printerNames |
|
153 |
"Answer a collection of all known printer names." |
|
154 |
||
155 |
^OperatingSystem getPrintersNames |
|
156 |
||
157 |
"Created: / 27-07-2006 / 17:54:45 / fm" |
|
158 |
! ! |
|
159 |
||
2235
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
160 |
!PrinterContext class methodsFor:'testing & examples'! |
2143 | 161 |
|
162 |
print: aString font: aFont title: aTitle |
|
2235
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
163 |
"Open a print dialog to allow printing of the given string |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
164 |
using the given title & font." |
2143 | 165 |
|
166 |
self print: aString font: aFont title: aTitle wordWrap: false |
|
167 |
||
2235
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
168 |
" |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
169 |
PrinterContext print: 'Holaaaa!! (from: PrinterContext>>print:aString font:aFont title:aTitle)' font: nil title: 'Printing Test' |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
170 |
PrinterContext print: self printingTestString font: nil title: 'Printing Test String' |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
171 |
PrinterContext print: self printingTestString font: (Font family:'Arial' face:'medium' size:8) title: 'Printing Test String' |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
172 |
" |
2143 | 173 |
|
174 |
"Created: / 27-07-2006 / 17:52:33 / fm" |
|
175 |
"Modified: / 03-08-2006 / 18:52:31 / fm" |
|
2235
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
176 |
"Modified: / 10-10-2006 / 17:37:49 / cg" |
2143 | 177 |
! |
178 |
||
179 |
print: aString font: aFont title: aTitle wordWrap: wordWrap |
|
2235
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
180 |
"Open a print dialog to allow printing of the given string |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
181 |
using the given title & font." |
2143 | 182 |
|
183 |
| printerInfo printer | |
|
2235
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
184 |
|
2143 | 185 |
printerInfo := PrintingDialog getPrinterInfo. |
186 |
printerInfo isNil ifTrue:[^self]. |
|
187 |
||
188 |
printer := self fromPrinterInfo: printerInfo. |
|
189 |
[ |
|
2235
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
190 |
printer |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
191 |
print: aString |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
192 |
font: aFont |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
193 |
title: aTitle |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
194 |
wordWrap: wordWrap |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
195 |
marginsRect: nil |
2143 | 196 |
] forkAt: 3 |
197 |
||
2235
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
198 |
" |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
199 |
PrinterContext print: 'Holaaaa!! (from: PrinterContext>>print:aString font:aFont title:aTitle)' font: nil title: 'Printing Test' wordWrap: true |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
200 |
PrinterContext print: (PrinterContext class sourceCodeAt:#'print:font:title:wordWrap:') font:nil title:'Printing Test String' wordWrap:true |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
201 |
PrinterContext print: (PrinterContext class sourceCodeAt:#'print:font:title:wordWrap:') font: (Font family:'Arial' face:'medium' size:8) title: 'Printing Test String' wordWrap: true |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
202 |
" |
2143 | 203 |
|
2235
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
204 |
"Created: / 03-08-2006 / 18:51:53 / fm" |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
205 |
"Modified: / 10-10-2006 / 17:42:06 / cg" |
2143 | 206 |
! |
207 |
||
2235
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
208 |
printCircles: arrayOfPointsAndRadius |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
209 |
"Opens a print dialog and prints the given circles" |
2143 | 210 |
|
211 |
| printerInfo printer | |
|
2235
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
212 |
|
2143 | 213 |
printerInfo := PrintingDialog getPrinterInfo. |
214 |
printerInfo isNil ifTrue:[^self]. |
|
215 |
||
216 |
printer := self fromPrinterInfo: printerInfo. |
|
217 |
[ |
|
2235
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
218 |
printer startPrintJob: 'Circles'. |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
219 |
arrayOfPointsAndRadius |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
220 |
do:[:pointAndRadius | |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
221 |
printer displayCircle:(pointAndRadius at:1) |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
222 |
radius:(pointAndRadius at:2). |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
223 |
]. |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
224 |
printer endPrintJob. |
2143 | 225 |
] forkAt: 3 |
226 |
||
2235
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
227 |
" |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
228 |
PrinterContext printCircles: |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
229 |
(Array with: (Array with: 800@800 with: 600) |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
230 |
with: (Array with: 1500@1500 with: 1000) |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
231 |
with: (Array with: 4000@2500 with: 2000)) |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
232 |
" |
2143 | 233 |
|
2235
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
234 |
"Created: / 07-08-2006 / 11:46:52 / fm" |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
235 |
"Modified: / 10-10-2006 / 17:36:23 / cg" |
2143 | 236 |
! |
237 |
||
2235
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
238 |
printCirclesIn: rectangles |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
239 |
"Opens a print dialog and prints the given circles" |
2146 | 240 |
|
241 |
| printerInfo printer | |
|
2235
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
242 |
|
2146 | 243 |
printerInfo := PrintingDialog getPrinterInfo. |
244 |
printerInfo isNil ifTrue:[^self]. |
|
245 |
||
246 |
printer := self fromPrinterInfo: printerInfo. |
|
247 |
[ |
|
2235
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
248 |
printer startPrintJob: 'Circles In Rectangles'. |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
249 |
rectangles |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
250 |
do:[:rectangle | |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
251 |
printer displayCircleIn: rectangle. |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
252 |
]. |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
253 |
printer endPrintJob. |
2146 | 254 |
] forkAt: 3 |
255 |
||
2235
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
256 |
" |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
257 |
PrinterContext printCirclesIn: |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
258 |
(Array with: (Rectangle left:20 top:20 width:400 height:600) |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
259 |
with: (Rectangle left:40 top:40 width:600 height:400) |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
260 |
) |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
261 |
" |
2146 | 262 |
|
2235
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
263 |
"Created: / 07-08-2006 / 11:48:46 / fm" |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
264 |
"Modified: / 10-10-2006 / 17:38:28 / cg" |
2146 | 265 |
! |
266 |
||
2235
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
267 |
printLines: pairOfPointsArray |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
268 |
"Opens a print dialog and prints the given lines" |
2143 | 269 |
|
270 |
| printerInfo printer | |
|
2235
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
271 |
|
2143 | 272 |
printerInfo := PrintingDialog getPrinterInfo. |
273 |
printerInfo isNil ifTrue:[^self]. |
|
274 |
||
275 |
printer := self fromPrinterInfo: printerInfo. |
|
276 |
[ |
|
2235
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
277 |
printer startPrintJob: 'Lines'. |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
278 |
printer foreground:Color black background:Color white. |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
279 |
pairOfPointsArray |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
280 |
do:[:pairOfPoints | |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
281 |
printer displayLineFrom: (pairOfPoints at:1) to: (pairOfPoints at:2). |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
282 |
]. |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
283 |
printer endPrintJob. |
2143 | 284 |
] forkAt: 3 |
285 |
||
2235
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
286 |
" |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
287 |
PrinterContext printLines: |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
288 |
(Array with: (Array with:10@10 with:100@10) |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
289 |
with: (Array with:10@10 with:35@200)) |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
290 |
" |
2143 | 291 |
|
292 |
"Created: / 07-08-2006 / 12:09:48 / fm" |
|
293 |
"Modified: / 07-08-2006 / 14:11:17 / fm" |
|
2235
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
294 |
"Modified: / 10-10-2006 / 17:38:44 / cg" |
2143 | 295 |
! |
296 |
||
2235
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
297 |
printPolygons: polygons |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
298 |
"Opens a print dialog and prints the given polygons" |
2143 | 299 |
|
300 |
| printerInfo printer | |
|
2235
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
301 |
|
2143 | 302 |
printerInfo := PrintingDialog getPrinterInfo. |
303 |
printerInfo isNil ifTrue:[^self]. |
|
304 |
||
305 |
printer := self fromPrinterInfo: printerInfo. |
|
306 |
[ |
|
2235
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
307 |
printer startPrintJob: 'Polygons'. |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
308 |
printer foreground:Color black background:Color white. |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
309 |
polygons |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
310 |
do:[:aPolygon | |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
311 |
aPolygon displayStrokedOn: printer. |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
312 |
]. |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
313 |
printer endPrintJob. |
2143 | 314 |
] forkAt: 3 |
315 |
||
2235
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
316 |
" |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
317 |
PrinterContext printPolygons: |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
318 |
(Array with: (Polygon vertices:( |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
319 |
Array |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
320 |
with:10@10 |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
321 |
with:60@10 |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
322 |
with:35@60))) |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
323 |
" |
2143 | 324 |
|
2235
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
325 |
"Created: / 07-08-2006 / 12:09:48 / fm" |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
326 |
"Modified: / 07-08-2006 / 14:11:17 / fm" |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
327 |
"Modified: / 10-10-2006 / 17:39:23 / cg" |
2143 | 328 |
! |
329 |
||
2235
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
330 |
printRectangles: rectangles |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
331 |
"Opens a print dialog and prints the given rectangles" |
2147 | 332 |
|
333 |
| printerInfo printer | |
|
2235
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
334 |
|
2147 | 335 |
printerInfo := PrintingDialog getPrinterInfo. |
336 |
printerInfo isNil ifTrue:[^self]. |
|
337 |
||
338 |
printer := self fromPrinterInfo: printerInfo. |
|
339 |
[ |
|
2235
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
340 |
printer startPrintJob: 'Rectangles'. |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
341 |
rectangles |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
342 |
do:[:rectangle | |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
343 |
printer displayRectangleX: rectangle origin x |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
344 |
y: rectangle origin y |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
345 |
width: rectangle width |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
346 |
height: rectangle height. |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
347 |
]. |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
348 |
printer endPrintJob. |
2147 | 349 |
] forkAt: 3 |
350 |
||
2235
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
351 |
" |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
352 |
PrinterContext printRectangles: |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
353 |
(Array with: (Rectangle left:20 top:20 width:400 height:600) |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
354 |
with: (Rectangle left:40 top:40 width:600 height:400) |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
355 |
) |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
356 |
" |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
357 |
|
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
358 |
"Created: / 07-08-2006 / 11:40:48 / fm" |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
359 |
"Modified: / 10-10-2006 / 17:39:51 / cg" |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
360 |
! |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
361 |
|
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
362 |
printStrings: stringAndPositionsArray |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
363 |
"Opens a print dialog and prints the given strings" |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
364 |
|
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
365 |
| printerInfo printer | |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
366 |
|
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
367 |
printerInfo := PrintingDialog getPrinterInfo. |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
368 |
printerInfo isNil ifTrue:[^self]. |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
369 |
|
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
370 |
printer := self fromPrinterInfo: printerInfo. |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
371 |
[ |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
372 |
printer startPrintJob: 'Strings with Position'. |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
373 |
printer foreground:Color black background:Color white. |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
374 |
stringAndPositionsArray |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
375 |
do:[:pairOfPointsAndPosition | |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
376 |
printer displayString:(pairOfPointsAndPosition at: 1) |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
377 |
x:(pairOfPointsAndPosition at: 2) x |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
378 |
y:(pairOfPointsAndPosition at: 2) y |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
379 |
]. |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
380 |
printer endPrintJob. |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
381 |
] forkAt: 3 |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
382 |
|
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
383 |
" |
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
384 |
PrinterContext printStrings: |
2147 | 385 |
(Array with: (Array with:'Testing printing with standart method' with:10@10) |
386 |
with: (Array with:'Another test string to print' with:80@200)) |
|
2235
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
387 |
" |
2147 | 388 |
|
389 |
"Created: / 07-08-2006 / 12:09:48 / fm" |
|
390 |
"Modified: / 07-08-2006 / 14:11:17 / fm" |
|
2235
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
391 |
"Modified: / 10-10-2006 / 17:40:07 / cg" |
2143 | 392 |
! ! |
393 |
||
394 |
!PrinterContext methodsFor:'abort handling'! |
|
395 |
||
396 |
abortPrintJob |
|
397 |
"Abort the current print job." |
|
398 |
||
399 |
abort := true. |
|
400 |
jobid := nil. |
|
401 |
||
402 |
"Modified: / 02-08-2006 / 15:40:26 / fm" |
|
403 |
! |
|
404 |
||
405 |
aborted |
|
406 |
"Answer whether the user aborted from PrintAbortDialog." |
|
407 |
^abort |
|
408 |
||
409 |
"Created: / 27-07-2006 / 10:20:10 / fm" |
|
410 |
! ! |
|
411 |
||
412 |
!PrinterContext methodsFor:'accessing'! |
|
413 |
||
414 |
getCharHeight |
|
415 |
"Private - answer the height of the font selected in the receiver's |
|
416 |
device context." |
|
417 |
||
418 |
| textMetrics | |
|
419 |
textMetrics := Win32OperatingSystem::TextMetricsStructure new. |
|
420 |
( OperatingSystem |
|
421 |
getTextMetrics: gcId "deviceContext" |
|
422 |
lpMetrics: textMetrics "asParameter" ) |
|
423 |
ifFalse: [ ^self error ]. |
|
424 |
^textMetrics tmHeight + textMetrics tmExternalLeading |
|
425 |
||
426 |
"Created: / 02-08-2006 / 17:47:20 / fm" |
|
427 |
"Modified: / 03-08-2006 / 10:09:01 / fm" |
|
428 |
! |
|
429 |
||
430 |
name |
|
431 |
"Answer the receiver's name from the current printerInfo." |
|
432 |
||
433 |
^self printerInfo printerName |
|
434 |
||
435 |
"Modified: / 02-08-2006 / 16:55:03 / fm" |
|
436 |
! |
|
437 |
||
438 |
name: aName |
|
439 |
"Set the receiver's printer name to aName." |
|
440 |
||
441 |
self printerInfo: (self class getPrinterInformation: aName) |
|
442 |
||
443 |
"Created: / 27-07-2006 / 10:33:04 / fm" |
|
444 |
"Modified: / 02-08-2006 / 16:54:46 / fm" |
|
445 |
! |
|
446 |
||
447 |
numberOfColorBitsPerPixel |
|
448 |
||
449 |
^ OperatingSystem getDeviceCaps:gcId index:12 "Bitspixel" |
|
450 |
||
451 |
"Created: / 03-08-2006 / 09:58:18 / fm" |
|
452 |
! |
|
453 |
||
454 |
pixelsPerInchOfScreenHeight |
|
455 |
^ OperatingSystem getDeviceCaps:gcId index:90 "Logpixelsy" |
|
456 |
||
457 |
"Created: / 01-08-2006 / 16:29:16 / fm" |
|
458 |
! |
|
459 |
||
460 |
pixelsPerInchOfScreenWidth |
|
461 |
^ OperatingSystem getDeviceCaps:gcId index:88 "Logpixelsx" |
|
462 |
||
463 |
"Created: / 01-08-2006 / 16:28:34 / fm" |
|
464 |
! |
|
465 |
||
466 |
printerInfo |
|
467 |
"Answer the receiver's name from the current printerInfo." |
|
468 |
||
469 |
^printerInfo |
|
470 |
||
471 |
"Created: / 02-08-2006 / 16:55:17 / fm" |
|
472 |
! |
|
473 |
||
474 |
printerInfo: aPrinterInfo |
|
475 |
"Sets the receiver's printerInfo." |
|
476 |
||
477 |
printerInfo := aPrinterInfo |
|
478 |
||
479 |
"Created: / 02-08-2006 / 16:55:34 / fm" |
|
480 |
"Modified: / 03-08-2006 / 13:11:19 / fm" |
|
481 |
! |
|
482 |
||
483 |
printerInfoWithName: aName |
|
484 |
"Set the receiver's printer name to aName." |
|
485 |
||
486 |
self printerInfo: (self class getPrinterInformation: aName). |
|
487 |
^self |
|
488 |
||
489 |
"Created: / 02-08-2006 / 16:55:52 / fm" |
|
490 |
! |
|
491 |
||
492 |
printerUserFriendlyName |
|
493 |
"Answer the receiver's name from the current printerInfo." |
|
494 |
||
495 |
^self printerInfo userFriendlyName |
|
496 |
||
497 |
"Created: / 03-08-2006 / 12:55:57 / fm" |
|
498 |
! ! |
|
499 |
||
500 |
!PrinterContext methodsFor:'initialization & release'! |
|
501 |
||
502 |
buildPrinter |
|
503 |
"Private - create all the operating system resources needed." |
|
504 |
self |
|
505 |
createDC; |
|
506 |
initExtent |
|
507 |
||
508 |
"Created: / 27-07-2006 / 10:20:36 / fm" |
|
509 |
"Modified: / 01-08-2006 / 15:57:49 / fm" |
|
510 |
! |
|
511 |
||
512 |
createDC |
|
513 |
"Private - Create a device context for the receiver" |
|
514 |
||
515 |
gcId := printerInfo createDC |
|
516 |
||
517 |
"/ | printerInfo driverNm mediumNm deviceNm hPrinter driverData| |
|
518 |
"/ printerInfo := self class getPrinterInformation: self name. |
|
519 |
"/ driverNm := printerInfo driverName. |
|
520 |
"/ mediumNm := printerInfo medium. |
|
521 |
"/ deviceNm := printerInfo printerName. |
|
522 |
"/ |
|
523 |
"/ hPrinter := OperatingSystem openPrinter:deviceNm. |
|
524 |
"/ driverData := OperatingSystem getDocumentProperties:nil hPrinter:hPrinter pDeviceName:deviceNm. |
|
525 |
"/ Win32OperatingSystem primClosePrinter:hPrinter. |
|
526 |
"/ |
|
527 |
"/ "deviceContext" gcId := OperatingSystem createPrinterDC:driverNm device:deviceNm output:mediumNm initData:driverData. |
|
528 |
||
529 |
"/ ( deviceContext := GDILibrary |
|
530 |
"/ createDC: driverName asParameter |
|
531 |
"/ deviceName: deviceName asParameter |
|
532 |
"/ output: printerPort asParameter |
|
533 |
"/ initData: nil ) = 0 |
|
534 |
"/ ifTrue: [ ^self osError ]. |
|
535 |
||
536 |
"Created: / 27-07-2006 / 10:21:05 / fm" |
|
537 |
"Modified: / 02-08-2006 / 17:30:47 / fm" |
|
538 |
! |
|
539 |
||
540 |
initExtent |
|
541 |
"Private - init the width and height of GraphicsTool for the receiver." |
|
542 |
||
543 |
device |
|
544 |
width:self printerWidthArea; |
|
545 |
height:self printerHeightArea |
|
546 |
||
547 |
"Modified: / 01-08-2006 / 16:14:49 / fm" |
|
548 |
! |
|
549 |
||
550 |
printerHeightArea |
|
551 |
^ (OperatingSystem getDeviceCaps:gcId index:10 "Vertres") |
|
552 |
||
553 |
"Created: / 01-08-2006 / 16:14:49 / fm" |
|
554 |
! |
|
555 |
||
556 |
printerWidthArea |
|
557 |
^ OperatingSystem getDeviceCaps:gcId "deviceContext" index:8 "Horzres" |
|
558 |
||
559 |
"Created: / 01-08-2006 / 16:14:08 / fm" |
|
560 |
! ! |
|
561 |
||
562 |
!PrinterContext methodsFor:'printing'! |
|
563 |
||
564 |
print: aString |
|
565 |
font: aFont |
|
566 |
title: aTitle |
|
567 |
wordWrap: wordWrapBoolean |
|
568 |
marginsRect: aMarginsRect |
|
569 |
"Answer the receiver. Output the receiver string to |
|
570 |
the printer using aFont. A Print abort dialog box will be opened |
|
571 |
with aTitle. If collateBoolean is true, collate output, otherwise |
|
572 |
do not. Print copiesInteger copies of the specified string. If |
|
573 |
wordWrapBoolean is true, word wrap the lines, otherwise do not. |
|
574 |
Left, top, right & bottom margins are specified in inches in |
|
575 |
aMarginsRect." |
|
576 |
| lines linesPerPage totalPage marginsRect firstPage charHeight abortDialog | |
|
577 |
||
578 |
jobid isNil |
|
579 |
ifTrue: [ self startPrintJob: aTitle ]. |
|
580 |
abortDialog := PrintAbortDialog new open: aTitle printer: self. |
|
2147 | 581 |
self font: aFont. |
2143 | 582 |
marginsRect := self marginsRectangleFor: aMarginsRect. |
2147 | 583 |
lines := self asArrayOfStringLines: aString in: marginsRect wordWrap: wordWrapBoolean. |
2143 | 584 |
charHeight := self getCharHeight. |
585 |
linesPerPage := marginsRect bottom - marginsRect top // charHeight. |
|
586 |
totalPage := lines size + linesPerPage - 1 // linesPerPage. |
|
587 |
firstPage := true. |
|
588 |
||
589 |
"/ collateBoolean |
|
590 |
"/ ifTrue: [ |
|
591 |
"/ copiesInteger timesRepeat: [ |
|
592 |
1 to: totalPage do: [ :page | |
|
593 |
abort ifTrue: [^self]. |
|
594 |
firstPage ifFalse: [ self formFeed ]. |
|
595 |
abortDialog updatePrintingPageInfo: 'Page ', page printString, '/', totalPage printString. |
|
596 |
"/ self device font: printerFont. |
|
2147 | 597 |
self font: aFont. |
2143 | 598 |
self printPage: page in: marginsRect lines: lines linesPerPage: linesPerPage. |
599 |
firstPage := false ]. |
|
600 |
||
601 |
"/ ] |
|
602 |
"/ ] ifFalse: [ |
|
603 |
"/ 1 to: totalPage do: [ :page | |
|
604 |
"/ copiesInteger timesRepeat: [ |
|
605 |
"/ abort ifTrue: [ ^self endPrintJob ]. |
|
606 |
"/ firstPage ifFalse: [ self formFeed ]. |
|
607 |
"/ self device font: printerFont. |
|
608 |
"/ self printPage: page in: marginsRect lines: lines linesPerPage: linesPerPage. |
|
609 |
"/ firstPage := false |
|
610 |
"/ ] |
|
611 |
"/ ] |
|
612 |
"/ ]. |
|
613 |
||
614 |
jobid notNil |
|
615 |
ifTrue: [ self endPrintJob. |
|
616 |
abortDialog close.]. |
|
617 |
||
618 |
"/ abort ifFalse: [ abortDialog close ] |
|
619 |
||
620 |
"Created: / 03-08-2006 / 16:13:33 / fm" |
|
621 |
"Modified: / 04-08-2006 / 13:40:02 / fm" |
|
622 |
! |
|
623 |
||
624 |
print: aString |
|
625 |
pageHeader: aString2 |
|
626 |
font: aFont |
|
627 |
title: aTitle |
|
628 |
wordWrap: wordWrapBoolean |
|
629 |
marginsRect: aMarginsRect |
|
630 |
||
631 |
"Private - Answer the receiver. Output the receiver string to |
|
632 |
the printer using aFont. A Print abort dialog box will be opened |
|
633 |
with aTitle. If collateBoolean is true, collate output, otherwise |
|
634 |
do not. Print copiesInteger copies of the specified string. If |
|
635 |
wordWrapBoolean is true, word wrap the lines, otherwise do not. |
|
636 |
Left, top, right & bottom margins are specified in inches in |
|
637 |
aMarginsRect. |
|
638 |
Mg: Erweitert um pageHeader" |
|
639 |
"Changed by K3/EES5-Mg, 08.01.96" |
|
640 |
||
641 |
| lines linesPerPage totalPage marginsRect firstPage charHeight printerFont headerLines| |
|
642 |
||
2147 | 643 |
self font: aFont. |
2143 | 644 |
charHeight := self getCharHeight. |
645 |
marginsRect := self marginsRectangleFor: aMarginsRect. |
|
2147 | 646 |
lines := self asArrayOfStringLines: aString in: marginsRect wordWrap: wordWrapBoolean. |
647 |
headerLines := self asArrayOfStringLines: aString2 in: marginsRect wordWrap: wordWrapBoolean. |
|
2143 | 648 |
linesPerPage := marginsRect bottom - marginsRect top // charHeight. |
649 |
||
650 |
linesPerPage > headerLines size |
|
651 |
ifFalse: |
|
652 |
[Dialog information: 'Der Dokumentenkopf ist zu groß; wird ignoriert!!'. |
|
653 |
headerLines := #(). |
|
654 |
] |
|
655 |
ifTrue: [linesPerPage := linesPerPage - headerLines size]. |
|
656 |
totalPage := lines size + linesPerPage - 1 // linesPerPage. |
|
657 |
firstPage := true. |
|
658 |
||
659 |
"/ collateBoolean |
|
660 |
"/ ifTrue: [ |
|
661 |
"/ copiesInteger timesRepeat: [ |
|
662 |
||
663 |
1 to: totalPage do: [ :page | |
|
664 |
abort ifTrue: [ ^self]. |
|
665 |
firstPage ifFalse: [ self formFeed ]. |
|
666 |
self font: printerFont. |
|
667 |
self printPage: page in: marginsRect lines: lines headerLines: headerLines linesPerPage: linesPerPage. |
|
668 |
firstPage := false |
|
669 |
] |
|
670 |
||
671 |
"/ ] |
|
672 |
"/ ] ifFalse: [ |
|
673 |
"/ 1 to: totalPage do: [ :page | |
|
674 |
"/ copiesInteger timesRepeat: [ |
|
675 |
"/ abort ifTrue: [ ^self endPrintJob ]. |
|
676 |
"/ firstPage ifFalse: [ self formFeed ]. |
|
677 |
"/ self device font: printerFont. |
|
678 |
"/ self printPage: page in: marginsRect lines: lines headerLines: headerLines linesPerPage: linesPerPage. |
|
679 |
"/ firstPage := false |
|
680 |
"/ ] |
|
681 |
"/ ] |
|
682 |
"/ ]. |
|
683 |
||
684 |
"Created: / 03-08-2006 / 16:14:10 / fm" |
|
685 |
! ! |
|
686 |
||
2147 | 687 |
!PrinterContext methodsFor:'printing process'! |
2143 | 688 |
|
689 |
endPage |
|
690 |
"Informs device that we are finished writing to a page." |
|
691 |
( OperatingSystem endPage: gcId ) > 0 |
|
692 |
ifFalse: [ self error ] |
|
693 |
||
694 |
"Created: / 27-07-2006 / 18:20:48 / fm" |
|
695 |
"Modified: / 01-08-2006 / 16:01:34 / fm" |
|
696 |
! |
|
697 |
||
698 |
endPrintJob |
|
699 |
||
700 |
"End the print job. Everything drawn between startPrintJob |
|
701 |
and endPrintJob will become one entry in the print queue." |
|
702 |
"Changed by K3EES5-Mg, 19.09.97" |
|
703 |
||
704 |
| result | |
|
705 |
self endPage. |
|
706 |
result := OperatingSystem endDoc: gcId "deviceContext". |
|
707 |
"graphicsTool" device close "deleteDC". |
|
708 |
"deviceContext" gcId := nil. |
|
709 |
jobid := nil. |
|
710 |
result >= 0 "> geändert in >=: Mg 22.6.95" |
|
711 |
ifFalse: [ ^self error "osError" ] |
|
712 |
||
713 |
"Created: / 27-07-2006 / 18:21:04 / fm" |
|
714 |
"Modified: / 01-08-2006 / 16:01:38 / fm" |
|
715 |
! |
|
716 |
||
717 |
formFeed |
|
718 |
"Send a form feed to the printer." |
|
719 |
self |
|
720 |
endPage; |
|
721 |
startPage |
|
722 |
||
723 |
"Created: / 27-07-2006 / 18:25:40 / fm" |
|
724 |
! |
|
725 |
||
726 |
startPage |
|
727 |
"Starts a page." |
|
728 |
( OperatingSystem startPage: gcId ) > 0 |
|
729 |
ifFalse: [ ^self error "osError" ]. |
|
730 |
||
731 |
"Created: / 27-07-2006 / 18:25:55 / fm" |
|
732 |
"Modified: / 28-07-2006 / 18:19:04 / fm" |
|
733 |
! |
|
734 |
||
735 |
startPrintJob |
|
736 |
"Start a print job. Everything drawn between startPrintJob |
|
737 |
and endPrintJob will become one entry in the print queue." |
|
738 |
self startPrintJob: nil |
|
739 |
||
740 |
"Created: / 27-07-2006 / 18:18:52 / fm" |
|
741 |
! |
|
742 |
||
743 |
startPrintJob: aString |
|
744 |
||
745 |
"Start a print job, using aString as the job title; everything |
|
746 |
drawn between startPrintJob and endPrintJob will become |
|
747 |
one entry in the print queue. |
|
748 |
||
749 |
Mg: Bei SpUserabort (bei Drucken in Datei) wird abort auf true gesetzt |
|
750 |
und SpUserabort zurückgegeben. |
|
751 |
" |
|
752 |
"Changed by K3/EES5-Mg, 21.07.97" |
|
753 |
"Changed by K3EES5-Mg, 19.09.97" |
|
754 |
||
755 |
^self startPrintJob: aString fileName: nil |
|
756 |
||
757 |
"Created: / 27-07-2006 / 18:19:09 / fm" |
|
758 |
! |
|
759 |
||
760 |
startPrintJob: aString fileName: aFileName |
|
761 |
||
762 |
"Start a print job, using aString as the job title; everything |
|
763 |
drawn between startPrintJob and endPrintJob will become |
|
764 |
one entry in the print queue." |
|
765 |
"Changed by K3/EES5-Mg, 21.07.97" |
|
766 |
"Changed by K3EES5-Mg, 19.09.97" |
|
767 |
"Changed by GS/EEZ3-Vr, 15.03.02" |
|
768 |
||
769 |
| docInfoStruct nameAddress title fileNameAddress | |
|
770 |
||
771 |
gcId "deviceContext" isNil ifTrue: [ self buildPrinter ]. |
|
772 |
abort := false. |
|
773 |
"self setAbortProc." |
|
774 |
title := aString isNil ifTrue: [ 'Smalltalk/X' "WindowLabelPrefix" ] ifFalse: [ aString ]. |
|
775 |
||
776 |
nameAddress := title asExternalBytes unprotectFromGC. |
|
777 |
"/ nameAddress := ExternalAddress copyToNonSmalltalkMemory: title. |
|
778 |
aFileName isNil ifFalse: [fileNameAddress := aFileName pathName asExternalBytes unprotectFromGC]. |
|
779 |
"/ aFileName isNil ifFalse: [fileNameAddress := ExternalAddress copyToNonSmalltalkMemory: aFileName]. |
|
780 |
||
781 |
docInfoStruct := Win32OperatingSystem::DocInfoStructure new "some value". |
|
782 |
docInfoStruct cbSize: docInfoStruct sizeInBytes; |
|
783 |
lpszDocName: nameAddress address. |
|
784 |
"/ ( docInfoStruct := SelfDefinedStructure named: 'DOCINFO' ) |
|
785 |
"/ cbSize: docInfoStruct sizeInBytes; |
|
786 |
"/ lpszDocName: nameAddress "asParameter". |
|
787 |
||
788 |
fileNameAddress isNil ifFalse:[docInfoStruct lpszOutput: fileNameAddress address"asParameter"]. |
|
789 |
||
790 |
jobid := OperatingSystem startDoc: gcId "deviceContext" |
|
791 |
docInfo: docInfoStruct "asParameter". |
|
792 |
"/ nameAddress free. |
|
793 |
"/ fileNameAddress isNil ifFalse: [fileNameAddress free]. |
|
794 |
||
795 |
jobid > 0 |
|
796 |
ifFalse: [jobid = -1 |
|
797 |
ifTrue: [abort := true. ^nil]. |
|
798 |
^self error "osError" ]. |
|
799 |
self startPage |
|
800 |
||
801 |
"Created: / 27-07-2006 / 18:19:31 / fm" |
|
802 |
"Modified: / 03-08-2006 / 15:11:19 / fm" |
|
2147 | 803 |
! ! |
804 |
||
805 |
!PrinterContext methodsFor:'queries'! |
|
806 |
||
807 |
supportsColor |
|
808 |
||
809 |
"Changed by K3/EES5-Vo, 11.03.98" |
|
810 |
"Changed by GS-EC/EES3-Vo, 06.10.05" |
|
811 |
||
812 |
"/ | retVal info | |
|
813 |
"/ |
|
814 |
"/ info := (self class getPrinterInformation: self name) asUppercase. |
|
815 |
"/ (info includesSubstring: ',PSCRIPT,') |
|
816 |
"/ ifTrue: [ |
|
817 |
"/ retVal := (DAPASX::DapasSystemInfo getYesNoInfoApp: 'Printer' profile: 'PostScriptBlackWhite') not. |
|
818 |
"/ ] |
|
819 |
"/ ifFalse: [ |
|
820 |
"/ retVal := (info includesSubstring: 'PDF') |
|
821 |
"/ ifTrue: [true] |
|
822 |
"/ ifFalse: [self numberOfColorBitsPerPixel > 1]. |
|
823 |
"/ ]. |
|
824 |
"/ |
|
825 |
"/ ^retVal |
|
826 |
||
827 |
"Created: / 03-08-2006 / 09:55:26 / fm" |
|
828 |
"Modified: / 04-08-2006 / 13:20:40 / fm" |
|
829 |
! |
|
830 |
||
831 |
supportsGraphics |
|
832 |
||
833 |
"Private & DEFAULT!!." |
|
834 |
"Changed by K3/EES5-Mg, 26.01.96" |
|
835 |
||
836 |
^(OperatingSystem getDeviceCaps: gcId asParameter index: 2 "Technology") ~= 4 |
|
837 |
||
838 |
"Created: / 03-08-2006 / 10:07:43 / fm" |
|
839 |
! ! |
|
840 |
||
841 |
!PrinterContext methodsFor:'text printing'! |
|
842 |
||
843 |
asArrayOfStringLines: aString in: aRectangle wordWrap: wordWrapBoolean |
|
844 |
"Private - convert aString into an array of lines; if wordWrapBoolean |
|
845 |
is true, also perform word wrapping on the lines, within aRectangle." |
|
846 |
| line lines stream x0 x1 partialLine leftMargin rightMargin partialLineWidth index | |
|
847 |
stream := ReadStream on: aString. |
|
848 |
lines := OrderedCollection new. |
|
849 |
wordWrapBoolean ifTrue: [ |
|
850 |
leftMargin := aRectangle left. |
|
851 |
rightMargin := aRectangle right ]. |
|
852 |
[ stream atEnd ] whileFalse: [ |
|
853 |
line := stream nextLine. |
|
854 |
wordWrapBoolean |
|
855 |
ifFalse: [ lines add: line ] |
|
856 |
ifTrue: [ |
|
857 |
x0 := x1 := 1. |
|
858 |
1 to: line size do: [ :i | |
|
859 |
( ( line at: i ) = Character space "32" and: [ (partialLine := line copyFrom: x0 to: i) trimBlanks notEmpty ] ) |
|
860 |
ifTrue: [ |
|
861 |
partialLineWidth := self stringWidthOf: partialLine. |
|
862 |
( leftMargin + partialLineWidth ) > rightMargin |
|
863 |
ifTrue: [ |
|
864 |
partialLine := line copyFrom: x0 to: x1. |
|
865 |
lines add: partialLine. |
|
866 |
x0 := x1 + 1 ] |
|
867 |
ifFalse: [ x1 := i ] ]. |
|
868 |
index := i |
|
869 |
]. |
|
870 |
line isEmpty |
|
871 |
ifTrue: [ lines add: line ] |
|
872 |
ifFalse: [ |
|
873 |
partialLine := line copyFrom: x0 to: index. |
|
874 |
partialLineWidth := self stringWidthOf: partialLine. |
|
875 |
( leftMargin + partialLineWidth ) > rightMargin |
|
876 |
ifTrue: [ |
|
877 |
partialLine := line copyFrom: x0 to: x1. |
|
878 |
lines add: partialLine. |
|
879 |
partialLine := line copyFrom: x1 + 1 to: index |
|
880 |
]. |
|
881 |
lines add: partialLine |
|
882 |
] |
|
883 |
] |
|
884 |
]. |
|
885 |
^lines asArray |
|
886 |
||
887 |
"Created: / 02-08-2006 / 17:56:51 / fm" |
|
888 |
"Modified: / 04-08-2006 / 13:39:50 / fm" |
|
889 |
! |
|
890 |
||
891 |
displayStringLines: anIndexedCollection from: startIndex to: endIndex in: aRectangle |
|
892 |
"Private - display Strings in anIndexedCollection starting at startIndex and |
|
893 |
ending at endIndex, clipped within the bounds of aRectangle." |
|
894 |
| charHeight ta region ascent| |
|
895 |
charHeight := self getCharHeight. |
|
896 |
ascent := self font ascentOn: self device. |
|
897 |
startIndex to: endIndex do: [ :i | |
|
898 |
|lineToPrint| |
|
899 |
lineToPrint := ( anIndexedCollection at: i ). |
|
900 |
self device |
|
901 |
displayString: lineToPrint |
|
902 |
from:1 |
|
903 |
to: lineToPrint size |
|
904 |
x: aRectangle left |
|
905 |
y: (aRectangle top + ( i - startIndex * charHeight ) ) |
|
906 |
in:nil |
|
907 |
with: gcId |
|
908 |
opaque:false |
|
909 |
fontAscent: ascent. |
|
910 |
]. |
|
911 |
||
912 |
"/ region := self setClipRect: aRectangle. |
|
913 |
"/ ta := self getTextAlign. |
|
914 |
"/ self setTextAlign: TaTop. |
|
915 |
"/ startIndex to: endIndex do: [ :i | |
|
916 |
"/ self |
|
917 |
"/ displayText: ( anIndexedCollection at: i ) |
|
918 |
"/ at: aRectangle left @ ( aRectangle top + ( i - startIndex * charHeight ) ) ]. |
|
919 |
"/ self setTextAlign: ta. |
|
920 |
"/ self destroyRegion: region |
|
921 |
||
922 |
"Created: / 03-08-2006 / 11:37:52 / fm" |
|
923 |
"Modified: / 03-08-2006 / 12:38:43 / fm" |
|
924 |
! |
|
925 |
||
926 |
displayStringLines: anIndexedCollection in: aRectangle |
|
927 |
"Private - display anIndexedCollection of Strings clipped within |
|
928 |
the bounds of aRectangle." |
|
929 |
self |
|
930 |
displayStringLines: anIndexedCollection |
|
931 |
from: 1 |
|
932 |
to: anIndexedCollection size |
|
933 |
in: aRectangle |
|
934 |
||
935 |
"Created: / 03-08-2006 / 16:03:07 / fm" |
|
936 |
! |
|
937 |
||
938 |
marginsRectangleFor:aRectangle |
|
939 |
"Private - Answer a Rectangle defining margins based on aRectangle. |
|
940 |
Units for aRectangle are in inches, returned margins rectangle is |
|
941 |
in device units (pixels)." |
|
942 |
||
943 |
|left top right bottom pixelsPerInchX pixelsPerInchY horzRes vertRes inset rectangle| |
|
944 |
pixelsPerInchX := self pixelsPerInchOfScreenWidth. |
|
945 |
pixelsPerInchY := self pixelsPerInchOfScreenHeight. |
|
946 |
aRectangle isNil ifTrue:[ |
|
947 |
horzRes := self printerWidthArea. |
|
948 |
vertRes := self printerHeightArea. |
|
949 |
inset := self class defaultMargins. |
|
950 |
left := (inset x * pixelsPerInchX) asInteger. |
|
951 |
top := (inset y * pixelsPerInchY) asInteger. |
|
952 |
right := horzRes - (inset x * pixelsPerInchX) asInteger. |
|
953 |
bottom := vertRes - (inset y * pixelsPerInchY) asInteger |
|
954 |
] ifFalse:[ |
|
955 |
left := (aRectangle left * pixelsPerInchX) asInteger. |
|
956 |
top := (aRectangle top * pixelsPerInchY) asInteger. |
|
957 |
right := (aRectangle right * pixelsPerInchX) asInteger. |
|
958 |
bottom := (aRectangle bottom * pixelsPerInchY) asInteger |
|
959 |
]. |
|
960 |
rectangle := left @ top extent: right @ bottom. |
|
961 |
^ rectangle |
|
962 |
||
963 |
"Created: / 27-07-2006 / 18:22:57 / fm" |
|
964 |
"Modified: / 04-08-2006 / 13:39:45 / fm" |
|
965 |
! |
|
966 |
||
967 |
printPage: pageIndex in: aRectangle lines: lines headerLines: headerLines linesPerPage: linesPerPage |
|
968 |
||
969 |
"Private - print page # pageIndex from lines, assuming |
|
970 |
the given number of linesPerPage." |
|
971 |
"Changed by K3/EES5-Mg, 30.07.97" |
|
972 |
||
973 |
| firstLine lastLine l indexString p cHeight rect hLines| |
|
974 |
firstLine := ( pageIndex - 1 ) * linesPerPage + 1. |
|
975 |
lastLine := ( firstLine + linesPerPage - 1 ) min: lines size. |
|
976 |
||
977 |
rect := aRectangle deepCopy. |
|
978 |
hLines := headerLines deepCopy. |
|
979 |
headerLines size > 0 ifTrue: |
|
980 |
[l := hLines first. |
|
981 |
(p := l indexOfString: '#P') = 0 ifFalse: |
|
982 |
[indexString := pageIndex printString,' '. |
|
983 |
"l replaceFrom: p to: p + indexString size - 1 with: indexString startingAt: 1." |
|
984 |
l := (l copyFrom: 1 to: p - 1),indexString,(l copyFrom: p + 2 to: l size). |
|
985 |
hLines at: 1 put: l. |
|
986 |
]. |
|
987 |
cHeight := self getCharHeight. |
|
988 |
rect top: rect top + (hLines size * cHeight). |
|
989 |
]. |
|
990 |
||
991 |
self displayStringLines: hLines in: aRectangle. |
|
992 |
self displayStringLines: lines from: firstLine to: lastLine in: rect. |
|
993 |
||
994 |
"Created: / 27-07-2006 / 18:28:00 / fm" |
|
995 |
"Modified: / 03-08-2006 / 16:03:15 / fm" |
|
996 |
! |
|
997 |
||
998 |
printPage: pageIndex in: aRectangle lines: lines linesPerPage: linesPerPage |
|
999 |
"Private - print page # pageIndex from lines, assuming |
|
1000 |
the given number of linesPerPage." |
|
1001 |
| firstLine lastLine | |
|
1002 |
firstLine := ( pageIndex - 1 ) * linesPerPage + 1. |
|
1003 |
lastLine := ( firstLine + linesPerPage - 1 ) min: lines size. |
|
1004 |
self displayStringLines: lines from: firstLine to: lastLine in: aRectangle |
|
1005 |
||
1006 |
"Created: / 27-07-2006 / 18:24:59 / fm" |
|
1007 |
"Modified: / 03-08-2006 / 12:47:24 / fm" |
|
2143 | 1008 |
! |
1009 |
||
1010 |
stringWidthOf: aString |
|
1011 |
"Return the width of aString |
|
1012 |
when written using the current font." |
|
1013 |
^self |
|
1014 |
stringWidthOf: aString |
|
1015 |
at: aString size. |
|
1016 |
||
1017 |
"Modified: / 03-08-2006 / 10:18:23 / fm" |
|
1018 |
! |
|
1019 |
||
1020 |
stringWidthOf: aString at: index |
|
1021 |
"Return the width of aString up to index |
|
1022 |
when written using the current font; expand tabs out |
|
1023 |
to 4 spaces for calculations" |
|
1024 |
| answer str size spaceWidth| |
|
1025 |
index <= 0 ifTrue: [^0]. |
|
1026 |
str := index >= aString size |
|
1027 |
ifTrue:[aString] |
|
1028 |
ifFalse:[aString copyFrom: 1 to: index]. |
|
1029 |
true "self font isNil" |
|
1030 |
ifTrue: [ "if font not set yet, calculate based on default font" |
|
1031 |
"/ extString := str asExternalString. |
|
1032 |
size := Win32OperatingSystem::WinPointStructure new. |
|
1033 |
( OperatingSystem |
|
1034 |
getTextExtentPoint: gcId "self handle" |
|
1035 |
string: str |
|
1036 |
size: size) |
|
1037 |
ifFalse: [ ^self error ]. |
|
1038 |
answer := size x. |
|
1039 |
#TODO. |
|
1040 |
] ifFalse: [ answer := self font widthOf: str on: self device "self handle" ]. |
|
1041 |
index > aString size ifTrue: [ |
|
1042 |
spaceWidth:= self font widthOf: Character space on: self device. |
|
1043 |
answer := answer + (index - aString size * spaceWidth)]. |
|
1044 |
^answer. |
|
1045 |
||
1046 |
"Created: / 03-08-2006 / 10:27:20 / fm" |
|
1047 |
"Modified: / 04-08-2006 / 12:27:26 / fm" |
|
1048 |
! ! |
|
1049 |
||
1050 |
!PrinterContext class methodsFor:'documentation'! |
|
1051 |
||
1052 |
version |
|
2235
0df6bda4b353
pretty printed & added some documentation and examples
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1053 |
^ '$Header: /cvs/stx/stx/libview2/PrinterContext.st,v 1.5 2006-10-10 15:55:30 cg Exp $' |
2143 | 1054 |
! ! |