StdPrintText.dcl 3.87 KB
Newer Older
Peter Achten's avatar
Peter Achten committed
1
2
3
definition module StdPrintText

//	********************************************************************************
Peter Achten's avatar
Peter Achten committed
4
//	Clean Standard Object I/O library, version 1.2
Peter Achten's avatar
Peter Achten committed
5
6
7
8
//	
//	StdPrintText specifies functions to print text.
//	********************************************************************************

9
10
11
from	StdPictureDef	import FontDef, FontName, FontStyle, FontSize
import	StdPrint
from	StdString import String
Peter Achten's avatar
Peter Achten committed
12
13
14
15
16
17
18
19


:: WrapMode :== Int

NoWrap 			:== 0
LeftJustify 	:== 1
RightJustify 	:== 2

20
21
class CharStreams cs
where
Peter Achten's avatar
Peter Achten committed
22
	getChar		:: !*cs -> (!Bool,!Char,!*cs)
23
24
25
26
27
		//	returns the charstreams next character, and whether this operation was
		//	successful 
	savePos		:: !*cs -> *cs
		//	saves actual position of charstream to be enable the restorePos function
		//	to restore it then.
Peter Achten's avatar
Peter Achten committed
28
29
	restorePos	:: !*cs -> *cs
	eos			:: !*cs -> (!Bool,!*cs)
30
		//	end of stream
Peter Achten's avatar
Peter Achten committed
31
32
33
34
35
36
37
38
39

instance CharStreams FileCharStream

:: *FileCharStream

fileToCharStream :: !*File -> *FileCharStream
charStreamToFile :: !*FileCharStream -> *File


40
41
printText1 :: !Bool !WrapMode !FontDef !Int !*charStream !PrintSetup !*printEnv
		 ->   (!(!*charStream,!PrintSetup),!*printEnv)
Peter Achten's avatar
Peter Achten committed
42
43
		 | CharStreams charStream & PrintEnvironments printEnv

44
/* 	printText1 doDialog wrapMode font spacesPerTab charStream printSetup env
Peter Achten's avatar
Peter Achten committed
45
46
47
48
49
50
51
52
53
54
55
56
	prints a CharStream:
	doDialog:
		identical to print (StdPrint)
	wrapMode:
		controls word wrapping in case lines do not fit. NoWrap suppresses wrapping.
		LeftJustify and RightJustify wrap text to the left and right respectively.
	font:
		the text will be printed in this font.
	spacesPerTab:
		the number of spaces a tab symbol represents.
	charStream:
		the charStream to be printed.
57
	printSetup, env:
Peter Achten's avatar
Peter Achten committed
58
59
60
61
		identical to print (StdPrint)
*/


62
63
64
65
66
67
68
printText2	::	!String !String !Bool !WrapMode !FontDef !Int !*charStream !PrintSetup
				!*printEnv
			->  (!(!*charStream,!PrintSetup),!*printEnv)
			|	CharStreams charStream & PrintEnvironments printEnv

/*	printText2 titleStr pageStr doDialog wrapMode fontParams spacesPerTab charStream
			   printSetup env
Peter Achten's avatar
Peter Achten committed
69
70
71
72
73
74
75
76
77
78
79
	prints a charStream with a header on each page.
	titleStr:
		this String will be printed on each page at the left corner of the header
	pageStr:
		this String and the actual page number are printed on the right corner of 
		the header
	The other parameters are identical to printText1.
*/


printText3 ::!Bool !WrapMode !FontDef !Int 
80
81
			 .(PrintInfo *Picture -> (state, (Int,Int), *Picture))
			 (state Int *Picture -> *Picture)
Peter Achten's avatar
Peter Achten committed
82
			 !*charStream
83
84
			 !PrintSetup !*printEnv
		 ->  (!(!*charStream,!PrintSetup),!*printEnv)
Peter Achten's avatar
Peter Achten committed
85
86
		 | CharStreams charStream & PrintEnvironments printEnv

87
88
/*	printText3 doDialog wrapMode font spacesPerTab textRange eachPageDraw charStream
			   printSetup env
Peter Achten's avatar
Peter Achten committed
89
90
91
92
93
94
95
96
97
98
99
100
101
	prints a charStream with a header and trailer on each page. 
	textRange:
		this function takes a PrintInfo record and the printer Picture on which the 
		text will be printed. It returns a triple (state,range,picture):
		state:
			a value of arbitrary type that can be used to pass data to the page 
			printing function pages. 
		range:
			a pair (top,bottom), where top<bottom. The printed text will appear 
			within these y-coordinates only, so a header and a trailer can be 
			printed for each page.
	eachPageDraw:
		this function draws the header and/or trailer for the current page. Its 
102
103
104
		arguments are the data produced by textRange, the actual page number, and an
		initial printer Picture. This function is applied by printText3 before each new
		page receives its text. 
Peter Achten's avatar
Peter Achten committed
105
106
107
108
	The other parameters are identical to printText1.
*/


109
/*	If a file is openend with FReadData, then all possible newline conventions
Peter Achten's avatar
Peter Achten committed
110
	(unix,mac,dos) will be recognized. All these printing functions will replace
111
	nonprintable characters of the font with ASCII spaces. Exceptions are: newline,
Peter Achten's avatar
Peter Achten committed
112
113
114
	formfeed and tab. So the ASCII space has to be a printable character in the used
	font. A form feed character will cause a form feed, and it will also end a line.
*/