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