10 hereby transferred. |
10 hereby transferred. |
11 " |
11 " |
12 |
12 |
13 PipeStream subclass:#PrinterStream |
13 PipeStream subclass:#PrinterStream |
14 instanceVariableNames:'native pageFormat' |
14 instanceVariableNames:'native pageFormat' |
15 classVariableNames:'PrintCommand LeftMargin DefaultCommands PageFormat |
15 classVariableNames:'' |
16 DefaultPageFormats Landscape' |
|
17 poolDictionaries:'' |
16 poolDictionaries:'' |
18 category:'Streams-External' |
17 category:'Streams-External' |
|
18 ! |
|
19 |
|
20 PrinterStream class instanceVariableNames:'PrintCommand DefaultCommands PageFormat LeftMargin DefaultPageFormats |
|
21 Landscape' |
|
22 |
|
23 " |
|
24 The following class instance variables are inherited by this class: |
|
25 |
|
26 PipeStream - |
|
27 NonPositionableExternalStream - |
|
28 ExternalStream - |
|
29 ReadWriteStream - |
|
30 WriteStream - |
|
31 PositionableStream - |
|
32 PeekableStream - |
|
33 Stream - |
|
34 Object - |
|
35 " |
19 ! |
36 ! |
20 |
37 |
21 !PrinterStream class methodsFor:'documentation'! |
38 !PrinterStream class methodsFor:'documentation'! |
22 |
39 |
23 copyright |
40 copyright |
54 which is either set to PrinterStream (for dumb printers) or to one of |
71 which is either set to PrinterStream (for dumb printers) or to one of |
55 the subclasses (PostscriptPrinterStream etc.). |
72 the subclasses (PostscriptPrinterStream etc.). |
56 |
73 |
57 To print: |
74 To print: |
58 |
75 |
59 |p| |
76 |p| |
60 |
77 |
61 p := Printer new. |
78 p := Printer new. |
62 p notNil ifTrue:[ |
79 p notNil ifTrue:[ |
63 p nextPutAll:'hello world'; cr. |
80 p nextPutAll:'hello world'; cr. |
64 p nextPutAll:' ...'; cr. |
81 p nextPutAll:' ...'; cr. |
65 p close |
82 p close |
66 ]. |
83 ]. |
67 |
84 |
68 See users of the Printer global variable for more examples. |
85 See users of the Printer global variable for more examples. |
69 |
86 |
70 [class variables:] |
87 [class variables:] |
71 PrintCommand <String> the operatingSystem command for printing. |
88 PrintCommand <String> the operatingSystem command for printing. |
72 Usually something like 'lp' or 'lpr' |
89 Usually something like 'lp' or 'lpr' |
73 |
90 |
74 LeftMargin <Integer> optional default left margin. |
91 LeftMargin <Integer> optional default left margin. |
75 Defaults to 0. |
92 Defaults to 0. |
76 |
93 |
77 |
94 |
78 [author:] |
95 [author:] |
79 Claus Gittinger |
96 Claus Gittinger |
80 " |
97 " |
81 ! ! |
98 ! ! |
82 |
99 |
83 !PrinterStream class methodsFor:'initialization'! |
100 !PrinterStream class methodsFor:'initialization'! |
84 |
101 |
85 initialize |
102 initialize |
86 "this is usually redefined by the startup-file" |
103 "this is usually redefined by the startup-file" |
|
104 |
|
105 DefaultCommands isNil ifTrue:[ |
|
106 DefaultCommands := #('lpr' |
|
107 'lpr -P<your-printer>' |
|
108 'cat | rsh <printHost> lpr -h' |
|
109 'cat >xxx ; ghostview xxx' |
|
110 'cat > printfile' |
|
111 'a2ps' |
|
112 'a2ps | rsh <printHost> lpr -h' |
|
113 'a2ps > printfile' |
|
114 ). |
|
115 ]. |
87 |
116 |
88 PrintCommand isNil ifTrue:[ |
117 PrintCommand isNil ifTrue:[ |
89 OperatingSystem isBSDlike ifTrue:[ |
118 OperatingSystem isBSDlike ifTrue:[ |
90 PrintCommand := 'lpr' |
119 PrintCommand := 'lpr' |
91 ] ifFalse:[ |
120 ] ifFalse:[ |
145 "return a list presented as possible commands for printed |
176 "return a list presented as possible commands for printed |
146 (in the launchers printer configuration). |
177 (in the launchers printer configuration). |
147 This list can be set from the startup script with: |
178 This list can be set from the startup script with: |
148 PrinterStream defaultCommands:#( ... )" |
179 PrinterStream defaultCommands:#( ... )" |
149 |
180 |
|
181 DefaultCommands isNil ifTrue:[ |
|
182 self == PrinterStream ifFalse:[ |
|
183 ^ superclass defaultCommands |
|
184 ] |
|
185 ]. |
150 ^ DefaultCommands |
186 ^ DefaultCommands |
151 |
187 |
152 "Created: 23.4.1996 / 18:25:18 / cg" |
188 "Created: 23.4.1996 / 18:25:18 / cg" |
153 ! |
189 ! |
154 |
190 |
155 defaultCommands:collectionOfCommandStrings |
191 defaultCommands:collectionOfCommandStrings |
156 "set the list which will be presented as possible commands for printing. |
192 "set the list which will be presented as possible commands for printing. |
157 (shown in in the launchers printer configuration). |
193 (shown in in the launchers printer configuration). |
158 This can be done from the startup script with: |
194 This can be done from the startup script with: |
159 PrinterStream defaultCommands:#( ... )" |
195 PrinterStream defaultCommands:#( ... )" |
160 |
196 |
161 DefaultCommands := collectionOfCommandStrings |
197 DefaultCommands := collectionOfCommandStrings |
162 |
198 |
163 "Created: 23.4.1996 / 18:26:06 / cg" |
199 "Created: 23.4.1996 / 18:26:06 / cg" |
164 ! |
200 ! |
166 defaultPageFormats |
202 defaultPageFormats |
167 "return a list of supported pae formats. |
203 "return a list of supported pae formats. |
168 This list can be set from the startup script with: |
204 This list can be set from the startup script with: |
169 PrinterStream defaultPageFormats:#..." |
205 PrinterStream defaultPageFormats:#..." |
170 |
206 |
|
207 DefaultPageFormats isNil ifTrue:[ |
|
208 self == PrinterStream ifFalse:[ |
|
209 ^ superclass defaultPageFormats |
|
210 ] |
|
211 ]. |
171 ^ DefaultPageFormats |
212 ^ DefaultPageFormats |
172 |
213 |
173 "Created: 23.4.1996 / 18:25:18 / cg" |
214 "Created: 23.4.1996 / 18:25:18 / cg" |
174 ! |
215 ! |
175 |
216 |
176 defaultPageFormats:aList |
217 defaultPageFormats:aList |
177 "set the list of supported pae formats. |
218 "set the list of supported pae formats. |
178 (shown in in the launchers printer configuration). |
219 (shown in in the launchers printer configuration). |
179 This list can be set from the startup script with: |
220 This list can be set from the startup script with: |
180 PrinterStream defaultPageFormats:#..." |
221 PrinterStream defaultPageFormats:#..." |
181 |
222 |
182 DefaultPageFormats := aList. |
223 DefaultPageFormats := aList. |
183 |
224 |
184 "/ validate the list |
225 "/ validate the list |
185 aList do:[:name | |
226 aList do:[:name | |
186 |unit ok| |
227 |unit ok| |
187 |
228 |
188 ok := true. |
229 ok := true. |
189 #('W' 'H' 'lW' 'lH') do:[:what | |
230 #('W' 'H' 'lW' 'lH') do:[:what | |
190 unit := (name , what) asSymbolIfInterned. |
231 unit := (name , what) asSymbolIfInterned. |
191 (unit isNil |
232 (unit isNil |
192 or:[(UnitConverter convert:1 from:unit to:#millimeter) isNil]) ifTrue:[ |
233 or:[(UnitConverter convert:1 from:unit to:#millimeter) isNil]) ifTrue:[ |
193 ok := false |
234 ok := false |
194 ] |
235 ] |
195 ]. |
236 ]. |
196 ok ifFalse:[ |
237 ok ifFalse:[ |
197 ('PRINTER: UnitConverter has no size-info for ''' , name , '''-format') errorPrintCR |
238 ('PRINTER: UnitConverter has no size-info for ''' , name , '''-format') errorPrintCR |
198 ] |
239 ] |
199 ]. |
240 ]. |
200 |
241 |
201 " |
242 " |
202 PrinterStream |
243 PrinterStream |
203 defaultPageFormats:#( |
244 defaultPageFormats:#( |
204 'letter' |
245 'letter' |
205 'a4' |
246 'a4' |
206 'a5' |
247 'a5' |
207 'a6' |
248 'a6' |
208 ) |
249 ) |
209 " |
250 " |
210 |
251 |
211 "Created: 23.4.1996 / 18:25:18 / cg" |
252 "Created: 23.4.1996 / 18:25:18 / cg" |
212 ! |
253 ! |
213 |
254 |
214 landscape |
255 landscape |
215 "return the landscape setting" |
256 "return the landscape setting" |
216 |
257 |
|
258 Landscape isNil ifTrue:[ |
|
259 self == PrinterStream ifFalse:[ |
|
260 ^ superclass landscape |
|
261 ] |
|
262 ]. |
217 ^ Landscape |
263 ^ Landscape |
218 ! |
264 ! |
219 |
265 |
220 landscape:aBoolean |
266 landscape:aBoolean |
221 "set/clear landscape printing" |
267 "set/clear landscape printing" |
239 "return a symbol describing the default page format. |
290 "return a symbol describing the default page format. |
240 This list can be set from the startup script with: |
291 This list can be set from the startup script with: |
241 PrinterStream defaultPageFormat:#... |
292 PrinterStream defaultPageFormat:#... |
242 or via the launchers settings menu." |
293 or via the launchers settings menu." |
243 |
294 |
|
295 PageFormat isNil ifTrue:[ |
|
296 self == PrinterStream ifFalse:[ |
|
297 ^ superclass pageFormat |
|
298 ] |
|
299 ]. |
244 ^ PageFormat |
300 ^ PageFormat |
245 |
301 |
246 "Created: 23.4.1996 / 18:25:18 / cg" |
302 "Created: 23.4.1996 / 18:25:18 / cg" |
247 ! |
303 ! |
248 |
304 |
251 Valid symbols are #letter, #a4, #a5 etc. |
307 Valid symbols are #letter, #a4, #a5 etc. |
252 The UnitConverter must contain width/height information on |
308 The UnitConverter must contain width/height information on |
253 that symbol, in order for printing to be correct. |
309 that symbol, in order for printing to be correct. |
254 |
310 |
255 This list can be set from the startup script with: |
311 This list can be set from the startup script with: |
256 PrinterStream defaultPageFormat:#... |
312 PrinterStream defaultPageFormat:#... |
257 or via the launchers settings menu." |
313 or via the launchers settings menu." |
258 |
314 |
259 PageFormat := aSymbol |
315 PageFormat := aSymbol |
260 |
316 |
261 "Created: 23.4.1996 / 18:25:18 / cg" |
317 "Created: 23.4.1996 / 18:25:18 / cg" |
264 printCommand |
320 printCommand |
265 "return the command used for printing (usually 'lp' or 'lpr'). |
321 "return the command used for printing (usually 'lp' or 'lpr'). |
266 This is either set from the startup file, or via the launchers |
322 This is either set from the startup file, or via the launchers |
267 settings menu." |
323 settings menu." |
268 |
324 |
|
325 PrintCommand isNil ifTrue:[ |
|
326 self == PrinterStream ifFalse:[ |
|
327 ^ superclass printCommand |
|
328 ] |
|
329 ]. |
269 ^ PrintCommand |
330 ^ PrintCommand |
270 |
331 |
271 "Modified: 18.5.1996 / 09:12:35 / cg" |
332 "Modified: 18.5.1996 / 09:12:35 / cg" |
272 ! |
333 ! |
273 |
334 |
318 |
379 |
319 cr |
380 cr |
320 "send a carriage-return to the printer" |
381 "send a carriage-return to the printer" |
321 |
382 |
322 super nextPut:(Character cr). |
383 super nextPut:(Character cr). |
323 self spaces:LeftMargin |
384 self spaces:(self class leftMargin) |
|
385 |
|
386 "Modified: 1.6.1996 / 00:13:44 / cg" |
324 ! |
387 ! |
325 |
388 |
326 next:count put:aCharacter |
389 next:count put:aCharacter |
327 "send some character multiple times to the printer - translate as needed. |
390 "send some character multiple times to the printer - translate as needed. |
328 Redefined to allow individual character translation in subclasses" |
391 Redefined to allow individual character translation in subclasses" |
329 |
392 |
330 count timesRepeat:[ |
393 count timesRepeat:[ |
331 self nextPut:aCharacter |
394 self nextPut:aCharacter |
332 ] |
395 ] |
333 |
396 |
334 "Created: 10.4.1996 / 13:08:13 / cg" |
397 "Created: 10.4.1996 / 13:08:13 / cg" |
335 "Modified: 10.4.1996 / 13:09:06 / cg" |
398 "Modified: 10.4.1996 / 13:09:06 / cg" |
336 ! |
399 ! |
337 |
400 |
338 nextPut:aCharacter |
401 nextPut:aCharacter |
339 "send some characters to the printer - translate as needed" |
402 "send some characters to the printer - translate as needed" |
340 |
403 |
341 (aCharacter == Character cr) ifTrue:[ |
404 (aCharacter == Character cr) ifTrue:[ |
342 super nextPut:(Character cr). |
405 super nextPut:(Character cr). |
343 self spaces:LeftMargin |
406 self spaces:(self class leftMargin) |
344 ] ifFalse:[ |
407 ] ifFalse:[ |
345 super nextPut:aCharacter |
408 super nextPut:aCharacter |
346 ] |
409 ] |
|
410 |
|
411 "Modified: 1.6.1996 / 00:13:48 / cg" |
347 ! |
412 ! |
348 |
413 |
349 nextPutAll:aCollection |
414 nextPutAll:aCollection |
350 "send some characters to the printer - translate as needed. |
415 "send some characters to the printer - translate as needed. |
351 The argument, aCollection can be a Text (i.e. include emphasis)" |
416 The argument, aCollection can be a Text (i.e. include emphasis)" |
352 |
417 |
353 aCollection hasChangeOfEmphasis ifTrue:[ |
418 aCollection hasChangeOfEmphasis ifTrue:[ |
354 aCollection keysAndValuesDo:[:idx :aChar | |
419 aCollection keysAndValuesDo:[:idx :aChar | |
355 self emphasis:(aCollection emphasisAt:idx). |
420 self emphasis:(aCollection emphasisAt:idx). |
356 self nextPut:aChar. |
421 self nextPut:aChar. |
357 ]. |
422 ]. |
358 self normal. |
423 self normal. |
359 ] ifFalse:[ |
424 ] ifFalse:[ |
360 aCollection do:[:aChar | |
425 aCollection do:[:aChar | |
361 self nextPut:aChar |
426 self nextPut:aChar |
362 ] |
427 ] |
363 ] |
428 ] |
364 |
429 |
365 "Modified: 18.5.1996 / 09:43:45 / cg" |
430 "Modified: 18.5.1996 / 09:43:45 / cg" |
366 ! |
431 ! |
367 |
432 |
404 |
469 |
405 emphasis:anEmphasis |
470 emphasis:anEmphasis |
406 "change the emphasis" |
471 "change the emphasis" |
407 |
472 |
408 anEmphasis isNil ifTrue:[ |
473 anEmphasis isNil ifTrue:[ |
409 ^ self normal |
474 ^ self normal |
410 ]. |
475 ]. |
411 anEmphasis == #bold ifTrue:[ |
476 anEmphasis == #bold ifTrue:[ |
412 ^ self bold |
477 ^ self bold |
413 ]. |
478 ]. |
414 anEmphasis == #italic ifTrue:[ |
479 anEmphasis == #italic ifTrue:[ |
415 ^ self italic |
480 ^ self italic |
416 ]. |
481 ]. |
417 (anEmphasis = #(bold italic) |
482 (anEmphasis = #(bold italic) |
418 or:[anEmphasis = #(italic bold)]) ifTrue:[ |
483 or:[anEmphasis = #(italic bold)]) ifTrue:[ |
419 ^ self boldItalic |
484 ^ self boldItalic |
420 ]. |
485 ]. |
421 anEmphasis == #underline ifTrue:[ |
486 anEmphasis == #underline ifTrue:[ |
422 ^ self underline |
487 ^ self underline |
423 ]. |
488 ]. |
424 anEmphasis == #strikeout ifTrue:[ |
489 anEmphasis == #strikeout ifTrue:[ |
425 ^ self strikeout |
490 ^ self strikeout |
426 ]. |
491 ]. |
427 |
492 |
428 "Created: 14.5.1996 / 18:53:54 / cg" |
493 "Created: 14.5.1996 / 18:53:54 / cg" |
429 "Modified: 18.5.1996 / 09:42:49 / cg" |
494 "Modified: 18.5.1996 / 09:42:49 / cg" |
430 ! |
495 ! |