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.82 date: 2024/04/22 16:49:12
user: stefan
file: PostscriptPrinterStream.st directory: libbasic2
module: stx stc-classLibrary: libbasic2

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.

copyright

COPYRIGHT (c) 1988 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.

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
(comment from inherited method)
return true if this is a color printer

o  supportsColor: aBoolean

o  supportsGrayscale
assume true by default

o  supportsGrayscale: aBoolean

o  supportsGreyscale: aBoolean
marked as obsolete by exept MBP at 20-09-2021

** This is an obsolete interface - do not use it (it may vanish in future versions) **

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
print aCharacter.
Answer the argument.

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) openAndWaitUntilVisible.

    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.7.0.0; WebServer 1.702 at 20f6060372b9.unknown:8081; Sat, 23 Nov 2024 08:01:37 GMT