EpsonFX1PrinterStream.st
author Claus Gittinger <cg@exept.de>
Sat, 02 May 2020 21:40:13 +0200
changeset 5476 7355a4b11cb6
parent 5173 99246e219989
permissions -rw-r--r--
#FEATURE by cg class: Socket class added: #newTCPclientToHost:port:domain:domainOrder:withTimeout: changed: #newTCPclientToHost:port:domain:withTimeout:

"{ Encoding: utf8 }"

"
 COPYRIGHT (c) 1991 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.
"
"{ Package: 'stx:libbasic2' }"

"{ NameSpace: Smalltalk }"

PrinterStream subclass:#EpsonFX1PrinterStream
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:''
	category:'Interface-Printing'
!

!EpsonFX1PrinterStream class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 1991 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
"
    This class defines protocol for simple text printing on an Epson-FX1 printer
    (and compatibles, such as FX80, FX100, etc.). 
    It does not support multiple fonts, but knows how to print bold, italic etc.

    Graphics printing is not supported - you need a postscriptPrinter for this.

    I cannot tell, if this is really an Epson -
    all I had to test was a Citizen 120D - its documentation claims it to be 
    FX1 compatible.

    Notice: 
        This class only defines some minimum protocol for printing on
        Epsons - you really should use a PostscriptPrinter ...
        ... however, if you own an Epson, here is some class to start with.
        It may need to be enhanced at some places (for example: provide more
        fonts/emphasis's; better international character translation etc.)

    [Disclaimer:]    
        This class is not officially supported - take it or leave it.

    [Disclaimer2:]    
        This is more or less completely outdated (look at the creation date of this class !!).
        Left for historic (nostalgic?) reasons.
        Will be removed (or made autoloaded) in the future.

    [author:]
        Claus Gittinger
"
! !

!EpsonFX1PrinterStream class methodsFor:'initialization'!

initialize
    DefaultCommands := #('lpr' 
                         'lpr -P<your-printer>' 
                         'cat | rsh <printHost> lpr -h' 
                        ).
    super initialize

    "
     self initialize
    "
! !

!EpsonFX1PrinterStream class methodsFor:'queries'!

printerTypeName
    "return a descriptive name"

    ^ 'Epson FX1 compatible printer'
! !

!EpsonFX1PrinterStream methodsFor:'access-writing'!

cr
    "send a carriage return (newLine).
     We have to output cr-nl here"

    super nextPutUntranslated:(Character value:13).
    super nextPutUntranslated:(Character value:10).
    self spaces:self class leftMargin

    "Modified: 1.6.1996 / 00:13:39 / cg"
!

nextPut:aCharacter
    "send aCharacter to the printer.
     Catch special characters.
     Answer aCharacter.
     - currently only german umlauts are handled - If you own this type
       of printer and depend on it, add more translation here.
     See https://files.support.epson.com/pdf/fx100_/fx100_u1.pdf table6.2."

    |ascii xLation|

    ascii := aCharacter codePoint.
    (ascii < 128) ifTrue:[
        stream nextPut:aCharacter.
        ^ aCharacter.
    ].
    xLation := #(
                "/ german
                ($ä  ${ 2 )     "adiaeresis"
                ($ö  $| 2 )     "odiaeresis"
                ($ü  $} 2 )     "udiaeresis"
                ($Ä  $[ 2 )     "Adiaeresis"
                ($Ö  $\ 2 )     "Odiaeresis"
                ($Ü  $] 2 )     "Udiaeresis"
                ($ß  $~ 2 )     "ssharp"

                "/ france  
                ($à  $@ 1 )     "a-grave"
                ($é  ${ 1 )     "e-aigu"
                ($ú  $| 1 )     "u-aigu"
                ($è  ${ 1 )     "e-grave"
                ($ç  $\ 1 )     "c-cedille"

                "/ italy  
                ($ò  $| 6 )     "o-grave"
                ($ì  $~ 6 )     "i-grave"

                "/ spain  
                ($Ñ  $\ 7 )     "N-tilde"
                ($ñ  $| 7 )     "n-tilde"
                ($¿  $] 7 )     "question"

                "/ british  
                ($£  $# 3 )     "pound"
                "/ japan  
                ($¥  $\ 8 )     "Yen"
            ) detect:[:pair | pair first == aCharacter] ifNone:nil.

    xLation notNil ifTrue:[
        self character:(xLation second) fromCharacterSet:(xLation third)
    ].
    ^ aCharacter

    "Modified: 18.5.1996 / 09:03:18 / cg"
! !

!EpsonFX1PrinterStream methodsFor:'emphasis change'!

bold
    "set emphasis to bold"

    "send: <ESC>G "

    super escape:$G

    "Modified: 18.5.1996 / 09:03:31 / cg"
!

italic
    "set emphasis to italic"

    "send: <ESC>4 will do that"

    super escape:$4

    "Modified: 18.5.1996 / 09:03:33 / cg"
!

normal
    "set emphasis to normal"

    "send: <ESC>H<ESC>5"

    super escape:$H. super escape:$5

    "Modified: 18.5.1996 / 09:03:35 / cg"
! !

!EpsonFX1PrinterStream methodsFor:'layout'!

linesPerPage:n
    "change the lines-per-page setting"

    "send: <ESC>C<n>"

    super escape:$C.
    super nextPut:(Character value:n)

    "Modified: 18.5.1996 / 09:03:50 / cg"
!

newPage
    "force a newPage"

    super nextPut:(Character value:12)

    "Modified: 18.5.1996 / 09:04:04 / cg"
!

noTopMargin
    "turn off topMargin in the printer"

    "send <ESC>0"

    super escape:$O

    "Modified: 18.5.1996 / 09:04:19 / cg"
!

pageHeight:inches
    "set the pageHeight in inches"

    "send <ESC>G<0><inch>"

    super escape:$C.
    super nextPut:(Character value:0).
    super nextPut:(Character value:inches)

    "Modified: 18.5.1996 / 09:04:38 / cg"
!

proportional:aBoolean
    "turn on/off proportional printing"

    "send <ESC>p0 or <ESC>p1"

    super escape:$p.
    super nextPut:(aBoolean ifTrue:[$1] ifFalse:[$0])

    "Modified: 18.5.1996 / 09:05:18 / cg"
!

reset
    "reset the printer - send <ESC>@"

    super escape:$@

    "Modified: 18.5.1996 / 09:05:27 / cg"
!

topMargin:n
    "set the topMargin"

    "send <ESC>N<n>"

    super escape:$N.
    super nextPut:(Character value:n)

    "Modified: 18.5.1996 / 09:05:43 / cg"
! !

!EpsonFX1PrinterStream methodsFor:'private'!

character:char fromCharacterSet:set
    "send a character from an alternate character set"

    "send: <ESC>R<set><char><ESC>R<0>"

    super escape:$R.
    super nextPut:(Character value:set).
    super nextPut:char.
    super escape:$R.
    super nextPut:(Character value:0)
! !

!EpsonFX1PrinterStream class methodsFor:'documentation'!

version
    ^ '$Header$'
! !


EpsonFX1PrinterStream initialize!