
ReadWriteStream subclass: #FileStream
  instanceVariableNames: 
    'file pageStart writtenOn lastByte lineDelimiter '
  classVariableNames: ''
  poolDictionaries: 
    'CharacterConstants ' !

!FileStream class methods ! !


!FileStream methods !

atEnd
        "Answer true if the receiver is positioned at the
         end (beyond the last object), else answer false."
    (position < readLimit or:
        [(pageStart + position) <= self updateLastByte])
            ifTrue: [^false]
            ifFalse:[^true]!

bootTransputer
   | byte |
   byte:=0.
   [self atEnd]
     whileFalse: [self sendToTrans: ((self next) asciiValue).
                  "Cursor offset:(100@100).
                  byte printOn: Terminal.
                  byte:=byte+1."
                 ].
   self close!

close
        "Close the file associated with the receiver stream
         after writing all the data to the file."
    self readLimit.
    self writePage.
    file close!

compareWith:aFileStream
   | reportPane pos ok|
 reportPane:=TextEditor windowLabeled:'Compareing files'
                         frame:(0@0 extent:300@100) .

  pos:=0.ok:=false.
  self size = aFileStream size
  ifTrue:
 [ ok:=true.
  [((self atEnd or:[aFileStream atEnd]) not)
       & ok] whileTrue:
     [self next = aFileStream next
        ifTrue:[pos:=pos+1]
        ifFalse:[ok:=false.
                 reportPane nextPutAll:'no match at: ';
                      nextPutAll:(pos radix: 10);cr
                ]
     ]
  ].
  ok ifTrue:[ reportPane nextPutAll:'compleate match length: ';
                      nextPutAll:(pos radix: 10);cr]
     ifFalse:[ reportPane nextPutAll:'no match ';
                      nextPutAll:(pos radix: 10);cr].
  ^ok!

copyFrom: first to: last
        "Answer a String containing the characters of the
         receiver stream from positions first to last."
    | string savePosition index putIndex number size |
    string := collection species new: last - first + 1.
    savePosition := self position.
    size := file size.
    putIndex := 1.
    index := first.
    [index <= last]
        whileTrue: [
            index > size
                ifTrue: [^self error: 'copy beyond end of file'].
            self position: index - 1.
            number := (last min: pageStart + readLimit - 1)
                - index + 1.
            string
                replaceFrom: putIndex
                to: putIndex + number - 1
                with: collection
                startingAt: position + 1.
            putIndex := putIndex + number.
            index := index + number].
    self position: savePosition.
    ^string!

copyFrom: first to: last into: aByteObject
        "Copy the characters of the receiver stream
         from positions first to last into an object
         containing bytes."
    | string savePosition index putIndex number size |
    string := collection species new: last - first + 1.
    savePosition := self position.
    size := file size.
    putIndex := 1.
    index := first.
    [index <= last]
        whileTrue: [
            index > size
                ifTrue: [^self error: 'copy beyond end of file'].
            self position: index - 1.
            number := (last min: pageStart + readLimit - 1)
                - index + 1.
            aByteObject
                replaceFrom: putIndex
                to: putIndex + number - 1
                with: collection
                startingAt: position + 1.
            putIndex := putIndex + number.
            position := position + number.
            index := index + number]!

cr
        "Write the line terminating character
         (carriage-return line-feed pair or
         line-feed) to the receiver stream."
    self lineDelimiter == Cr
        ifTrue: [self nextPut: Cr].
    self nextPut: Lf!

