|
Class: PostscriptPrinterStream
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
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.
copyrightCOPYRIGHT (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.
accessing-defaults
-
bottomMargin
-
return the bottom margin (in inches)
-
bottomMargin: inches
-
set the bottom margin (in inches)
-
leftMargin
-
return the left margin (in inches)
-
leftMargin: inches
-
set the left margin (in inches)
-
psProlog
-
-
psTrailer
-
-
resolution
-
return the printers actual resolution (if known)
-
resolution: dpiValuePoint
-
set the printers actual resolution (if known)
-
rightMargin
-
return the right margin (in inches)
-
rightMargin: inches
-
set the right margin (in inches)
-
supportsColor
-
(comment from inherited method)
return true if this is a color printer
-
supportsColor: aBoolean
-
-
supportsGrayscale
-
assume true by default
-
supportsGrayscale: aBoolean
-
-
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) **
-
topMargin
-
return the top margin (in inches)
-
topMargin: inches
-
set the top margin (in inches)
initialization
-
initCharacterSize
-
setup the character parameters
-
initFonts
-
setup the font names.
initProlog uses those parameters.
Usage example(s):
PostscriptPrinterStream initFonts
|
-
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
|
-
initPageProlog
-
define the page prolog
-
initPageTrailer
-
define the page epilog
-
initProlog
-
define the documents prolog
Usage example(s):
PostscriptPrinterStream initProlog
|
-
initTrailer
-
define the documents epilog
-
initialize
-
self initProlog. - now done lazy
Usage example(s):
Normal := nil.
self initialize
|
-
reInitPage
-
self initProlog. - now done lazy
queries
-
printerTypeName
-
return a descriptive name
-
supportsMargins
-
return true if this printer supports margins
-
supportsPageSizes
-
return true if this printer supports different page sizes
-
supportsPostscript
-
return true if this is a postscript printer
access-writing
-
cr
-
send line termination
-
nextPut: aCharacterOrByte
-
print aCharacter.
Answer the argument.
accessing
-
colNr
-
return the current column-Nr (within the line)
-
lineNr
-
return the current line-Nr (within the page)
-
pageCount
-
returns the number of the currently printed page
-
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 ...
-
pageStartAction: something
-
set pageStartAction - if nonNil, that is evaluated prior to every page.
emphasis change
-
bold
-
further printing is in bold
-
boldItalic
-
further printing is in boldItalic
-
italic
-
further printing is in italic
-
noStrikeout
-
further printing is not strikedout
-
noUnderline
-
further printing is not underlined
-
normal
-
further printing is in normal style (i.e. non-bold/non-italic)
-
strikeout
-
further printing is strikedout
-
underline
-
further printing is underlined
font change
-
courier
-
further printing is in the courier font
-
helvetica
-
further printing is in the helvetica font
-
times
-
further printing is in the times font
open & close
-
endPrint
-
finish a document - finish page; then send documentTrailer.
Send nothing if nativePrinting.
-
setNative: aBoolean
-
-
startPrint
-
start a document - send documentProlog & start a page.
Send nothing if nativePrinting.
private
-
endPage
-
end a page - flush buffered text & send pageTrailer
-
flushLine
-
flush buffered line text
-
nextPage
-
new page - finish previous page & start enew.
Should not be sent when nativePrinting.
-
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.
-
setFont
-
change the font.
Uses current fFamily and fStyle (which give the font's nr)
-
startPage
-
start a page - send pageProlog, reset x/y position and line/col.
queries
-
fontHeight
-
the used fonts height in my postscript coordinate system
(i.e. in twips, which is 1/20th of a point)
-
leftX
-
the left x startPosition (i.e. leftMargin) in my postscript coordinate system.
(i.e. in twips, which is 1/20th of a point)
-
linesPerPage
-
the number of lines per page
-
overAllPageSize
-
the overAll pageSize in my postscript coordinate system.
(i.e. in twips, which is 1/20th of a point)
-
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)
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).
|
|