eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'PostscriptPrinterStream':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: PostscriptPrinterStream


Inheritance:

   Object
   |
   +--Stream
      |
      +--PrinterStream
         |
         +--PostscriptPrinterStream

Package:
stx:libbasic2
Category:
Interface-Printing
Version:
rev: 1.75 date: 2018/02/09 17:04:47
user: cg
file: PostscriptPrinterStream.st directory: libbasic2
module: stx stc-classLibrary: libbasic2
Author:
Claus Gittinger

Description:


This class provides simple text output to postscript printers;
to use it, evaluate 
    Smalltalk at:#Printer put:PostscriptPrinterStream
(usually in some rc file) or change it via the launchers settings-menu.

See examples on how to send something to the printer.

For now, only Helvetica, Courier and Times fonts in italic, roman and bold are supported.

It does not directly support graphics and other fancy features of Postscript,
but provides a compatible interface for simple text line-printing 
(see other subclasses of PrinterStream).

If you already have a postscript string at hand, this can be sent to the printer in native mode.

To output graphics, you need the PSGraphicsContext (and friend-) classes.
These provide protocol similar to the one provided by display graphicContexts.
PSGraphicsContext generates its own postscript - not caring for the margin/font settings
here (these are only used if the printer-stream protocol is used (i.e. nextPut, cr etc.)

[Disclaimer:]    
    Notice, that these postscript classes are derived from public domain code; 
    there is no warranty.


Related information:

    PSGraphicsContext
    EpsonFX1PrinterStream
    HPLjetIIPrinterStream
    PrinterStream

Class protocol:

accessing-defaults
o  bottomMargin
return the bottom margin (in inches)

o  bottomMargin: inches
set the bottom margin (in inches)

o  leftMargin
return the left margin (in inches)

o  leftMargin: inches
set the left margin (in inches)

o  psProlog

o  psTrailer

o  resolution
return the printers actual resolution (if known)

o  resolution: dpiValuePoint
set the printers actual resolution (if known)

o  rightMargin
return the right margin (in inches)

o  rightMargin: inches
set the right margin (in inches)

o  supportsColor

o  supportsColor: aBoolean

o  supportsGreyscale

o  supportsGreyscale: aBoolean

o  topMargin
return the top margin (in inches)

o  topMargin: inches
set the top margin (in inches)

initialization
o  initCharacterSize
setup the character parameters

o  initFonts
setup the font names.
initProlog uses those parameters.
usage example(s):
     PostscriptPrinterStream initFonts

o  initPage
setup the page parameters.
All coordinates are scaled by 20 w.r.t the PS coordinates (i.e. in twips).
usage example(s):
     TopMargin := LeftMargin := BottomMargin := nil.
     self initPage

o  initPageProlog
define the page prolog

o  initPageTrailer
define the page epilog

o  initProlog
define the documents prolog
usage example(s):
     PostscriptPrinterStream initProlog

o  initTrailer
define the documents epilog

o  initialize
self initProlog. - now done lazy
usage example(s):
     Normal := nil.
     self initialize

o  reInitPage
self initProlog. - now done lazy

queries
o  printerTypeName
return a descriptive name

o  supportsMargins
return true if this printer supports margins

o  supportsPageSizes
return true if this printer supports different page sizes

o  supportsPostscript
return true if this is a postscript printer


Instance protocol:

access-writing
o  cr
send line termination

o  nextPut: aCharacterOrByte
(comment from inherited method)
send a character to the printer

accessing
o  colNr
return the current column-Nr (within the line)

o  lineNr
return the current line-Nr (within the page)

o  pageCount
returns the number of the currently printed page

o  pageEndAction: something
set pageEndAction - if non-nil, that will be called before
and EndPage is emmitted.
An example use is a private block,
which draws a company frame around the page ...

o  pageStartAction: something
set pageStartAction - if nonNil, that is evaluated prior to every page.

emphasis change
o  bold
further printing is in bold

o  boldItalic
further printing is in boldItalic

o  italic
further printing is in italic

o  noStrikeout
further printing is not strikedout

o  noUnderline
further printing is not underlined

o  normal
further printing is in normal style (i.e. non-bold/non-italic)

o  strikeout
further printing is strikedout

o  underline
further printing is underlined

font change
o  courier
further printing is in the courier font

o  helvetica
further printing is in the helvetica font

o  times
further printing is in the times font

open & close
o  endPrint
finish a document - finish page; then send documentTrailer.
Send nothing if nativePrinting.

o  setNative: aBoolean

o  startPrint
start a document - send documentProlog & start a page.
Send nothing if nativePrinting.

private
o  endPage
end a page - flush buffered text & send pageTrailer

o  flushLine
flush buffered line text

o  nextPage
new page - finish previous page & start enew.
Should not be sent when nativePrinting.

o  placeString: aString at: pos
special entry: place a string at some particular position in my ps-coordinate
system. Can be used with endPageActions to place a page-number.

o  setFont
change the font.
Uses current fFamily and fStyle (which give the font's nr)

o  startPage
start a page - send pageProlog, reset x/y position and line/col.

queries
o  fontHeight
the used fonts height in my postscript coordinate system
(i.e. in twips, which is 1/20th of a point)

o  leftX
the left x startPosition (i.e. leftMargin) in my postscript coordinate system.
(i.e. in twips, which is 1/20th of a point)

o  linesPerPage
the number of lines per page

o  overAllPageSize
the overAll pageSize in my postscript coordinate system.
(i.e. in twips, which is 1/20th of a point)

o  topY
the top y startPosition (i.e. page-size - topMargin) in my own coordinate system
(i.e. in twips, which is 1/20th of a point)


Examples:


For text printing, use:
    |s|

    s := Printer new.
    s nextPutAll:'hello'; cr.
    s nextPutAll:'normal '.
    s bold; nextPutAll:'this is bold'; normal; cr.
    s nextPutAll:'normal '.
    s italic; nextPutAll:'this is italic'; normal; cr.
    s nextPutAll:'normal '.
    s boldItalic; nextPutAll:'this is boldItalic'; normal; cr.
    s nextPutAll:'normal '.
    s underline; nextPutAll:'this is underlined'; noUnderline; cr.
    s nextPutAll:'normal again '.
    s strikeout; nextPutAll:'this is strikedout'; noStrikeout; cr.
    s helvetica.
    s nextPutAll:'helvetica '.
    s underline; nextPutAll:' helv-underline'; noUnderline;
      space; strikeout; nextPutAll:'helv-strikeout'; noStrikeout;
      bold; nextPutAll:' helv-bold'; normal; cr.
    s times.
    s nextPutAll:'times'; cr.
    s courier.
    s nextPutAll:'courier'; cr.
    s close
or, if you already have emphasized text at hand:
    |s|

    s := Printer new.
    s nextPutAll:'hello'; cr.
    s nextPutAll:'this is '; 
      nextPutAll:(Text string:'bold' emphasis:#bold); 
      cr;
      nextPutAll:'this is '; 
      nextPutAll:(Text string:'italic' emphasis:#italic); 
      cr;
      nextPutAll:'this is ';
      nextPutAll:(Text string:'boldItalic' emphasis:#(bold italic)); 
      cr;
      nextPutAll:'normal again'; 
      cr;
      helvetica;
      nextPutAll:'helvetica';
      cr;
      times;
      nextPutAll:'times'; 
      cr;
      courier;
      nextPutAll:'courier';
      cr.
    s close
placing a page-hook, to add a page number: (page hooks require that you understand some postscript ... ... and have a look at how this class generates its postscript code)
    |s hook pageNr|

    s := Printer new.

    pageNr := 0.
    hook := [ 

                pageNr := pageNr + 1.
                s placeString:('page ' , pageNr printString) at:(5500 @ 400).
            ].

    s pageEndAction:hook.
    (1 to:200) do:[:lineNr |
        s nextPutAll:'line ' , lineNr printString.
        s cr.
    ].
    s close.
placing a page-hook, to add a custom frame, logo or company letter-head: (page hooks require that you understand some postscript ... ... and have a look at how this class generates its postscript code. ... and notice that the code below is a q&d demo, working with letter-sized pages only; a real program should ask the printerStream about the actual pageHeight/pageWidth.)
    |s hook pageNr|

    s := Printer new.

    pageNr := 0.
    hook := [ 

                pageNr := pageNr + 1.
                s placeString:('page ' , pageNr printString) at:(5500 @ 400).
                s placeString:('Document revision:') at:(900 @ 1200).
                s placeString:('Revieved by:')       at:(900 @ 900).

                s setNative:true.
                s nextPutAll:'0 setlinewidth'; cr.
                s nextPutAll:'800 800 moveto'; cr.
                s nextPutAll:'11000 800 lineto'; cr.
                s nextPutAll:'11000 15500 lineto'; cr.
                s nextPutAll:'800 15500 lineto'; cr.
                s nextPutAll:'800 800 lineto'; cr.
                s nextPutAll:'stroke'; cr.

                s nextPutAll:'800 1100 moveto'; cr.
                s nextPutAll:'11000 1100 lineto'; cr.
                s nextPutAll:'stroke'; cr.

                s nextPutAll:'800 1400 moveto'; cr.
                s nextPutAll:'11000 1400 lineto'; cr.
                s nextPutAll:'stroke'; cr.

                s setNative:false.
            ].

    s pageEndAction:hook.
    (1 to:200) do:[:lineNr |
        s nextPutAll:'line ' , lineNr printString.
        s cr.
    ].
    s close.
If you already have a postscript string at hand, this can be sent to the printer in native mode:
    |s|

    s := Printer newNative.
    s nextPutAll:<your postscript string>.
s close To output graphics, you need the PSGraphicsContext (and friend-) classes. These provide protocol similar to the one provided by display graphicContexts. Notice, that these postscript classes are derived from public domain code; there is no warranty. Usage:
    |drawable s|

    s := Printer newNative.
    drawable := PSGraphicsContext on:s.

    drawable displayLineFrom:(0@0) to:(100@100).
    drawable displayLineFrom:(100@0) to:(0@100).
    drawable displayCircle:(150@150) radius:50.
    (Image fromFile:'bitmaps/SBrowser.xbm') displayOn:drawable at:(50@30).

    drawable close.
the same in a view:
    |drawable|

    drawable := (View extent:200@200) openAndWait.

    drawable displayLineFrom:(0@0) to:(100@100).
    drawable displayLineFrom:(100@0) to:(0@100).
    drawable displayCircle:(150@150) radius:50.
    (Image fromFile:'bitmaps/SBrowser.xbm') displayOn:drawable at:(50@30).


ST/X 7.1.0.0; WebServer 1.663 at exept.de:8081; Sun, 22 Jul 2018 16:44:45 GMT