dotakeItsBitmapInPostScript: aFormPiece
   | byte length aChar data theBytewidth lastusedByte
      index data aForm aRectangle bitsPerPixel|
   aRectangle:=aFormPiece rectangle.
   aForm:=aFormPiece form.
   bitsPerPixel:= aFormPiece bitsPerPixel.
   byte:=0.

   theBytewidth:=((aForm width+15)//16)*2 .
   lastusedByte:=(aForm width +(-1))//8+1.
   length:=(aForm height)* theBytewidth.
   self nextPutAll: 'gsave'.
     self nextPut:(13 asCharacter). self nextPut:(10 asCharacter).

   ((aRectangle origin x) * 18//10+20) printOn:self.self nextPut:(32 asCharacter).
     (400-(aRectangle origin y)-(aRectangle extent y)) * 22//10
          printOn:self.
      self nextPutAll: ' translate ' .
      self nextPut:(13 asCharacter). self nextPut:(10 asCharacter).


    ((aRectangle extent x)*18//10) printOn:self.self nextPut:(32 asCharacter).
       ((aRectangle extent y)*22//10) printOn:self.
       self nextPutAll:' scale' .
       self nextPut:(13 asCharacter). self nextPut:(10 asCharacter).
   ((aForm width)// bitsPerPixel ) printOn:self.self nextPut:(32 asCharacter).
     (aForm height) printOn:self.self nextPut:(32 asCharacter).
      bitsPerPixel printOn:self.
         self nextPut:(13 asCharacter). self nextPut:(10 asCharacter).
   self nextPut: $[.
                    ((aForm width)//bitsPerPixel) printOn:self.self nextPutAll:' 0 0 '.
                    (0-(aForm height)) printOn:self.self nextPutAll:' 0 '.
                      (aForm height) printOn:self.
   self nextPut: $].
       self nextPut:(13 asCharacter).self nextPut:(10 asCharacter).
    self nextPutAll:'{currentfile picstr readhexstring pop} image'.
       self nextPut:(13 asCharacter). self nextPut:(10 asCharacter).

   1 to: aForm height do:
   [ :row |
    1 to: lastusedByte do:
     [: col  |
                 index:=col+ ((row+(-1))*theBytewidth).

                  data:=(aForm bitmap at: index).
                  aChar:=(data//16)+48.
                  58<=aChar ifTrue: [aChar:=aChar+7].
                  self nextPut: (aChar asCharacter).
                  aChar:=(data\\16)+48.
                  58<=aChar  ifTrue: [aChar:=aChar+7].
                  self nextPut: (aChar asCharacter).
                  byte:=byte+1.
                  (byte\\32)=0
                     ifTrue: [ self nextPut:(13 asCharacter).
                               self nextPut:(10 asCharacter).
                             ]
     ].

    ].
     [(byte\\256)~=0]
    whileTrue: [
                aChar:=48.

                self nextPut: (aChar asCharacter).
                self nextPut: (aChar asCharacter).
                byte:=byte+1.
                  (byte\\32)=0
                    ifTrue: [ self nextPut:(13 asCharacter).
                              self nextPut:(10 asCharacter).
                            ]
               ].
   self nextPutAll:'% endOfbitmap'.
   self nextPut:(13 asCharacter).
     self nextPut:(10 asCharacter).
   self nextPutAll: 'grestore'.
    self nextPut:(13 asCharacter). self nextPut:(10 asCharacter).!

dotakeItsCurveInPostScript: aCurvePiece
   | aChar data  index aRectangle numCurves aCurve width height curveOrigin|

   aRectangle:=aCurvePiece rectangle.
   numCurves:=aCurvePiece size.
   self nextPutAll: 'gsave'.
     self nextPut:(13 asCharacter). self nextPut:(10 asCharacter).

   ((aRectangle origin x) * 18//10+20) printOn:self.self nextPut:(32 asCharacter).
     (400-(aRectangle origin y)) * 22//10
          printOn:self.
      self nextPutAll: ' translate ' .
      self nextPut:(13 asCharacter). self nextPut:(10 asCharacter).
      self nextPut:(13 asCharacter). self nextPut:(10 asCharacter).
    width:= aRectangle extent x  asFloat*1.8.
    height:=aRectangle extent y asFloat*2.2.

  1 to:numCurves do:
  [ :i |  self nextPutAll:' gsave ' .

      aCurve:= aCurvePiece  aCurve.
       width /( aCurve baseRectangle extent x asFloat) printOnCh:self.self nextPut:(32 asCharacter).
       height/( aCurve baseRectangle extent y asFloat negated) printOnCh:self.
       self nextPutAll:' scale '.
      (aCurve at:1) x printOnCh:self.self nextPut:(32 asCharacter).
          (aCurve at:1) y   printOnCh:self.
          self nextPutAll:' moveto '.
      self nextPut:(13 asCharacter). self nextPut:(10 asCharacter).
     aCurve type isNil
      ifTrue:
     [
      2 to:aCurve size do:
        [ :j |
          (aCurve at:j) x printOnCh:self.self nextPut:(32 asCharacter).
          (aCurve at:j) y  printOnCh:self.
          self nextPutAll:' lineto '.
          self nextPut:(13 asCharacter). self nextPut:(10 asCharacter).
        ]. self nextPutAll:' stroke '.
     ]
      ifFalse:
     [
       2 to:(aCurve size+(-1))//3 *3+1 do:
        [ :j |
          (aCurve at:j) x printOnCh:self.self nextPut:(32 asCharacter).
          (aCurve at:j) y  printOnCh:self.self nextPut:(32 asCharacter).
          (j+(-1) \\ 3)=0
           ifTrue:
             [ self nextPutAll:' curveto '.
               self nextPut:(13 asCharacter). self nextPut:(10 asCharacter).
             ].
        ].

        self nextPutAll:' stroke '.
     ].
     self nextPutAll: 'grestore'.
     self nextPut:(13 asCharacter). self nextPut:(10 asCharacter).
     self nextPut:(13 asCharacter). self nextPut:(10 asCharacter).
  ].
   self nextPutAll:'% endOfCurve'.
   self nextPut:(13 asCharacter).
     self nextPut:(10 asCharacter).
   self nextPutAll: 'grestore'.
    self nextPut:(13 asCharacter). self nextPut:(10 asCharacter).!

dotakeItsTextInPostScript: aTextPiece
   | byte length aChar data theBytewidth theByteheight lastusedByte
      index data aRectangle  aText aFile aName i aLine anEscape
        fontWidth fontHeight upperLeftx upperLefty currentLefty
        fontWidthInit fontHeightInit goon currentFont
        theFonts numS fontScale fontDisp operator oldOperator extended
      asciich comment charactersArePrinted bracketed streamStack|

   theFonts:= A4PaperArc postScriptFonts.

   goon:=true.
   anEscape:=false.
   bracketed:=false.

   fontScale:=6.
   fontDisp:=6.

   operator:=0.
   oldOperator:=0.

   streamStack:=OrderedCollection new.

   aRectangle:= aTextPiece  rectangle.
   theByteheight:=1.
   i:=1.
   aText:=  aTextPiece text.
   theBytewidth:=aText size .
   (aText at:1) == $!!
    ifTrue:[
             aName:='                          '.
             aText do:[:ch | ch=$!! ifFalse:[ aName at:i put:ch.i:=i+1]].
             aFile := (File pathName:aName).
           ]
    ifFalse:[
              aFile:=ReadStream on:aText.
            ].
    aFile isNil
      ifFalse:[
         theBytewidth:= aFile nextLine size.

          i:=1."theBytewidth:=1."
          [aFile atEnd]
             whileFalse:[ aLine:=aFile nextLine .
                aLine isNil
                   ifFalse:[ numS:=0.
                         aLine do:[:ch | ch=$# ifTrue:[numS:=numS+2].
                                         ch=$& ifTrue:[numS:=numS+1]
                                  ].
                         "theBytewidth:=
                           (aLine size -numS)
                             max:theBytewidth"
                           ].
                          i:=i+1
                        ].
              theByteheight:=i.
              ].


   " theBytewidth:=    20. "
   byte:=0.
   self nextPutAll: 'gsave'.
     self nextPut:(13 asCharacter). self nextPut:(10 asCharacter).
   fontWidth:=fontWidthInit:= (aRectangle extent x)*4 // theBytewidth.
   fontHeight:=fontHeightInit:= (aRectangle extent y)*22 // (theByteheight*10).
   upperLeftx:=  ((aRectangle origin x) * 18//10+20).
   upperLefty:= (400-(aRectangle origin y))*22//10.
   currentLefty:=upperLefty-fontHeight.
   currentFont:=aTextPiece font.

   upperLeftx printOn:self.self nextPut:(32 asCharacter).
      currentLefty printOn:self.
     self nextPutAll: ' moveto' .
      self nextPut:(13 asCharacter). self nextPut:(10 asCharacter).

   self setFontLabel:'F001' font:currentFont
       width:fontWidth
       height: fontHeight .
   charactersArePrinted:=false.

  aFile reset.aFile nextLine.
  [ aFile isNil]
    whileFalse:
  [
    [aFile atEnd ]
     whileFalse:
     [ comment:=false.
        aFile nextLine

          do:[:ch |
          comment
          ifFalse:
          [
          goon
           ifTrue:
          [
              anEscape
              ifTrue:[anEscape:=false.
                      charactersArePrinted
                        ifFalse:[  self nextPut:($().
                                  charactersArePrinted:=true].
                      self nextPut:ch.
                     ]
              ifFalse:
           [
             " ch=$^
               ifTrue:[ streamStack addLast aFile.
                       aFile:=ReadStream on:'christer'
                      ]. "

              ch=$\
              ifFalse:
              [
               (ch=$# )
                ifTrue:[  charactersArePrinted
                          ifTrue:
                            [self nextPutAll:')show '].
                          charactersArePrinted :=false.
                         goon:=false.extended:=false
                       ]
                ifFalse:[
                         ch=$&
                          ifTrue:
                          [  goon:=false.extended:=true]
                          ifFalse:
                          [
                            ch=$%
                             ifTrue:[comment:=true]
                             ifFalse:[
                                   charactersArePrinted
                                     ifFalse:[  self nextPut:($().
                                       charactersArePrinted:=true].
                            ( ch=$( or: [ch=$) or:[ch=$\]])
                              ifTrue:[self nextPut:$\].
                              self nextPut:ch
                                     ]
                          ]
                        ]
               ]
               ifTrue:[ anEscape:=true]
             ]
            ]
           ifFalse:
            [
              oldOperator:=operator.operator:=0.
              extended
              ifTrue:[ asciich:=(ch asciiValue)+128.
                       charactersArePrinted
                          ifFalse:[  self nextPut:($().
                             charactersArePrinted:=true].
                       self nextPutAll:' \'.
                       self nextPut:( (asciich // 64 +48) asCharacter).
                       self nextPut:( (asciich \\ 64 // 8+48 )asCharacter).
                       self nextPut:(( asciich \\  8+48 )asCharacter).
                     ]
              ifFalse:
              [
                ch=$z
                ifTrue:[
                ((aRectangle extent x)  asFloat / 200.0) printOn:self.self nextPut:(32 asCharacter).
       ((aRectangle extent y) asFloat / 200.0) printOn:self.
       self nextPutAll:' scale' .
       self nextPut:(13 asCharacter). self nextPut:(10 asCharacter).
                       ].
               ch=$(
                ifTrue:[
                         bracketed:=true
                       ].
                ch=$)
                ifTrue:[
                         bracketed:=false
                       ].
              ch=$p
                ifTrue:[ self nextPut:$ .
                         oldOperator printOn:self.
                         self nextPut:$ .
                       ].
                ch=$g
                ifTrue:[
                         self nextPutAll: ' gsave '.
                       ].
                ch=$h
                ifTrue:[
                         self nextPutAll: ' grestore '.
                       ].
               ch=$n
                ifTrue:[
                         operator := oldOperator negated
                       ].
               ch=$t
                ifTrue:[
                         self nextPutAll: ' translate '.
                       ].
              ch=$s
                ifTrue:[
                         self nextPutAll: ' currentpoint '.
                       ].
               ch=$r
                ifTrue:[
                         self nextPutAll: ' moveto ' .
                       ].
                ch=$c
                ifTrue:[
                         self nextPutAll: ' curveto  '.
                       ].
                 ch=$f
                ifTrue:[
                         self nextPutAll: ' stroke  '.
                       ].
                ch=$l
                ifTrue:[
                          self nextPutAll: ' lineto  ' .
                       ].
               ch=$d
                 ifTrue:[
                           oldOperator=0
                            ifFalse:[fontDisp:=oldOperator].
                           0 printOn:self.self nextPut:(32 asCharacter).
                           fontHeight*fontDisp // 10 negated printOn:self.
                           self nextPutAll: ' rmoveto' .
                       ].
               ch=$+
                ifTrue:[
                           oldOperator=0
                            ifFalse:[fontDisp:=oldOperator].
                           fontWidth*fontDisp // 10 printOn:self.self nextPut:(32 asCharacter).
                           0 printOn:self.
                           self nextPutAll: ' rmoveto' .
                       ].
                ch=$u
                ifTrue:[
                           oldOperator=0
                            ifFalse:[fontDisp:=oldOperator].
                           0 printOn:self.self nextPut:(32 asCharacter).
                           fontHeight *fontDisp// 10 printOn:self.
                           self nextPutAll: ' rmoveto' .
                       ].
                ch=$-
                ifTrue:[
                           oldOperator=0
                            ifFalse:[fontDisp:=oldOperator].
                           0 printOn:self.self nextPut:(32 asCharacter).
                           fontWidth*fontDisp // 10 negated printOn:self.
                           self nextPutAll: ' rmoveto' .
                       ].
              ch=$*
                ifTrue:[
                          oldOperator=0
                           ifFalse:[fontScale:=oldOperator].
                          fontWidth:=fontWidth*fontScale//10.
                          fontHeight:=fontHeight*fontScale//10.
                         self setFontLabel:'F002' font:currentFont
                           width: fontWidth
                           height: fontHeight

                       ].
              ch=$/
                ifTrue:[
                          oldOperator=0
                           ifFalse:[fontScale:=oldOperator].
                          fontWidth:=fontWidth*fontScale//10.
                          fontHeight:=fontHeight*fontScale//10.
                         self setFontLabel:'F002' font:currentFont
                           width: fontWidth
                           height: fontHeight

                       ].

              ch isDigit
                ifTrue: [ operator:=oldOperator*10+(ch digitValue)].

              (ch >= $A and:[ ch <= $M])
                ifTrue:[ currentFont :=theFonts at:(ch asciiValue +(-64)).
                         self setFontLabel:'F002' font:currentFont
                           width: fontWidth
                           height: fontHeight
                       ].
              ch=$$ 
                 ifTrue:[
                     fontWidth:=fontWidthInit.
                     fontHeight:=fontHeightInit.
                     currentFont:=aTextPiece font.
                     self setFontLabel:'F001' font:currentFont
                                          width:fontWidth
                                          height:  fontHeight.
                     self nextPutAll: ' currentpoint pop ' .
                     self nextPut:(32 asCharacter).
                     currentLefty printOn:self.
                     self nextPutAll: ' moveto' .
                         ].
             " self nextPut:($() "
              ].
            bracketed
             ifFalse:
              [goon:=true]
            ]
            ]
              ].
        charactersArePrinted
        ifTrue:[
             self nextPutAll:')show '.
              charactersArePrinted  := false
               ].
         self nextPut:(13 asCharacter). self nextPut:(10 asCharacter).
        currentLefty:=currentLefty-fontHeight.
        bracketed
        ifFalse:[
          upperLeftx printOn:self.self nextPut:(32 asCharacter).
           currentLefty printOn:self.
           self nextPutAll: ' moveto' .
           self nextPut:(13 asCharacter). self nextPut:(10 asCharacter)
                ]
     ].
   streamStack isEmpty
    ifFalse:[aFile:=streamStack removeLast]
    ifTrue:[aFile:=nil]
  ].
   self nextPutAll:'% endOftext'.
   self nextPut:(13 asCharacter).
     self nextPut:(10 asCharacter).
   self nextPutAll: 'grestore'.
    self nextPut:(13 asCharacter). self nextPut:(10 asCharacter).!

dotakeItsTextInPostScriptNaked: aTextPiece
   | byte length aChar data theBytewidth theByteheight lastusedByte
      index data aRectangle  aText aFile aName i aLine anEscape
        fontWidth fontHeight upperLeftx upperLefty currentLefty
        fontWidthInit fontHeightInit goon currentFont
        theFonts numS fontScale fontDisp operator oldOperator extended
      asciich comment charactersArePrinted bracketed streamStack|

   theFonts:= A4PaperArc postScriptFonts.

   goon:=true.
   anEscape:=false.
   bracketed:=false.

   fontScale:=6.
   fontDisp:=6.

   operator:=0.
   oldOperator:=0.

   streamStack:=OrderedCollection new.

   aRectangle:= aTextPiece  rectangle.
   theByteheight:=1.
   i:=1.
   aText:=  aTextPiece text.
   theBytewidth:=aText size .
   (aText at:1) == $!!
    ifTrue:[
             aName:='                          '.
             aText do:[:ch | ch=$!! ifFalse:[ aName at:i put:ch.i:=i+1]].
             aFile := (File pathName:aName).
           ]
    ifFalse:[
              aFile:=ReadStream on:aText.
            ].
    aFile isNil
      ifFalse:[
         theBytewidth:= aFile nextLine size.

          i:=1."theBytewidth:=1."
          [aFile atEnd]
             whileFalse:[ aLine:=aFile nextLine .
                aLine isNil
                   ifFalse:[ numS:=0.
                         aLine do:[:ch | ch=$# ifTrue:[numS:=numS+2].
                                         ch=$& ifTrue:[numS:=numS+1]
                                  ].
                         "theBytewidth:=
                           (aLine size -numS)
                             max:theBytewidth"
                           ].
                          i:=i+1
                        ].
              theByteheight:=i.
              ].


   " theBytewidth:=    20. "
   byte:=0.
   self nextPutAll: 'gsave'.
     self nextPut:(13 asCharacter). self nextPut:(10 asCharacter).
   fontWidth:=fontWidthInit:= (aRectangle extent x)*4 // theBytewidth.
   fontHeight:=fontHeightInit:= (aRectangle extent y)*22 // (theByteheight*10).
   upperLeftx:=  ((aRectangle origin x) * 18//10+20).
   upperLefty:= (400-(aRectangle origin y))*22//10.
   currentLefty:=upperLefty-fontHeight.
   currentFont:=aTextPiece font.


  self nextPutAll:'/leftX '.upperLeftx printOn:self.
  self nextPutAll:' def /curY '.currentLefty printOn:self.
        self nextPutAll:' def';cr.

  self nextPutAll:'/newLine {leftX /curY curY dy sub def curY moveto}';cr.
  self nextPutAll:'/dx '.fontWidth printOn:self.
  self nextPutAll:' def /dy '.fontHeight printOn:self.
        self nextPutAll:' def';cr.
  self nextPutAll:'/setFontArray {/fontArry dx dy 0 0 0 0 6 astore def} '.
  self nextPutAll:'/baseFont /'.
  self nextPutAll:aTextPiece font.
  self nextPutAll:' findfont def'.
  self nextPut:(13 asCharacter). self nextPut:(10 asCharacter).
  self nextPutAll:'/baseFont fontArray'.
  self nextPutAll:' makefont setfont'.
  self nextPut:(13 asCharacter). self nextPut:(10 asCharacter).

  upperLeftx printOn:self.self nextPut:(32 asCharacter).
      currentLefty printOn:self.
     self nextPutAll: ' moveto' .
      self nextPut:(13 asCharacter). self nextPut:(10 asCharacter).

   charactersArePrinted:=false.

  aFile reset.aFile nextLine.
  [ aFile isNil]
    whileFalse:
  [
    [aFile atEnd ]
     whileFalse:
     [ comment:=false.
        aFile nextLine

          do:[:ch |
          comment
          ifFalse:
          [
          goon
           ifTrue:
          [
              anEscape
              ifTrue:[anEscape:=false.
                      charactersArePrinted
                        ifFalse:[  self nextPut:($().
                                  charactersArePrinted:=true].
                      self nextPut:ch.
                     ]
              ifFalse:
           [
              ch=$\
              ifFalse:
              [
               (ch=$# )
                ifTrue:[  charactersArePrinted
                          ifTrue:
                            [self nextPutAll:')show '].
                          charactersArePrinted :=false.
                         goon:=false.extended:=false
                       ]
                ifFalse:[
                         ch=$%
                          ifTrue:[comment:=true]
                          ifFalse:[
                                   charactersArePrinted
                                     ifFalse:[  self nextPut:($().
                                       charactersArePrinted:=true].
                            ( ch=$( or: [ch=$) or:[ch=$\]])
                              ifTrue:[self nextPut:$\].
                              self nextPut:ch
                                 ]
                        ]
               ]
               ifTrue:[ anEscape:=true]
             ]
            ]
           ifFalse:
            [ ch=$#
               ifTrue:[goon:=true]
               ifFalse:[self nextPut:ch]
            ]
            ]
              ].
        charactersArePrinted
        ifTrue:[
             self nextPutAll:')show '.
              charactersArePrinted  := false
               ].
         self nextPut:(13 asCharacter). self nextPut:(10 asCharacter).
        currentLefty:=currentLefty-fontHeight.
        goon
        ifTrue:[
           self nextPutAll: ' newLine';cr
                ]
     ].
   streamStack isEmpty
    ifFalse:[aFile:=streamStack removeLast]
    ifTrue:[aFile:=nil]
  ].
   self nextPutAll:'% endOftext'.
   self nextPut:(13 asCharacter).
     self nextPut:(10 asCharacter).
   self nextPutAll: 'grestore'.
    self nextPut:(13 asCharacter). self nextPut:(10 asCharacter).!

file
        "Answer the file over which the receiver is
         streaming."
    ^file!

fillItsBitmap: aForm
   | byte length fileLength aChar itsWidth itsHeight|
   byte:=1.
   length:=((aForm height)* (aForm width))
                     / 8.
   aChar:=(self next).
   fileLength:= aChar asciiValue +(((self next) asciiValue)*256).
   aChar:=(self next).
   itsWidth :=aChar asciiValue +(((self next) asciiValue)*256).
   aChar:=(self next).
   itsHeight :=aChar asciiValue +(((self next) asciiValue)*256).
   aForm width:itsWidth height: itsHeight.
   [(self atEnd) or: [byte=(length+1)] ]
     whileFalse: [aForm bitmap at:byte put:
                  ((self next) asciiValue).
                  byte:=byte+1.
                 ].
   self close!

fillItsBitmapFromMW
   | byte byteTot length fileLength aChar itsWidth itsHeight aForm aFormStack|
   byteTot:=1.

   aFormStack:=OrderedCollection new.
   1 to:4 do:[:i | self next].

   aChar:=(self next).
   itsWidth :=aChar asciiValue +(((self next) asciiValue)*256).
   aChar:=(self next).
   itsHeight :=aChar asciiValue +(((self next) asciiValue)*256).
   9 to:32 do: [:i | self next].

   [itsHeight=0]
     whileFalse: [    byte:=1.
                 aForm :=Form width:itsWidth height: (itsHeight min:400).
                 length:=(aForm height)* (aForm width)
                     / 8.
                 itsHeight:=(itsHeight - (itsHeight min:400)).
                 [(self atEnd) or: [byte=(length+1)] ]
                 whileFalse: [aForm bitmap at:byte put:
                  ((self next) asciiValue).
                  byte:=byte+1.byteTot:=byteTot+1.
                 ].
                   aFormStack addLast:aForm
                ].
   self close.
   ^aFormStack!

fillItsBitmapFromPCX
   | bByte  aByte  byte byteTot length fileLength aChar
     itsWidth itsHeight aForm aFormStack |

   byteTot:=1.

   aFormStack:=OrderedCollection new.
   1 to:4 do:[:i | self next].

   aChar:=(self next).
   itsWidth :=aChar asciiValue +(((self next) asciiValue)*256).
   aChar:=(self next).
   itsHeight :=aChar asciiValue +(((self next) asciiValue)*256).
   aChar:=(self next).
   itsWidth :=aChar asciiValue +(((self next) asciiValue)*256)-itsWidth.
   aChar:=(self next).
   itsHeight :=aChar asciiValue +(((self next) asciiValue)*256)-itsHeight.
   13 to:128 do: [:i | self next].

   [itsHeight=0]
     whileFalse: [    byte:=1.
                 aForm :=Form width:itsWidth height: (itsHeight ).
                 length:=(aForm height)* (((aForm width+15)//16)*16)
                     / 8.
                 itsHeight:=(itsHeight - (itsHeight )).
                 [(self atEnd) or: [(length)<byte] ]
                 whileFalse: [
                   aByte:=(self next) asciiValue.
                   (aByte//64)=3
                   ifTrue:[ bByte:= (self next) asciiValue.
                           1 to:(aByte\\64) do:
                                 [:i| aForm bitmap at:byte put:bByte.
                                      byte:=byte+1.byteTot:=byteTot+1.
                                 ]
                          ]
                   ifFalse:[ aForm bitmap at:byte put:aByte.
                             byte:=byte+1.byteTot:=byteTot+1.
                           ].
                             ].
                   aFormStack addLast:aForm
                ].
   self close.
   ^aFormStack!

flush
        "Guarantee that any writes to the receiver stream
         are physically recorded on disk."
    | position |
    position := self position.
    self
        setToEnd;
        readLimit;
        writePage.
    file flush.
    self position: position!

formFromSelf
   | byte length fileLength aChar itsWidth itsHeight aForm bigForm aByte|
   byte:=1.
   bigForm:=Form width:2048 height:200.
   0 to:3 do:
 [:i |

   aChar:=(self next).
   fileLength:= aChar asciiValue +(((self next) asciiValue)*256)*2+(-4).
   aChar:=(self next).
   itsWidth :=aChar asciiValue +(((self next) asciiValue)*256)*4.
   aChar:=(self next).
   itsHeight :=aChar asciiValue +(((self next) asciiValue)*256).
   aForm := Form width:itsWidth height: itsHeight.
   length:=((aForm height)* (aForm width))
                     / 8.

   1 to:length do:[:j|
                  aByte:=(self next) asciiValue.
                  aByte:=(aByte \\ 16 )*16+(aByte//16).
                  aForm bitmap at:j put:aByte.
                  ].
   1 to:( fileLength-length) do:[:j| (self next)].
   bigForm copy: (0@0 extent:(512@200)) from:aForm  to:(i*512)@0 rule:3
  ].
   ^bigForm!

forMutoGraph: aForm pixelSize:bitsPerPixel place: aPoint number:anInteger
   | byte length aChar data theBytewidth lastusedByte
      index data aForm bitsPerPixel|



   byte:=0.

   theBytewidth:=((aForm width+15)//16)*2 .
   lastusedByte:=(aForm width +(-1))//8+1.
   length:=(aForm height)* theBytewidth.
   self nextPutAll: 'gsave'.
     self nextPut:(13 asCharacter). self nextPut:(10 asCharacter).

   aPoint x  printOn:self.self nextPut:(32 asCharacter).
   (aPoint y + 252) printOn:self.
      self nextPutAll: ' translate ' .
      self nextPut:(13 asCharacter). self nextPut:(10 asCharacter).


    ((216)) printOn:self.self nextPut:(32 asCharacter).
       ((144)) printOn:self.
       self nextPutAll:' scale' .
       self nextPut:(13 asCharacter). self nextPut:(10 asCharacter).
   ((aForm width)// bitsPerPixel ) printOn:self.self nextPut:(32 asCharacter).
     (aForm height) printOn:self.self nextPut:(32 asCharacter).
      bitsPerPixel printOn:self.
         self nextPut:(13 asCharacter). self nextPut:(10 asCharacter).
   self nextPut: $[.
                    ((aForm width)//bitsPerPixel) printOn:self.self nextPutAll:' 0 0 '.
                    (0-(aForm height)) printOn:self.self nextPutAll:' 0 '.
                      (aForm height) printOn:self.
   self nextPut: $].
       self nextPut:(13 asCharacter).self nextPut:(10 asCharacter).
    self nextPutAll:'{currentfile picstr readhexstring pop} image'.
       self nextPut:(13 asCharacter). self nextPut:(10 asCharacter).

   1 to: aForm height do:
   [ :row |
    1 to: lastusedByte do:
     [: col  |
                 index:=col+ ((row+(-1))*theBytewidth).

                  data:=(aForm bitmap at: index).
                  aChar:=(data//16)+48.
                  58<=aChar ifTrue: [aChar:=aChar+7].
                  self nextPut: (aChar asCharacter).
                  aChar:=(data\\16)+48.
                  58<=aChar  ifTrue: [aChar:=aChar+7].
                  self nextPut: (aChar asCharacter).
                  byte:=byte+1.
                  (byte\\32)=0
                     ifTrue: [ self nextPut:(13 asCharacter).
                               self nextPut:(10 asCharacter).
                             ]
     ].

    ].
     [(byte\\256)~=0]
    whileTrue: [
                aChar:=48.

                self nextPut: (aChar asCharacter).
                self nextPut: (aChar asCharacter).
                byte:=byte+1.
                  (byte\\32)=0
                    ifTrue: [ self nextPut:(13 asCharacter).
                              self nextPut:(10 asCharacter).
                            ]
               ].
   self nextPutAll:'% endOfbitmap'.
   self nextPut:(13 asCharacter).
     self nextPut:(10 asCharacter).
   self nextPutAll: 'grestore'.
    self nextPut:(13 asCharacter). self nextPut:(10 asCharacter).

   self nextPutAll:'gsave';nextPut:(13 asCharacter).
        aPoint x printOn:self.self nextPut:(32 asCharacter).
        (aPoint y +20) printOn:self.
   self nextPut:(13 asCharacter);
        nextPutAll:'moveto';nextPut:(13 asCharacter);
        nextPutAll:'/F001 /Timnes-Roman findfont def';nextPut:(13 asCharacter);
        nextPutAll:'F001[36 0 0 20 0 0]';nextPut:(13 asCharacter);
        nextPutAll:'makefont setfont';nextPut:(13 asCharacter);
        nextPut:$(.
        anInteger printOn:self.
   self nextPut:$);
        nextPutAll:' show';nextPut:(13 asCharacter);
        nextPutAll:'grestore';nextPut:(13 asCharacter).!

forMutoGraphaCurve: aCurveCollection  place: aPoint number:anInteger

   | aChar data aRectangle index numCurves aCurve width height curveOrigin|
   numCurves:=aCurveCollection size.
   self nextPutAll: 'gsave'.
     self nextPut:(13 asCharacter). self nextPut:(10 asCharacter).

   (aPoint x) printOn:self.self nextPut:(32 asCharacter).
     (aPoint y + 396)   printOn:self.
      self nextPutAll: ' translate ' .
      self nextPut:(13 asCharacter). self nextPut:(10 asCharacter).
      self nextPut:(13 asCharacter). self nextPut:(10 asCharacter).
    width:= 216.0.
    height:=144.0.

  1 to:numCurves do:
  [ :i |  self nextPutAll:' gsave ' .

      aCurve:= aCurveCollection at:i.
       width /( aCurve baseRectangle extent x asFloat) printOnCh:self.self nextPut:(32 asCharacter).
       height/( aCurve baseRectangle extent y asFloat negated) printOnCh:self.
       self nextPutAll:' scale '.
      (aCurve at:1) x printOnCh:self.self nextPut:(32 asCharacter).
          (aCurve at:1) y   printOnCh:self.
          self nextPutAll:' moveto '.
      self nextPut:(13 asCharacter). self nextPut:(10 asCharacter).
     aCurve type isNil
      ifTrue:
     [
      2 to:aCurve size do:
        [ :j |
          (aCurve at:j) x printOnCh:self.self nextPut:(32 asCharacter).
          (aCurve at:j) y  printOnCh:self.
          self nextPutAll:' lineto '.
          self nextPut:(13 asCharacter). self nextPut:(10 asCharacter).
        ]. self nextPutAll:' stroke '.
     ]
      ifFalse:
     [
       2 to:(aCurve size+(-1))//3 *3+1 do:
        [ :j |
          (aCurve at:j) x printOnCh:self.self nextPut:(32 asCharacter).
          (aCurve at:j) y  printOnCh:self.self nextPut:(32 asCharacter).
          (j+(-1) \\ 3)=0
           ifTrue:
             [ self nextPutAll:' curveto '.
               self nextPut:(13 asCharacter). self nextPut:(10 asCharacter).
             ].
        ].

        self nextPutAll:' stroke '.
     ].
     self nextPutAll: 'grestore'.
     self nextPut:(13 asCharacter). self nextPut:(10 asCharacter).
     self nextPut:(13 asCharacter). self nextPut:(10 asCharacter).
  ].
   self nextPutAll:'% endOfCurve'.
   self nextPut:(13 asCharacter).
     self nextPut:(10 asCharacter).
   self nextPutAll: 'grestore'.
    self nextPut:(13 asCharacter). self nextPut:(10 asCharacter).

  self nextPutAll:'gsave';nextPut:(13 asCharacter).
        aPoint x printOn:self.self nextPut:(32 asCharacter).
        (aPoint y +20) printOn:self.
   self nextPut:(13 asCharacter);
        nextPutAll:'moveto';nextPut:(13 asCharacter);
        nextPutAll:'/F001 /Timnes-Roman findfont def';nextPut:(13 asCharacter);
        nextPutAll:'F001[36 0 0 20 0 0]';nextPut:(13 asCharacter);
        nextPutAll:'makefont setfont';nextPut:(13 asCharacter);
        nextPut:$(.
        anInteger printOn:self.
   self nextPut:$);
        nextPutAll:' show';nextPut:(13 asCharacter);
        nextPutAll:'grestore';nextPut:(13 asCharacter).!

initPostScriptGraphics

   self nextPutAll: 'initgraphics'.
     self nextPut:(13 asCharacter). self nextPut:(10 asCharacter).
   self nextPutAll: '/picstr ' .
      256 printOn:self .
        self nextPutAll: ' string def'.
          self nextPut:(13 asCharacter). self nextPut:(10 asCharacter).!

lineDelimiter
        "Answer the line delimiter character for the
         receiver file stream, either carriage-return
         or line-feed."
    ^lineDelimiter!

lineDelimiter: aCharacter
        "Change the line delimiter character to aCharacter."
    lineDelimiter := aCharacter!

next
        "Answer the next character accessible by the receiver
         and advance the stream position.  Report an error
         if the receiver stream is positioned at end."
    <primitive: 65>
    self position: self position.
    self atEnd
        ifTrue: [
            ^self error: 'read beyond end of stream']
        ifFalse: [
            (position := position + 1) > readLimit
                ifTrue: [self error: 'position outside of stream'].
            ^collection at: position]!

nextLine
        "Answer a String consisting of the characters of
         the receiver up to the next line delimiter."
    | line |
    line := self upTo: lineDelimiter.
    lineDelimiter == Cr
        ifTrue: [self peekFor: Lf].
    ^line!

nextPut: aCharacter
        "Write aCharacter to the receiver stream."
    writtenOn := true.
    ^self primitiveNextPut: aCharacter!

nextPutAll: aCollection
        "Write each of the chararacters in
         aCollection to the receiver stream."
    | currentPosition stopIndex |
    stopIndex := position + aCollection size.
    stopIndex <= writeLimit
        ifTrue: [
            collection
                replaceFrom: position + 1
                to: stopIndex
                with: aCollection
                startingAt: 1.
            position := stopIndex.
            writtenOn := true.
            ^aCollection].
    ^aCollection do: [ :element |
        self nextPut: element]!

pathName
        "Answer the complete pathname of the file
         over which the receiver is streaming."
    | path |
    path := file directory pathName.
    path = '\'
        ifTrue: [path := ''].
    ^(String with: file directory drive), ':',
        path, '\', file name!

position
        "Answer the current receiver stream position."
    ^pageStart + position - 1.!

position: anInteger
        "Set the receiver stream position to anInteger."
    self readLimit.
    ((anInteger + 1) < pageStart
        or: [(pageStart + collection size) <= (anInteger + 1)])
            ifTrue: [
                self writePage.
                pageStart := ((anInteger // collection size)
                    * collection size) + 1.
                readLimit := file
                    readBuffer: collection
                    atPosition: pageStart].
    position := anInteger - pageStart + 1.
    self updateLastByte!

primitiveNextPut: aCharacter
        "Private - Write aCharacter to the receiver stream.
         Answer aCharacter."
    <primitive: 66>
    self position: self position.
    position := position + 1.
    writtenOn := true.
    collection at: position put: aCharacter.
    ^aCharacter!

printForMutoGraph
  self nextPutAll:'showpage'.
   self nextPut:(13 asCharacter).
     self nextPut:(10 asCharacter).!

readLimit
        "Private - Answer the size of the receiver file."
    readLimit := readLimit max: position.
    ^self updateLastByte!

resetTrans
 < primitive: resetTrans >
   ^self error: 'user prim failed'!

sendToTrans: aByte
 < primitive: sendToTrans >
   ^self error: 'user prim failed'!

setFontLabel: aLabel font: aFont width:dx height:dy
 self nextPut:$/.
 self nextPutAll:aLabel.self nextPutAll:' /'.
    self nextPutAll:aFont.
    self nextPutAll:' findfont def'.
    self nextPut:(13 asCharacter). self nextPut:(10 asCharacter).
   self nextPutAll:aLabel.
   self nextPut: $[.
    dx printOn:self.self nextPutAll:' 0 0 '.
    dy printOn:self.self nextPutAll:' 0 '.
    (0) printOn:self.
   self nextPut: $].
       self nextPut:(13 asCharacter).self nextPut:(10 asCharacter).
    self nextPutAll:'makefont setfont'.

       self nextPut:(13 asCharacter). self nextPut:(10 asCharacter).!

setLimits
        "Private - Initialize the stream size and position."
    file := collection.
    collection := String new: File pageSize.
    writeLimit := collection size.
    readLimit := file
        readBuffer: collection
        atPosition: 1.
    position := 0.
    pageStart := 1.
    writtenOn := false.
    lastByte := file size.
    lineDelimiter := Cr.
    2 to: readLimit do: [ :i |
        (collection at: i) == Lf
            ifTrue: [
                (collection at: i - 1) == Cr
                    ifFalse: [lineDelimiter := Lf].
                ^self]]!

takeByteCodeFrom:aClass
 |data aChar aByte pos|

 self nextPutAll:(aClass name asString).
  self nextPut:(13 asCharacter).
  self nextPut:(10 asCharacter).
 self nextPutAll:('instVarNames:').
  self nextPut:(13 asCharacter).
  self nextPut:(10 asCharacter).
  pos:=0.
  1 to: ((aClass instVarNames) size) do:
         [ :anIndex |
            self nextPutAll:
             (((aClass instVarNames) at:  anIndex) asString).
                 self nextPut:$ .
           pos:=pos+1.
           pos=4 ifTrue:
                  [pos:=0.
                   self nextPut:(13 asCharacter).
                   self nextPut:(10 asCharacter).
                  ].
         ].

  self nextPut:(13 asCharacter).
  self nextPut:(10 asCharacter).
 aClass selectors do: [ :aSelect |
                  self nextPut:(13 asCharacter).
                  self nextPut:(10 asCharacter).
                  self nextPutAll:(aClass sourceCodeAt:aSelect ).
                  self nextPut:(13 asCharacter).
                  self nextPut:(10 asCharacter).
                  self nextPutAll:'selectors :'.
                  self nextPut:(13 asCharacter).
                  self nextPut:(10 asCharacter).
                  pos:=0.
                  1 to: ((aClass compiledMethodAt:aSelect) size) do:
                    [ :anIndex |
                      (((aClass compiledMethodAt:aSelect) at: anIndex) class)
                                  =Symbol
                      ifTrue:[
                       self nextPutAll:
                        ((aClass compiledMethodAt:aSelect) at: anIndex)
                             ]
                      ifFalse:[
                         self nextPutAll:(
                             ((aClass compiledMethodAt:aSelect) at: anIndex)
                               class name).
                          (((aClass compiledMethodAt:aSelect) at: anIndex) class)
                                  =Association
                          ifTrue:[
                                  self nextPutAll:'-:-'.
                                 self nextPutAll:
                        (((aClass compiledMethodAt:aSelect) at: anIndex)  key).
                                 self nextPut:(13 asCharacter).
                                 self nextPut:(10 asCharacter).
                                 ]
                              ].
                        self nextPut:$ .
                      pos:=pos+1.
                      pos=4 ifTrue:
                                     [pos:=0.
                                      self nextPut:(13 asCharacter).
                                      self nextPut:(10 asCharacter).
                                     ].
                    ].
                  self nextPut:(13 asCharacter).
                  self nextPut:(10 asCharacter).
                  pos:=0.
                  ((aClass compiledMethodAt:aSelect) instVarAt:1)
                       do: [ :aByte |
                              data:=aByte "asciiValue".
                              aChar:=(data//16)+48.
                              58<=aChar ifTrue: [aChar:=aChar+7].
                              self nextPut: (aChar asCharacter).
                              aChar:=(data\\16)+48.
                              58<=aChar  ifTrue: [aChar:=aChar+7].
                              self nextPut: (aChar asCharacter).
                              self nextPut:$  .
                              pos:=pos+1.
                              pos=16 ifTrue:
                                     [pos:=0.
                                      self nextPut:(13 asCharacter).
                                      self nextPut:(10 asCharacter).
                                     ].
                           ].
                   self nextPut:(13 asCharacter).
                   self nextPut:(10 asCharacter).
                   self nextPut:(12 asCharacter)


                     ].
       self close!

takeItsBitmap: aForm
   | byte length|
   byte:=0.
   length:=((aForm height)* (aForm width))
                     / 8.
   self nextPut:((length \\ 256 ) asCharacter).
   self nextPut:((length // 256 )asCharacter).
   self nextPut:((aForm width \\ 256 ) asCharacter).
   self nextPut:((aForm width // 256 )asCharacter).
   self nextPut:((aForm height \\ 256 ) asCharacter).
   self nextPut:((aForm height // 256 )asCharacter).

   [byte=(length)]
     whileFalse: [
                  byte:=byte+1.
                  self nextPut: ((aForm bitmap at: byte) asCharacter).

                 ].
   self close!

takeItsBitmapInPostScript: anOrderedCollection
   | i |
   self nextPutAll: 'initgraphics'.
     self nextPut:(13 asCharacter). self nextPut:(10 asCharacter).
   self nextPutAll: '/picstr ' .
      256 printOn:self .
        self nextPutAll: ' string def'.
          self nextPut:(13 asCharacter). self nextPut:(10 asCharacter).
  anOrderedCollection do: [ :aFormPiece  |
                        self dotakeItsBitmapInPostScript:aFormPiece
                          ].!

takeItsCurvesInPostScript: anOrderedCollection
   | i aFile|

  anOrderedCollection do: [ :aCurvePiece  |
                        self dotakeItsCurveInPostScript:aCurvePiece
                          ].!

takeItsEveryThing: aA4arc
   | aFile |
  self nextPutAll: 'initgraphics'.
     self nextPut:(13 asCharacter). self nextPut:(10 asCharacter).
   self nextPutAll: '/picstr ' .
      256 printOn:self .
        self nextPutAll: ' string def'.
          self nextPut:(13 asCharacter). self nextPut:(10 asCharacter).
 aFile := (File pathName:'headfor.pos').
   [aFile atEnd]
    whileFalse:
     [
      self nextPut:(aFile next)
     ].
  aFile close.
    self nextPut:(13 asCharacter). self nextPut:(10 asCharacter).
   aA4arc thePieces do: [ :aPiece  |
                        aPiece class ==A4FormPiece
                        ifTrue:
                          [self dotakeItsBitmapInPostScript:aPiece].
                        aPiece class ==A4TextPiece
                        ifTrue:
                          [self dotakeItsTextInPostScriptNaked:aPiece].
                         aPiece class ==A4CurvePiece
                        ifTrue:
                          [self dotakeItsCurveInPostScript:aPiece].
                          ].

   self nextPutAll:'showpage'.
   self nextPut:(13 asCharacter).
     self nextPut:(10 asCharacter).
  "self close."!

takeItsTextAndBitmap: aA4arc
   | aFile |
  self nextPutAll: 'initgraphics'.
     self nextPut:(13 asCharacter). self nextPut:(10 asCharacter).
   self nextPutAll: '/picstr ' .
      256 printOn:self .
        self nextPutAll: ' string def'.
          self nextPut:(13 asCharacter). self nextPut:(10 asCharacter).
 aFile := (File pathName:'d:\plasma\headfor.pos').
   [aFile atEnd]
    whileFalse:
     [
      self nextPut:(aFile next)
     ].
    self nextPut:(13 asCharacter). self nextPut:(10 asCharacter).
   aA4arc thePieces do: [ :aPiece  |
                        aPiece Class ==A4FormPiece
                        ifTrue:
                          [self dotakeItsBitmapInPostScript:aPiece].
                        aPiece Class ==A4FormText
                        ifTrue:
                          [self dotakeItsTextInPostScript:aPiece].
                         aPiece Class ==A4FormText
                        ifTrue:
                          [self dotakeItsCurvesInPostScript:aPiece].
                          ].

 " aA4arc thePieces = nil
   ifFalse:
    [ self takeItsBitmapInPostScript: aA4arc thePieces] .

  aA4arc theTexts = nil
   ifFalse:
   [ self takeItsTextInPostScript: aA4arc theTexts ].

   aA4arc theCurves = nil
   ifFalse:
   [ self takeItsCurvesInPostScript: aA4arc theCurves ]."

   self nextPutAll:'showpage'.
   self nextPut:(13 asCharacter).
     self nextPut:(10 asCharacter).
  self close.!

takeItsTextInPostScript: anOrderedCollection
   | i aFile|
   aFile := (File pathName:'d:\plasma\headfor.pos').
   [aFile atEnd]
    whileFalse:
     [
      self nextPut:(aFile next)
     ].
    self nextPut:(13 asCharacter). self nextPut:(10 asCharacter).
  anOrderedCollection do: [ :aTextPiece  |
                        self dotakeItsTextInPostScript:aTextPiece
                          ].!

takeItsThing: aA4arc
   | aFile |
"  self nextPutAll: 'initgraphics'.
     self nextPut:(13 asCharacter). self nextPut:(10 asCharacter).
   self nextPutAll: '/picstr ' .
      256 printOn:self .
        self nextPutAll: ' string def'.
          self nextPut:(13 asCharacter). self nextPut:(10 asCharacter).
 aFile := (File pathName:'headfor.pos').
   [aFile atEnd]
    whileFalse:
     [
      self nextPut:(aFile next)
     ].
"
    self nextPut:(13 asCharacter). self nextPut:(10 asCharacter).
   aA4arc thePieces do: [ :aPiece  |
                        aPiece class ==A4FormPiece
                        ifTrue:
                          [self dotakeItsBitmapInPostScript:aPiece].
                        aPiece class ==A4TextPiece
                        ifTrue:
                          [self dotakeItsTextInPostScript:aPiece].
                         aPiece class ==A4CurvePiece
                        ifTrue:
                          [self dotakeItsCurveInPostScript:aPiece].
                          ].

   self nextPutAll:'showpage'.
   self nextPut:(13 asCharacter).
     self nextPut:(10 asCharacter).
  "self close."!

updateLastByte
        "Private - Answer the position of the last byte in
         the file, and update the instance variable."
    ^lastByte := lastByte max: position + pageStart - 1!

writeFormAsPCX:aForm
   | lines  bytesPerFormLine  bytesPerLine  bByte  aByte  byte byteTot length fileLength aChar
     itsWidth itsHeight |

   byteTot:=1.

   itsWidth:=aForm width.itsHeight:=aForm height.
   self nextPut:10 asCharacter.self nextPut:3 asCharacter.
   self nextPut:1 asCharacter. self nextPut:1 asCharacter.

   1 to:4 do:[:i | self nextPut:(0 asCharacter)].

   self nextPut:((itsWidth+(-1))\\256) asCharacter.
   self nextPut:((itsWidth+(-1))//256) asCharacter.
   self nextPut:((itsHeight+(-1))\\256) asCharacter.
   self nextPut:((itsHeight+(-1))//256) asCharacter.
   self nextPut:128 asCharacter.self nextPut:2 asCharacter.
   self nextPut:94 asCharacter. self nextPut:1 asCharacter.

   17 to:64 do: [:i | self nextPut:0 asCharacter].
   self nextPut:0 asCharacter.
   self nextPut:1 asCharacter.
   bytesPerLine:=((itsWidth+7)//8).
   bytesPerFormLine:=((itsWidth+15)//16)*2.
   self nextPut:bytesPerLine asCharacter.
   self nextPut:0 asCharacter.
   69 to:128 do: [:i | self nextPut:0 asCharacter].
   lines:=(aForm height).

   1 to: lines do:[:aLine |
                   1 to:bytesPerLine  do:
                   [:pos |
                   aByte:=aForm bitmap at:((aLine+(-1))*bytesPerFormLine)+pos.
                   (aByte//64)=3
                   ifTrue:[self nextPut:(193 asCharacter).
                           self nextPut:(aByte asCharacter).
                          ]
                   ifFalse:[ self nextPut:(aByte asCharacter).
                           ].
                   ].

                ].
   self close.
   ^aForm!

writePage
        "Private - Write the current page
         to the file, if it has changed."
    writtenOn
        ifTrue: [
            file
                writeBuffer: collection
                ofSize: readLimit
                atPosition: pageStart.
            writtenOn := false]! !
