author | fm |
Thu, 30 Nov 2006 14:26:37 +0100 | |
changeset 2274 | c0c247557f01 |
parent 2273 | 14e357a2c73f |
child 2275 | 6c2f8ba6b301 |
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 |
|
2272 | 15 |
instanceVariableNames:'name abort jobid printerInfo textAlign' |
2143 | 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 |
||
2272 | 411 |
container |
412 |
||
413 |
^self |
|
414 |
! |
|
415 |
||
2143 | 416 |
getCharHeight |
2236 | 417 |
"Private - answer the height of the font selected in the receiver's |
418 |
device context." |
|
419 |
||
2272 | 420 |
|textMetrics answer| |
2143 | 421 |
|
2272 | 422 |
|
2143 | 423 |
textMetrics := Win32OperatingSystem::TextMetricsStructure new. |
2272 | 424 |
"/ (OperatingSystem getTextMetrics:gcId lpMetrics:textMetrics) ifFalse:[ ^ self error ]. |
425 |
"/ Transcript showCR: 'CHAR HEIGHT PRIM ******* ', ' ', (textMetrics tmHeight + textMetrics tmExternalLeading) printString. |
|
426 |
"/ Transcript showCR: 'CHAR HEIGHT DEVICE ***** ', ' ', (self font heightOf:'PQWEXCZ' on:self device) printString. |
|
427 |
answer := (self font heightOf:'PQWEXCZ' on:self device). |
|
428 |
"/ answer := textMetrics tmHeight + textMetrics tmExternalLeading. |
|
429 |
^answer |
|
2143 | 430 |
|
431 |
"Created: / 02-08-2006 / 17:47:20 / fm" |
|
432 |
"Modified: / 03-08-2006 / 10:09:01 / fm" |
|
2236 | 433 |
"Modified: / 10-10-2006 / 18:15:17 / cg" |
2143 | 434 |
! |
435 |
||
2272 | 436 |
horizontalPixelsPerMeter |
437 |
"Answer horizontal pixels per meter |
|
438 |
on the screen." |
|
439 |
^self pixelsPerInchOfScreenWidth * 39.3700787 |
|
440 |
! |
|
441 |
||
2236 | 442 |
name |
443 |
"Answer the receiver's name from the current printerInfo." |
|
444 |
||
445 |
^ self printerInfo printerName |
|
2143 | 446 |
|
447 |
"Modified: / 02-08-2006 / 16:55:03 / fm" |
|
2236 | 448 |
"Modified: / 10-10-2006 / 18:15:33 / cg" |
2143 | 449 |
! |
450 |
||
2236 | 451 |
name:aName |
452 |
"Set the receiver's printer name to aName." |
|
453 |
||
454 |
self printerInfo:(self class getPrinterInformation:aName) |
|
2143 | 455 |
|
2236 | 456 |
"Modified: / 10-10-2006 / 18:15:36 / cg" |
2143 | 457 |
! |
458 |
||
459 |
numberOfColorBitsPerPixel |
|
460 |
^ OperatingSystem getDeviceCaps:gcId index:12 "Bitspixel" |
|
461 |
||
462 |
"Created: / 03-08-2006 / 09:58:18 / fm" |
|
2236 | 463 |
"Modified: / 10-10-2006 / 18:15:40 / cg" |
2143 | 464 |
! |
465 |
||
2272 | 466 |
physicalOffsetX |
467 |
||
468 |
"Papierhöhe in Pixels" |
|
469 |
"Changed by K3/EEZ3-Mg, 02.03.99" |
|
470 |
||
471 |
^ OperatingSystem getDeviceCaps:gcId index:112 "PhysicalOffsetX" |
|
472 |
||
473 |
"Created: / 01-08-2006 / 16:28:34 / fm" |
|
474 |
! |
|
475 |
||
476 |
physicalOffsetY |
|
477 |
||
478 |
"Papierhöhe in Pixels" |
|
479 |
"Changed by K3/EEZ3-Mg, 02.03.99" |
|
480 |
||
481 |
^ OperatingSystem getDeviceCaps:gcId index:113 "PhysicalOffsetY" |
|
482 |
||
483 |
"Created: / 01-08-2006 / 16:28:34 / fm" |
|
484 |
! |
|
485 |
||
2143 | 486 |
pixelsPerInchOfScreenHeight |
487 |
^ OperatingSystem getDeviceCaps:gcId index:90 "Logpixelsy" |
|
488 |
||
489 |
"Created: / 01-08-2006 / 16:29:16 / fm" |
|
490 |
! |
|
491 |
||
492 |
pixelsPerInchOfScreenWidth |
|
493 |
^ OperatingSystem getDeviceCaps:gcId index:88 "Logpixelsx" |
|
494 |
||
495 |
"Created: / 01-08-2006 / 16:28:34 / fm" |
|
496 |
! |
|
497 |
||
2272 | 498 |
printerHeightArea |
499 |
^ (OperatingSystem getDeviceCaps:gcId index:10) |
|
500 |
||
501 |
"Modified: / 10-10-2006 / 18:18:31 / cg" |
|
502 |
! |
|
503 |
||
2143 | 504 |
printerInfo |
2236 | 505 |
"Answer the receiver's name from the current printerInfo." |
506 |
||
507 |
^ printerInfo |
|
2143 | 508 |
|
509 |
"Created: / 02-08-2006 / 16:55:17 / fm" |
|
2236 | 510 |
"Modified: / 10-10-2006 / 18:18:34 / cg" |
2143 | 511 |
! |
512 |
||
2236 | 513 |
printerInfo:aPrinterInfo |
514 |
"Sets the receiver's printerInfo." |
|
515 |
||
2143 | 516 |
printerInfo := aPrinterInfo |
517 |
||
518 |
"Created: / 02-08-2006 / 16:55:34 / fm" |
|
519 |
"Modified: / 03-08-2006 / 13:11:19 / fm" |
|
2236 | 520 |
"Modified: / 10-10-2006 / 18:18:37 / cg" |
2143 | 521 |
! |
522 |
||
2236 | 523 |
printerInfoWithName:aName |
524 |
"Set the receiver's printer name to aName." |
|
525 |
||
526 |
self printerInfo:(self class getPrinterInformation:aName). |
|
527 |
^ self |
|
2143 | 528 |
|
529 |
"Created: / 02-08-2006 / 16:55:52 / fm" |
|
2236 | 530 |
"Modified: / 10-10-2006 / 18:18:41 / cg" |
2143 | 531 |
! |
532 |
||
2272 | 533 |
printerPhysicalHeight |
534 |
^ OperatingSystem getDeviceCaps:gcId "deviceContext" index:111 "PhysicalHeight" |
|
535 |
||
536 |
"Created: / 01-08-2006 / 16:14:08 / fm" |
|
537 |
! |
|
538 |
||
539 |
printerPhysicalWidth |
|
540 |
^ OperatingSystem getDeviceCaps:gcId "deviceContext" index:110 "PhysicalWidth" |
|
541 |
||
542 |
"Created: / 01-08-2006 / 16:14:08 / fm" |
|
543 |
! |
|
544 |
||
2143 | 545 |
printerUserFriendlyName |
2236 | 546 |
"Answer the receiver's name from the current printerInfo." |
547 |
||
548 |
^ self printerInfo userFriendlyName |
|
2143 | 549 |
|
550 |
"Created: / 03-08-2006 / 12:55:57 / fm" |
|
2236 | 551 |
"Modified: / 10-10-2006 / 18:18:55 / cg" |
2272 | 552 |
! |
553 |
||
554 |
printerWidthArea |
|
555 |
^ OperatingSystem getDeviceCaps:gcId "deviceContext" index:8 "Horzres" |
|
556 |
||
557 |
"Created: / 01-08-2006 / 16:14:08 / fm" |
|
558 |
! |
|
559 |
||
2273 | 560 |
setPrinterFont:aFont |
561 |
||
562 |
self font: aFont |
|
563 |
||
564 |
"Created: / 27-11-2006 / 14:50:55 / User" |
|
565 |
! |
|
566 |
||
2272 | 567 |
setTextAlign:aNumber |
568 |
||
569 |
"/ OperatingSystem setTextAlign: aNumber to: gcId. |
|
570 |
textAlign :=aNumber. |
|
571 |
! |
|
572 |
||
573 |
setViewportOrg: aPoint |
|
574 |
||
575 |
^ OperatingSystem |
|
576 |
setViewportOrg: gcId "deviceContext" |
|
577 |
x: aPoint x |
|
578 |
y: aPoint y |
|
579 |
oldOrigin: nil |
|
580 |
||
581 |
"Created: / 01-08-2006 / 16:14:08 / fm" |
|
582 |
! |
|
583 |
||
584 |
verticalPixelsPerMeter |
|
585 |
"Answer vertical pixels per inch |
|
586 |
on the screen." |
|
587 |
||
588 |
^self pixelsPerInchOfScreenHeight * 39.3700787 |
|
2143 | 589 |
! ! |
590 |
||
591 |
!PrinterContext methodsFor:'initialization & release'! |
|
592 |
||
593 |
buildPrinter |
|
2236 | 594 |
"Private - create all the operating system resources needed." |
595 |
||
596 |
self |
|
597 |
createDC; |
|
2143 | 598 |
initExtent |
599 |
||
600 |
"Created: / 27-07-2006 / 10:20:36 / fm" |
|
601 |
"Modified: / 01-08-2006 / 15:57:49 / fm" |
|
2236 | 602 |
"Modified: / 10-10-2006 / 18:14:04 / cg" |
2143 | 603 |
! |
604 |
||
605 |
createDC |
|
2236 | 606 |
"Private - Create a device context for the receiver" |
607 |
||
608 |
gcId := printerInfo createDC |
|
2143 | 609 |
|
610 |
"Created: / 27-07-2006 / 10:21:05 / fm" |
|
611 |
"Modified: / 02-08-2006 / 17:30:47 / fm" |
|
2236 | 612 |
"Modified: / 10-10-2006 / 18:14:28 / cg" |
2143 | 613 |
! |
614 |
||
615 |
initExtent |
|
616 |
"Private - init the width and height of GraphicsTool for the receiver." |
|
2272 | 617 |
|
618 |
width := self printerWidthArea. |
|
619 |
height := self printerHeightArea. |
|
2143 | 620 |
device |
2272 | 621 |
width:width; |
622 |
height:height. |
|
623 |
||
2143 | 624 |
|
625 |
"Modified: / 01-08-2006 / 16:14:49 / fm" |
|
626 |
! ! |
|
627 |
||
628 |
!PrinterContext methodsFor:'printing'! |
|
629 |
||
2236 | 630 |
print:aString font:aFont title:aTitle wordWrap:wordWrapBoolean marginsRect:aMarginsRect |
631 |
"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 |
||
2247 | 639 |
|lines linesPerPage totalPage marginsRect firstPage abortDialog| |
2143 | 640 |
|
2236 | 641 |
jobid isNil ifTrue:[ |
642 |
self startPrintJob:aTitle |
|
643 |
]. |
|
644 |
abortDialog := PrintAbortDialog new open:aTitle printer:self. |
|
645 |
self font:aFont. |
|
646 |
marginsRect := self marginsRectangleFor:aMarginsRect. |
|
647 |
lines := self |
|
648 |
asArrayOfStringLines:aString |
|
649 |
in:marginsRect |
|
650 |
wordWrap:wordWrapBoolean. |
|
2247 | 651 |
linesPerPage := self linesPerPageFor: marginsRect. |
2236 | 652 |
totalPage := (lines size + linesPerPage - 1) // linesPerPage. |
2143 | 653 |
firstPage := true. |
2236 | 654 |
|
2143 | 655 |
"/ collateBoolean |
656 |
"/ ifTrue: [ |
|
657 |
"/ copiesInteger timesRepeat: [ |
|
2236 | 658 |
|
659 |
1 to:totalPage do:[:page | |
|
660 |
abort ifTrue:[ ^ self ]. |
|
661 |
firstPage ifFalse:[ |
|
662 |
self formFeed |
|
663 |
]. |
|
664 |
abortDialog |
|
665 |
updatePrintingPageInfo:(self class classResources |
|
666 |
string:'Page %1/%2' |
|
667 |
with:page printString |
|
668 |
with:totalPage printString). |
|
669 |
||
2143 | 670 |
"/ self device font: printerFont. |
2236 | 671 |
|
672 |
self font:aFont. |
|
673 |
self |
|
674 |
printPage:page |
|
675 |
in:marginsRect |
|
676 |
lines:lines |
|
677 |
linesPerPage:linesPerPage. |
|
678 |
firstPage := false |
|
679 |
]. |
|
680 |
||
2143 | 681 |
"/ ] |
682 |
"/ ] ifFalse: [ |
|
683 |
"/ 1 to: totalPage do: [ :page | |
|
684 |
"/ copiesInteger timesRepeat: [ |
|
685 |
"/ abort ifTrue: [ ^self endPrintJob ]. |
|
686 |
"/ firstPage ifFalse: [ self formFeed ]. |
|
687 |
"/ self device font: printerFont. |
|
688 |
"/ self printPage: page in: marginsRect lines: lines linesPerPage: linesPerPage. |
|
689 |
"/ firstPage := false |
|
690 |
"/ ] |
|
691 |
"/ ] |
|
692 |
"/ ]. |
|
2236 | 693 |
|
694 |
jobid notNil ifTrue:[ |
|
695 |
self endPrintJob. |
|
696 |
abortDialog close. |
|
697 |
]. |
|
2143 | 698 |
|
2236 | 699 |
"/ abort ifFalse: [ abortDialog close ] |
2143 | 700 |
|
701 |
"Created: / 03-08-2006 / 16:13:33 / fm" |
|
702 |
"Modified: / 04-08-2006 / 13:40:02 / fm" |
|
2236 | 703 |
"Modified: / 10-10-2006 / 18:16:54 / cg" |
2247 | 704 |
"Modified: / 12-10-2006 / 11:50:37 / User" |
2143 | 705 |
! |
706 |
||
2274 | 707 |
print: aString |
708 |
pageHeader: aString2 |
|
709 |
font: aFont |
|
710 |
title: aTitle |
|
711 |
collate: collateBoolean |
|
712 |
copies: copiesInteger |
|
713 |
wordWrap: wordWrapBoolean |
|
714 |
marginsRect: aMarginsRect |
|
715 |
||
716 |
"Private - Answer the receiver. Output the receiver string to |
|
717 |
the printer using aFont. A Print abort dialog box will be opened |
|
718 |
with aTitle. If collateBoolean is true, collate output, otherwise |
|
719 |
do not. Print copiesInteger copies of the specified string. If |
|
720 |
wordWrapBoolean is true, word wrap the lines, otherwise do not. |
|
721 |
Left, top, right & bottom margins are specified in inches in |
|
722 |
aMarginsRect. |
|
723 |
Mg: Erweitert um pageHeader" |
|
724 |
"Changed by K3/EES5-Mg, 08.01.96" |
|
725 |
||
726 |
| lines linesPerPage totalPage marginsRect firstPage charHeight printerFont headerLines| |
|
727 |
||
728 |
printerFont := self setPrinterFont: aFont. |
|
729 |
charHeight := self "pen" getCharHeight. |
|
730 |
marginsRect := self marginsRectangleFor: aMarginsRect. |
|
731 |
lines := self "pen" asArrayOfStringLines: aString in: marginsRect wordWrap: wordWrapBoolean. |
|
732 |
headerLines := self "pen" asArrayOfStringLines: aString2 in: marginsRect wordWrap: wordWrapBoolean. |
|
733 |
linesPerPage := marginsRect bottom - marginsRect top // charHeight. |
|
734 |
||
735 |
linesPerPage > headerLines size |
|
736 |
ifFalse: |
|
737 |
[Dialog information: 'Der Dokumentenkopf ist zu groß; wird ignoriert!!'. |
|
738 |
headerLines := #(). |
|
739 |
] |
|
740 |
ifTrue: [linesPerPage := linesPerPage - headerLines size]. |
|
741 |
totalPage := lines size + linesPerPage - 1 // linesPerPage. |
|
742 |
firstPage := true. |
|
743 |
||
744 |
"/ collateBoolean |
|
745 |
"/ ifTrue: [ |
|
746 |
"/ copiesInteger timesRepeat: [ |
|
747 |
||
748 |
1 to: totalPage do: [ :page | |
|
749 |
abort ifTrue: [ ^self endPrintJob ]. |
|
750 |
firstPage ifFalse: [ self formFeed ]. |
|
751 |
self "pen" font: aFont "printerFont". |
|
752 |
self printPage: page in: marginsRect lines: lines headerLines: headerLines linesPerPage: linesPerPage. |
|
753 |
firstPage := false ] |
|
754 |
||
755 |
"/ ] |
|
756 |
"/ ] |
|
757 |
"/ ifFalse: [ |
|
758 |
"/ 1 to: totalPage do: [ :page | |
|
759 |
"/ copiesInteger timesRepeat: [ |
|
760 |
"/ abort ifTrue: [ ^self endPrintJob ]. |
|
761 |
"/ firstPage ifFalse: [ self formFeed ]. |
|
762 |
"/ self "pen" font: printerFont. |
|
763 |
"/ self printPage: page in: marginsRect lines: lines headerLines: headerLines linesPerPage: linesPerPage. |
|
764 |
"/ firstPage := false ] ] ]. |
|
765 |
||
766 |
"Created: / 30-11-2006 / 13:19:06 / User" |
|
767 |
! |
|
768 |
||
2236 | 769 |
print:aString pageHeader:aString2 font:aFont title:aTitle wordWrap:wordWrapBoolean marginsRect:aMarginsRect |
770 |
"Private - Answer the receiver. Output the receiver string to |
|
771 |
the printer using aFont. A Print abort dialog box will be opened |
|
772 |
with aTitle. If collateBoolean is true, collate output, otherwise |
|
773 |
do not. Print copiesInteger copies of the specified string. If |
|
774 |
wordWrapBoolean is true, word wrap the lines, otherwise do not. |
|
775 |
Left, top, right & bottom margins are specified in inches in |
|
776 |
aMarginsRect." |
|
777 |
||
778 |
|lines linesPerPage totalPage marginsRect firstPage charHeight printerFont headerLines| |
|
2143 | 779 |
|
2236 | 780 |
self font:aFont. |
2143 | 781 |
charHeight := self getCharHeight. |
2236 | 782 |
marginsRect := self marginsRectangleFor:aMarginsRect. |
783 |
lines := self |
|
784 |
asArrayOfStringLines:aString |
|
785 |
in:marginsRect |
|
786 |
wordWrap:wordWrapBoolean. |
|
787 |
headerLines := self |
|
788 |
asArrayOfStringLines:aString2 |
|
789 |
in:marginsRect |
|
790 |
wordWrap:wordWrapBoolean. |
|
791 |
linesPerPage := (marginsRect bottom - marginsRect top) // charHeight. |
|
792 |
linesPerPage > headerLines size ifFalse:[ |
|
793 |
Dialog information:(self class classResources |
|
794 |
string:'The header is too large - ignored!!'). |
|
795 |
headerLines := #(). |
|
796 |
] ifTrue:[ |
|
797 |
linesPerPage := linesPerPage - headerLines size |
|
798 |
]. |
|
799 |
totalPage := (lines size + linesPerPage - 1) // linesPerPage. |
|
2143 | 800 |
firstPage := true. |
2236 | 801 |
|
2143 | 802 |
"/ collateBoolean |
803 |
"/ ifTrue: [ |
|
804 |
"/ copiesInteger timesRepeat: [ |
|
2236 | 805 |
|
806 |
1 to:totalPage do:[:page | |
|
807 |
abort ifTrue:[ ^ self ]. |
|
808 |
firstPage ifFalse:[ |
|
809 |
self formFeed |
|
810 |
]. |
|
811 |
self font:printerFont. |
|
812 |
self |
|
813 |
printPage:page |
|
814 |
in:marginsRect |
|
815 |
lines:lines |
|
816 |
headerLines:headerLines |
|
817 |
linesPerPage:linesPerPage. |
|
818 |
firstPage := false |
|
819 |
] |
|
2143 | 820 |
|
2236 | 821 |
"/ ] |
822 |
"/ ] ifFalse: [ |
|
823 |
"/ 1 to: totalPage do: [ :page | |
|
824 |
"/ copiesInteger timesRepeat: [ |
|
825 |
"/ abort ifTrue: [ ^self endPrintJob ]. |
|
826 |
"/ firstPage ifFalse: [ self formFeed ]. |
|
827 |
"/ self device font: printerFont. |
|
828 |
"/ self printPage: page in: marginsRect lines: lines headerLines: headerLines linesPerPage: linesPerPage. |
|
829 |
"/ firstPage := false |
|
830 |
"/ ] |
|
831 |
"/ ] |
|
832 |
"/ ]. |
|
2143 | 833 |
|
834 |
"Created: / 03-08-2006 / 16:14:10 / fm" |
|
2236 | 835 |
"Modified: / 10-10-2006 / 18:18:03 / cg" |
2143 | 836 |
! ! |
837 |
||
2147 | 838 |
!PrinterContext methodsFor:'printing process'! |
2143 | 839 |
|
840 |
endPage |
|
2236 | 841 |
"Informs device that we are finished writing to a page." |
842 |
||
843 |
(OperatingSystem endPage:gcId) > 0 ifFalse:[ |
|
844 |
self error |
|
845 |
] |
|
2143 | 846 |
|
847 |
"Created: / 27-07-2006 / 18:20:48 / fm" |
|
848 |
"Modified: / 01-08-2006 / 16:01:34 / fm" |
|
2236 | 849 |
"Modified: / 10-10-2006 / 18:14:44 / cg" |
2143 | 850 |
! |
851 |
||
852 |
endPrintJob |
|
2236 | 853 |
"End the print job. Everything drawn between startPrintJob |
854 |
and endPrintJob will become one entry in the print queue." |
|
855 |
||
856 |
|result| |
|
2143 | 857 |
|
858 |
self endPage. |
|
2236 | 859 |
result := OperatingSystem endDoc:gcId. |
860 |
device close. |
|
861 |
gcId := nil. |
|
2143 | 862 |
jobid := nil. |
2237 | 863 |
result >= 0 ifFalse:[ self error ] |
2143 | 864 |
|
865 |
"Created: / 27-07-2006 / 18:21:04 / fm" |
|
866 |
"Modified: / 01-08-2006 / 16:01:38 / fm" |
|
2237 | 867 |
"Modified: / 10-10-2006 / 18:50:43 / cg" |
2143 | 868 |
! |
869 |
||
870 |
formFeed |
|
2236 | 871 |
"Send a form feed to the printer." |
872 |
||
2143 | 873 |
self |
874 |
endPage; |
|
875 |
startPage |
|
876 |
||
877 |
"Created: / 27-07-2006 / 18:25:40 / fm" |
|
2236 | 878 |
"Modified: / 10-10-2006 / 18:15:07 / cg" |
2143 | 879 |
! |
880 |
||
881 |
startPage |
|
2236 | 882 |
"Starts a page." |
883 |
||
884 |
(OperatingSystem startPage:gcId) > 0 ifFalse:[ |
|
885 |
^ self error |
|
886 |
]. |
|
2143 | 887 |
|
888 |
"Created: / 27-07-2006 / 18:25:55 / fm" |
|
889 |
"Modified: / 28-07-2006 / 18:19:04 / fm" |
|
2236 | 890 |
"Modified: / 10-10-2006 / 18:19:02 / cg" |
2143 | 891 |
! |
892 |
||
893 |
startPrintJob |
|
2236 | 894 |
"Start a print job. Everything drawn between startPrintJob |
895 |
and endPrintJob will become one entry in the print queue." |
|
896 |
||
897 |
self startPrintJob:nil |
|
2143 | 898 |
|
899 |
"Created: / 27-07-2006 / 18:18:52 / fm" |
|
2236 | 900 |
"Modified: / 10-10-2006 / 18:19:05 / cg" |
2143 | 901 |
! |
902 |
||
2236 | 903 |
startPrintJob:aString |
904 |
"Start a print job, using aString as the job title; everything |
|
905 |
drawn between startPrintJob and endPrintJob will become |
|
906 |
one entry in the print queue." |
|
907 |
||
908 |
^ self startPrintJob:aString fileName:nil |
|
2143 | 909 |
|
910 |
"Created: / 27-07-2006 / 18:19:09 / fm" |
|
2236 | 911 |
"Modified: / 10-10-2006 / 18:19:12 / cg" |
2143 | 912 |
! |
913 |
||
2236 | 914 |
startPrintJob:aString fileName:aFileName |
915 |
"Start a print job, using aString as the job title; everything |
|
916 |
drawn between startPrintJob and endPrintJob will become |
|
917 |
one entry in the print queue." |
|
918 |
||
919 |
|docInfoStruct nameAddress title fileNameAddress| |
|
2143 | 920 |
|
2236 | 921 |
gcId isNil ifTrue:[ |
922 |
self buildPrinter |
|
923 |
]. |
|
2143 | 924 |
abort := false. |
2236 | 925 |
title := aString ? 'Smalltalk/X'. |
2143 | 926 |
nameAddress := title asExternalBytes unprotectFromGC. |
2236 | 927 |
aFileName isNil ifFalse:[ |
928 |
fileNameAddress := aFileName pathName asExternalBytes unprotectFromGC |
|
929 |
]. |
|
930 |
docInfoStruct := Win32OperatingSystem::DocInfoStructure new. |
|
931 |
docInfoStruct |
|
932 |
cbSize:docInfoStruct sizeInBytes; |
|
933 |
lpszDocName:nameAddress address. |
|
934 |
fileNameAddress isNil ifFalse:[ |
|
935 |
docInfoStruct lpszOutput:fileNameAddress address |
|
936 |
]. |
|
937 |
jobid := OperatingSystem startDoc:gcId docInfo:docInfoStruct. |
|
938 |
jobid > 0 ifFalse:[ |
|
939 |
jobid = -1 ifTrue:[ |
|
940 |
abort := true. |
|
941 |
^ nil |
|
942 |
]. |
|
943 |
^ self error |
|
944 |
]. |
|
2143 | 945 |
self startPage |
946 |
||
947 |
"Created: / 27-07-2006 / 18:19:31 / fm" |
|
948 |
"Modified: / 03-08-2006 / 15:11:19 / fm" |
|
2236 | 949 |
"Modified: / 10-10-2006 / 18:20:01 / cg" |
2147 | 950 |
! ! |
951 |
||
952 |
!PrinterContext methodsFor:'queries'! |
|
953 |
||
954 |
supportsColor |
|
955 |
||
956 |
"/ | retVal info | |
|
957 |
"/ |
|
958 |
"/ info := (self class getPrinterInformation: self name) asUppercase. |
|
959 |
"/ (info includesSubstring: ',PSCRIPT,') |
|
960 |
"/ ifTrue: [ |
|
961 |
"/ retVal := (DAPASX::DapasSystemInfo getYesNoInfoApp: 'Printer' profile: 'PostScriptBlackWhite') not. |
|
962 |
"/ ] |
|
963 |
"/ ifFalse: [ |
|
964 |
"/ retVal := (info includesSubstring: 'PDF') |
|
965 |
"/ ifTrue: [true] |
|
966 |
"/ ifFalse: [self numberOfColorBitsPerPixel > 1]. |
|
967 |
"/ ]. |
|
968 |
"/ |
|
969 |
"/ ^retVal |
|
970 |
||
2236 | 971 |
^ false. |
972 |
||
2147 | 973 |
"Created: / 03-08-2006 / 09:55:26 / fm" |
974 |
"Modified: / 04-08-2006 / 13:20:40 / fm" |
|
2236 | 975 |
"Modified: / 10-10-2006 / 18:21:07 / cg" |
2147 | 976 |
! |
977 |
||
978 |
supportsGraphics |
|
2272 | 979 |
^(OperatingSystem getDeviceCaps: gcId "asParameter" index: 2 "Technology") ~= 4 |
2147 | 980 |
|
981 |
"Created: / 03-08-2006 / 10:07:43 / fm" |
|
2236 | 982 |
"Modified: / 10-10-2006 / 18:21:14 / cg" |
2147 | 983 |
! ! |
984 |
||
985 |
!PrinterContext methodsFor:'text printing'! |
|
986 |
||
2236 | 987 |
asArrayOfStringLines:aString in:aRectangle wordWrap:wordWrapBoolean |
988 |
"Private - convert aString into an array of lines; if wordWrapBoolean |
|
989 |
is true, also perform word wrapping on the lines, within aRectangle." |
|
990 |
||
991 |
|line lines stream x0 x1 partialLine leftMargin rightMargin partialLineWidth index| |
|
992 |
||
993 |
stream := ReadStream on:aString. |
|
2147 | 994 |
lines := OrderedCollection new. |
2236 | 995 |
wordWrapBoolean ifTrue:[ |
2147 | 996 |
leftMargin := aRectangle left. |
2236 | 997 |
rightMargin := aRectangle right |
998 |
]. |
|
999 |
[ stream atEnd ] whileFalse:[ |
|
2147 | 1000 |
line := stream nextLine. |
2236 | 1001 |
wordWrapBoolean ifFalse:[ |
1002 |
lines add:line |
|
1003 |
] ifTrue:[ |
|
1004 |
x0 := x1 := 1. |
|
1005 |
1 to:line size do:[:i | |
|
1006 |
((line at:i) = Character space "32" |
|
1007 |
and:[ (partialLine := line copyFrom:x0 to:i) trimBlanks notEmpty ]) |
|
1008 |
ifTrue:[ |
|
1009 |
partialLineWidth := self stringWidthOf:partialLine. |
|
1010 |
(leftMargin + partialLineWidth) > rightMargin ifTrue:[ |
|
1011 |
partialLine := line copyFrom:x0 to:x1. |
|
1012 |
lines add:partialLine. |
|
1013 |
x0 := x1 + 1 |
|
1014 |
] ifFalse:[ x1 := i ] |
|
2147 | 1015 |
]. |
2236 | 1016 |
index := i |
1017 |
]. |
|
1018 |
line isEmpty ifTrue:[ |
|
1019 |
lines add:line |
|
1020 |
] ifFalse:[ |
|
1021 |
partialLine := line copyFrom:x0 to:index. |
|
1022 |
partialLineWidth := self stringWidthOf:partialLine. |
|
1023 |
(leftMargin + partialLineWidth) > rightMargin ifTrue:[ |
|
1024 |
partialLine := line copyFrom:x0 to:x1. |
|
1025 |
lines add:partialLine. |
|
1026 |
partialLine := line copyFrom:x1 + 1 to:index |
|
1027 |
]. |
|
1028 |
lines add:partialLine |
|
1029 |
] |
|
1030 |
] |
|
2147 | 1031 |
]. |
2236 | 1032 |
^ lines asArray |
2147 | 1033 |
|
1034 |
"Created: / 02-08-2006 / 17:56:51 / fm" |
|
1035 |
"Modified: / 04-08-2006 / 13:39:50 / fm" |
|
2236 | 1036 |
"Modified: / 10-10-2006 / 18:14:00 / cg" |
2147 | 1037 |
! |
1038 |
||
2272 | 1039 |
displayString:aString at:aPoint in:aRect options:ignoredForNow adx:unknownForNow |
1040 |
|x y| |
|
1041 |
x := aPoint x. |
|
1042 |
y := aPoint y. |
|
1043 |
(textAlign isNil or:[textAlign == 0 ]) ifTrue:[ |
|
1044 |
self displayString:aString at:aPoint. |
|
1045 |
^ self |
|
1046 |
]. |
|
1047 |
(textAlign == 8 "TaBottom") ifTrue:[ |
|
1048 |
y := aPoint y - (self container font ascent) "container font ascent". |
|
1049 |
] ifFalse:[ (textAlign == 6 "TaCenter") ifTrue:[ |
|
1050 |
#TODO. |
|
1051 |
"/ x := aRect left + ((aRect width-(container font widthOf:aString))//2). |
|
1052 |
] ifFalse:[ (textAlign == 2 "TaRight") ifTrue:[ |
|
1053 |
x := aRect right - (self "container font widthof:" stringWidthOf:aString). |
|
1054 |
y := self "container font ascent" getCharHeight + aPoint y . |
|
1055 |
] ifFalse:[ (textAlign == 14 "TaCenterBottom") ifTrue:[ |
|
1056 |
y := aRect bottom - self getCharHeight "container font ascent". |
|
1057 |
x := aRect left + ((aRect width-(self "container font widthOf:" stringWidthOf:aString))//2). |
|
1058 |
] ifFalse:[ (textAlign == 10) ifTrue:[ |
|
1059 |
x := aRect right - (self "container font widthof:" stringWidthOf:aString). |
|
1060 |
y := aRect bottom "aPoint y - (self container font ascent)" - self getCharHeight. |
|
1061 |
]]]]]. |
|
1062 |
Transcript showCR: 'Original Pos: ', aPoint x printString, '@', aPoint y printString, |
|
1063 |
' Pos: ', x printString, '@', y printString, |
|
1064 |
' Text: ', aString. |
|
1065 |
self displayString:aString at:(x@y). |
|
1066 |
||
1067 |
"Modified: / 20-10-2006 / 13:53:44 / User" |
|
1068 |
! |
|
1069 |
||
2236 | 1070 |
displayStringLines:anIndexedCollection from:startIndex to:endIndex in:aRectangle |
1071 |
"Private - display Strings in anIndexedCollection starting at startIndex and |
|
1072 |
ending at endIndex, clipped within the bounds of aRectangle." |
|
1073 |
||
1074 |
|charHeight ta region ascent| |
|
1075 |
||
2147 | 1076 |
charHeight := self getCharHeight. |
2236 | 1077 |
ascent := self font ascentOn:self device. |
1078 |
startIndex to:endIndex do:[:i | |
|
2147 | 1079 |
|lineToPrint| |
2236 | 1080 |
|
1081 |
lineToPrint := (anIndexedCollection at:i). |
|
1082 |
self device |
|
1083 |
displayString:lineToPrint |
|
1084 |
from:1 |
|
1085 |
to:lineToPrint size |
|
1086 |
x:aRectangle left |
|
1087 |
y:(aRectangle top + ((i - startIndex) * charHeight)) |
|
1088 |
in:nil |
|
1089 |
with:gcId |
|
1090 |
opaque:false |
|
1091 |
fontAscent:ascent. |
|
2147 | 1092 |
]. |
1093 |
||
2236 | 1094 |
"/ region := self setClipRect: aRectangle. |
1095 |
"/ ta := self getTextAlign. |
|
1096 |
"/ self setTextAlign: TaTop. |
|
1097 |
"/ startIndex to: endIndex do: [ :i | |
|
1098 |
"/ self |
|
1099 |
"/ displayText: ( anIndexedCollection at: i ) |
|
1100 |
"/ at: aRectangle left @ ( aRectangle top + ( i - startIndex * charHeight ) ) ]. |
|
1101 |
"/ self setTextAlign: ta. |
|
1102 |
"/ self destroyRegion: region |
|
2147 | 1103 |
|
1104 |
"Created: / 03-08-2006 / 11:37:52 / fm" |
|
1105 |
"Modified: / 03-08-2006 / 12:38:43 / fm" |
|
2236 | 1106 |
"Modified: / 10-10-2006 / 18:14:36 / cg" |
2147 | 1107 |
! |
1108 |
||
2236 | 1109 |
displayStringLines:anIndexedCollection in:aRectangle |
1110 |
"Private - display anIndexedCollection of Strings clipped within |
|
1111 |
the bounds of aRectangle." |
|
1112 |
||
1113 |
self |
|
1114 |
displayStringLines:anIndexedCollection |
|
1115 |
from:1 |
|
1116 |
to:anIndexedCollection size |
|
1117 |
in:aRectangle |
|
2147 | 1118 |
|
1119 |
"Created: / 03-08-2006 / 16:03:07 / fm" |
|
2236 | 1120 |
"Modified: / 10-10-2006 / 18:14:40 / cg" |
2147 | 1121 |
! |
1122 |
||
2272 | 1123 |
displayText: aString at: aPoint |
1124 |
||
1125 |
self displayString:aString x:aPoint x y:aPoint y |
|
1126 |
! |
|
1127 |
||
2247 | 1128 |
linesPerPageFor: aRectangle |
1129 |
||
1130 |
|marginsRect charHeight| |
|
1131 |
||
1132 |
marginsRect := aRectangle isNil |
|
1133 |
ifTrue:[self marginsRectangleFor: nil] |
|
1134 |
ifFalse:[aRectangle]. |
|
1135 |
||
1136 |
charHeight := self getCharHeight. |
|
1137 |
^(marginsRect bottom - marginsRect top) // charHeight |
|
1138 |
||
1139 |
"Created: / 12-10-2006 / 11:52:57 / User" |
|
1140 |
! |
|
1141 |
||
2147 | 1142 |
marginsRectangleFor:aRectangle |
1143 |
"Private - Answer a Rectangle defining margins based on aRectangle. |
|
1144 |
Units for aRectangle are in inches, returned margins rectangle is |
|
1145 |
in device units (pixels)." |
|
1146 |
||
1147 |
|left top right bottom pixelsPerInchX pixelsPerInchY horzRes vertRes inset rectangle| |
|
2236 | 1148 |
|
2147 | 1149 |
pixelsPerInchX := self pixelsPerInchOfScreenWidth. |
1150 |
pixelsPerInchY := self pixelsPerInchOfScreenHeight. |
|
1151 |
aRectangle isNil ifTrue:[ |
|
1152 |
horzRes := self printerWidthArea. |
|
1153 |
vertRes := self printerHeightArea. |
|
1154 |
inset := self class defaultMargins. |
|
1155 |
left := (inset x * pixelsPerInchX) asInteger. |
|
1156 |
top := (inset y * pixelsPerInchY) asInteger. |
|
1157 |
right := horzRes - (inset x * pixelsPerInchX) asInteger. |
|
1158 |
bottom := vertRes - (inset y * pixelsPerInchY) asInteger |
|
1159 |
] ifFalse:[ |
|
1160 |
left := (aRectangle left * pixelsPerInchX) asInteger. |
|
1161 |
top := (aRectangle top * pixelsPerInchY) asInteger. |
|
1162 |
right := (aRectangle right * pixelsPerInchX) asInteger. |
|
1163 |
bottom := (aRectangle bottom * pixelsPerInchY) asInteger |
|
1164 |
]. |
|
2236 | 1165 |
rectangle := left @ top extent:right @ bottom. |
2147 | 1166 |
^ rectangle |
1167 |
||
1168 |
"Created: / 27-07-2006 / 18:22:57 / fm" |
|
1169 |
"Modified: / 04-08-2006 / 13:39:45 / fm" |
|
2236 | 1170 |
"Modified: / 10-10-2006 / 18:15:26 / cg" |
2147 | 1171 |
! |
1172 |
||
2236 | 1173 |
printPage:pageIndex in:aRectangle lines:lines headerLines:headerLines linesPerPage:linesPerPage |
1174 |
"Private - print page # pageIndex from lines, assuming |
|
1175 |
the given number of linesPerPage." |
|
1176 |
||
1177 |
|firstLine lastLine l indexString p cHeight rect hLines| |
|
2147 | 1178 |
|
2236 | 1179 |
firstLine := (pageIndex - 1) * linesPerPage + 1. |
1180 |
lastLine := (firstLine + linesPerPage - 1) min:lines size. |
|
2147 | 1181 |
rect := aRectangle deepCopy. |
1182 |
hLines := headerLines deepCopy. |
|
2236 | 1183 |
headerLines size > 0 ifTrue:[ |
1184 |
l := hLines first. |
|
2274 | 1185 |
p := l indexOfSubCollection: "indexOfString:"'#P'. |
1186 |
p = 0 ifFalse:[ |
|
2236 | 1187 |
indexString := pageIndex printString , ' '. |
1188 |
l := (l copyFrom:1 to:p - 1) , indexString , (l copyFrom:p + 2 to:l size). |
|
1189 |
hLines at:1 put:l. |
|
1190 |
]. |
|
1191 |
cHeight := self getCharHeight. |
|
1192 |
rect top:rect top + (hLines size * cHeight). |
|
1193 |
]. |
|
1194 |
self displayStringLines:hLines in:aRectangle. |
|
1195 |
self |
|
1196 |
displayStringLines:lines |
|
1197 |
from:firstLine |
|
1198 |
to:lastLine |
|
1199 |
in:rect. |
|
2147 | 1200 |
|
1201 |
"Created: / 27-07-2006 / 18:28:00 / fm" |
|
1202 |
"Modified: / 03-08-2006 / 16:03:15 / fm" |
|
2236 | 1203 |
"Modified: / 10-10-2006 / 18:18:15 / cg" |
2274 | 1204 |
"Modified: / 30-11-2006 / 13:34:44 / User" |
2147 | 1205 |
! |
1206 |
||
2236 | 1207 |
printPage:pageIndex in:aRectangle lines:lines linesPerPage:linesPerPage |
1208 |
"Private - print page # pageIndex from lines, assuming |
|
1209 |
the given number of linesPerPage." |
|
1210 |
||
1211 |
|firstLine lastLine| |
|
1212 |
||
1213 |
firstLine := (pageIndex - 1) * linesPerPage + 1. |
|
1214 |
lastLine := (firstLine + linesPerPage - 1) min:lines size. |
|
1215 |
self |
|
1216 |
displayStringLines:lines |
|
1217 |
from:firstLine |
|
1218 |
to:lastLine |
|
1219 |
in:aRectangle |
|
2147 | 1220 |
|
1221 |
"Created: / 27-07-2006 / 18:24:59 / fm" |
|
1222 |
"Modified: / 03-08-2006 / 12:47:24 / fm" |
|
2236 | 1223 |
"Modified: / 10-10-2006 / 18:18:22 / cg" |
2143 | 1224 |
! |
1225 |
||
2236 | 1226 |
stringWidthOf:aString |
1227 |
"Return the width of aString |
|
1228 |
when written using the current font." |
|
1229 |
||
1230 |
^ self stringWidthOf:aString at:aString size. |
|
2143 | 1231 |
|
1232 |
"Modified: / 03-08-2006 / 10:18:23 / fm" |
|
2236 | 1233 |
"Modified: / 10-10-2006 / 18:20:08 / cg" |
2143 | 1234 |
! |
1235 |
||
2236 | 1236 |
stringWidthOf:aString at:index |
1237 |
"Return the width of aString up to index |
|
1238 |
when written using the current font; expand tabs out |
|
1239 |
to 4 spaces for calculations" |
|
1240 |
||
1241 |
|answer str size spaceWidth| |
|
1242 |
||
1243 |
index <= 0 ifTrue:[ ^ 0 ]. |
|
1244 |
str := index >= aString size ifTrue:[ aString ] ifFalse:[ aString copyFrom:1 to:index ]. |
|
1245 |
true "self font isNil" ifTrue:[ |
|
1246 |
"if font not set yet, calculate based on default font" |
|
1247 |
"/ extString := str asExternalString. |
|
1248 |
size := Win32OperatingSystem::WinPointStructure new. |
|
1249 |
(OperatingSystem |
|
1250 |
getTextExtentPoint:gcId |
|
1251 |
string:str |
|
1252 |
size:size) ifFalse:[ ^ self error ]. |
|
1253 |
answer := size x. |
|
2272 | 1254 |
"/ Transcript showCR: 'FROM PRIM ******* ', str, ' ', answer printString. |
1255 |
"/ Transcript showCR: 'FROM DEVICE ***** ', str, ' ',(self font widthOf:str on:self device) printString. |
|
2236 | 1256 |
#TODO. |
1257 |
] ifFalse:[ |
|
1258 |
answer := self font widthOf:str on:self device |
|
1259 |
]. |
|
1260 |
index > aString size ifTrue:[ |
|
1261 |
spaceWidth := self font widthOf:Character space on:self device. |
|
1262 |
answer := answer + ((index - aString size) * spaceWidth) |
|
1263 |
]. |
|
1264 |
^ answer. |
|
2143 | 1265 |
|
1266 |
"Created: / 03-08-2006 / 10:27:20 / fm" |
|
1267 |
"Modified: / 04-08-2006 / 12:27:26 / fm" |
|
2236 | 1268 |
"Modified: / 10-10-2006 / 18:20:43 / cg" |
2272 | 1269 |
! |
1270 |
||
1271 |
withLineStyle:aSymbol lineWidth:lw paint:paintColor do:aBlock |
|
1272 |
|savStyle savWidth savPaint| |
|
1273 |
||
1274 |
savStyle := self lineStyle. |
|
1275 |
savWidth := self lineWidth. |
|
1276 |
savPaint := self paint. |
|
1277 |
||
1278 |
self lineStyle:aSymbol. |
|
1279 |
self lineWidth:lw. |
|
1280 |
self paint:paintColor. |
|
1281 |
aBlock value. |
|
1282 |
self paint:savPaint. |
|
1283 |
self lineWidth:savWidth. |
|
1284 |
self lineStyle:savStyle. |
|
1285 |
||
1286 |
"Created: / 13-09-2006 / 15:38:56 / User" |
|
2143 | 1287 |
! ! |
1288 |
||
1289 |
!PrinterContext class methodsFor:'documentation'! |
|
1290 |
||
1291 |
version |
|
2274 | 1292 |
^ '$Header: /cvs/stx/stx/libview2/PrinterContext.st,v 1.11 2006-11-30 13:26:37 fm Exp $' |
2143 | 1293 |
! ! |