PrinterStream.st
author Claus Gittinger <cg@exept.de>
Thu, 23 Nov 1995 02:51:57 +0100
changeset 126 fca9404da9d4
parent 112 3e18f2cfe430
child 139 edeec6741fc8
permissions -rw-r--r--
checkin from browser

"
 COPYRIGHT (c) 1990 by Claus Gittinger
	      All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"

PipeStream subclass:#PrinterStream
	 instanceVariableNames:''
	 classVariableNames:'PrintCommand LeftMargin'
	 poolDictionaries:''
	 category:'Streams-External'
!

!PrinterStream class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 1990 by Claus Gittinger
	      All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"
!

documentation
"
    a stream for printing; this (concrete or abstract) class can handle only
    very dumb printers. More intelligence is added by subclasses (see
    PostscriptPrinterStream among others.)
"
!

version
    ^ '$Header: /cvs/stx/stx/libbasic2/PrinterStream.st,v 1.12 1995-11-23 01:51:39 cg Exp $'
! !

!PrinterStream class methodsFor:'initialization'!

initialize
    "this is usually redefined by the startup-file"

    PrintCommand isNil ifTrue:[
	OperatingSystem isBSDlike ifTrue:[
	    PrintCommand := 'lpr'
	] ifFalse:[
	    PrintCommand := 'lp'
	]
    ].
    LeftMargin isNil ifTrue:[
	LeftMargin := 0
    ]
! !

!PrinterStream class methodsFor:'instance creation'!

new
    "return a new stream for printing"

    ^ self basicNew startPrint
! !

!PrinterStream class methodsFor:'accessing'!

leftMargin:aNumber
    "set the number of blanks for the left margin"

    LeftMargin := aNumber
!

printCommand
    "return the command for printing (usually lp or lpr)"

    ^ PrintCommand
!

printCommand:aString
    "set the command for printing (usually lp or lpr)"

    PrintCommand := aString
! !

!PrinterStream methodsFor:'access writing'!

bold
    "set font to bold
     - ignore here, since this class does not know anything about the printer"

    ^ self
!

courier
    "set font to courier 
     - ignore here, since this class does not know anything about the printer"

    ^ self
!

cr
    "send a carriage-return to the printer"

    super nextPut:(Character cr).
    self spaces:LeftMargin
!

helvetica
    "set font to helvetic
     - ignore here, since this class does not know anything about the printer"

    ^ self
!

italic
    "set font to italic
     - ignore here, since this class does not know anything about the printer"

    ^ self
!

lineLength
    "the printer pages width (in characters)"

    ^ 80
!

nextPut:aCharacter
    "send some characters to the printer - translate as needed"

    (aCharacter == Character cr) ifTrue:[
	super nextPut:(Character cr).
	self spaces:LeftMargin
    ] ifFalse:[
	super nextPut:aCharacter
    ]
!

nextPutAll:aCollection
    "send some characters to the printer - translate as needed"

    aCollection do:[:aChar |
	self nextPut:aChar
    ]
!

nextPutAllUntranslated:aCollection
    "send some raw characters to the printer"

    super nextPutAll:aCollection
!

nextPutUntranslated:aCharacter
    "send a raw character to the printer"

    super nextPut:aCharacter
!

normal
    "set font to normal (non-bold, non-italic)
     - ignore here, since this class does not know anything about the printer"

    ^ self
!

spaces:aNumber
    "send some spaces to the printer"

    aNumber timesRepeat:[
	super nextPut:(Character space)
    ]
!

times
    "set font to times 
     - ignore here, since this class does not know anything about the printer"

    ^ self
! !

!PrinterStream methodsFor:'open/close'!

close
    self endPrint.
    super close
!

endPrint
    ^ self
!

startPrint
    super writingTo:PrintCommand.
    self spaces:LeftMargin
! !

PrinterStream initialize!