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
42
43


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

46
/* 	printText1 doDialog wrapMode font spacesPerTab charStream printSetup env
Peter Achten's avatar
Peter Achten committed
47
48
49
50
51
52
53
54
55
56
57
58
	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.
59
	printSetup, env:
Peter Achten's avatar
Peter Achten committed
60
61
62
63
64
		identical to print (StdPrint)
*/



65
66
67
68
69
70
71
72

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
73
74
75
76
77
78
79
80
81
82
	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.
*/


83
84


Peter Achten's avatar
Peter Achten committed
85
printText3 ::!Bool !WrapMode !FontDef !Int 
86
87
			 .(PrintInfo *Picture -> (state, (Int,Int), *Picture))
			 (state Int *Picture -> *Picture)
Peter Achten's avatar
Peter Achten committed
88
			 !*charStream
89
90
			 !PrintSetup !*printEnv
		 ->  (!(!*charStream,!PrintSetup),!*printEnv)
Peter Achten's avatar
Peter Achten committed
91
92
		 | CharStreams charStream & PrintEnvironments printEnv

93
94
/*	printText3 doDialog wrapMode font spacesPerTab textRange eachPageDraw charStream
			   printSetup env
Peter Achten's avatar
Peter Achten committed
95
96
97
98
99
100
101
102
103
104
105
106
107
	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 
108
109
110
		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
111
112
113
114
	The other parameters are identical to printText1.
*/


115
/*	If a file is openend with FReadData, then all possible newline conventions
Peter Achten's avatar
Peter Achten committed
116
	(unix,mac,dos) will be recognized. All these printing functions will replace
117
	nonprintable characters of the font with ASCII spaces. Exceptions are: newline,
Peter Achten's avatar
Peter Achten committed
118
119
120
	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.
*/