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

//	********************************************************************************
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
9
10
11
12
13
//	
//	StdPrint specifies general printing functions.
//	Related functions and modules:
//	-	getResolution (StdPicture)
//	-	resizeBitmap  (StdBitmap)
//	-	StdPrintText to print text.
//	********************************************************************************
 

14
15
16
17
18
19
from	StdPicture		import	Picture, Point2
from	StdIOCommon		import	Size, Rectangle, IdFun, UpdateState, ViewFrame, UpdateArea
from	StdOverloaded	import	==
from	osprint			import	PrintSetup, JobInfo, PrintInfo, Alternative, 
								Cancelled, StartedPrinting, PrintEnvironments
from	iostate			import	IOSt, PSt
20
from	StdFile			import	FileEnv, Files
Peter Achten's avatar
Peter Achten committed
21

22
23
24
25
26
27
28
29
30
31
32
33
::	PageDimensions
	=	{	page		:: !Size		// size of the drawable area of the page 
		,	margins		:: !Rectangle	// This field contains information about the
										// size of the margins on a sheet in pixels.
										// Drawing can't occur within these margins.
										// The margin Rectangle is bigger than the
										// page size. Its values are:
										// corner1.x<=0 && corner1.y<=0 && 
										// corner2.x>=page.w && corner2.y>=page.h
		,	resolution	:: !(!Int,!Int)	// horizontal and vertical printer
										// resolution in dpi
		}
Peter Achten's avatar
Peter Achten committed
34

35
36
defaultPrintSetup	::	!*env -> (!PrintSetup, !*env)
					| FileEnv env
37
		// returns a default print setup 
38
39
40

printSetupDialog	::	!PrintSetup !*printEnv -> (!PrintSetup, !*printEnv)
					|	PrintEnvironments printEnv
41
42
43
44
45
46
47
48
49
		// lets the user choose a print setup via the print setup dialog
		
getPageDimensions	::	!PrintSetup	!Bool->	PageDimensions
instance == PageDimensions

fwritePrintSetup	::	!PrintSetup !*File -> *File
//	writes PrintSetup to file (text or data)

freadPrintSetup		::	!*File !*env -> (!Bool, !PrintSetup, !*File, !*env)	
50
					|	FileEnv env
51
52
53
54
55
56
57
//	reads PrintSetup from File (text or data). If resulting Boolean is True:success,
//	otherwise the default PrintSetup is returned


print	::	!Bool !Bool
			.(PrintInfo !*Picture -> ([IdFun *Picture],!*Picture))
			!PrintSetup !*printEnv
58
		-> (!PrintSetup,!*printEnv)
59
60
61
62
63
		|	PrintEnvironments printEnv

/*	print doDialog emulateScreen pages printSetup env
	sends output to the printer and returns the used print setup, which can differ
	from the input print setup
Peter Achten's avatar
Peter Achten committed
64
65
66
67
68
69
70
71
72
73
	doDialog:
		if True a dialog will pop up that lets the user choose all printing options,
		otherwise printing will happen in the default way.
	emulateScreen:
		if True, the printing routine will emulate the resolution of the screen. 
		That means that a pixel on paper has the same dimension as on screen. 
		Otherwise, the used resolution will be the printer resolution, with the 
		effect that coordinates get much "tighter". 
	pages:
		this function should calculate a list of functions, each function 
74
75
		representing one page to be printed. Each of these drawing functions is
		applied	to an initial printer Picture.
Peter Achten's avatar
Peter Achten committed
76
77
78
79
80
	env:
		a PrintEnvironment is either the PSt or the Files system. 
*/

printUpdateFunction
81
82
		:: 	!Bool (UpdateState -> *Picture -> *Picture) [Rectangle]
			!PrintSetup !*printEnv 
83
84
		-> (!PrintSetup,!*printEnv)
		|  PrintEnvironments printEnv
Peter Achten's avatar
Peter Achten committed
85

86
/*	printUpdateFunction doDialog update area printSetup env
Peter Achten's avatar
Peter Achten committed
87
88
89
90
91
92
93
94
95
	sends the content of the update function of a given area to the printer:
	doDialog:
		identical to print.
	update:
		this function will be applied to an UpdateState of value 
			{oldFrame=area,newFrame=area,updArea=[area]}.
	area:
		the area to be sent to the printer. If a rectangle of this area does not
		fit on one sheet, it will be distributed on several sheets. 
96
	printSetup,env,result value:
Peter Achten's avatar
Peter Achten committed
97
98
99
		identical to print.
*/

100
printPagePerPage ::	!Bool !Bool 
Peter Achten's avatar
Peter Achten committed
101
102
103
					.x
					.(.x -> .(PrintInfo -> .(*Picture -> ((.Bool,Point2),(.state,*Picture)))))
					((.state,*Picture) -> ((.Bool,Point2),(.state,*Picture)))
104
					!PrintSetup !*printEnv 
Peter Achten's avatar
Peter Achten committed
105
106
107
				-> 	(Alternative .x .state,!*printEnv)
		        | PrintEnvironments printEnv

108
/*	printPagePerPage doDialog emulateScreen x prepare pages printSetup env
Peter Achten's avatar
Peter Achten committed
109
110
111
112
	sends output to the printer.
	This function can be used more efficiently than print. The major difference is 
	that the pages function is a state transition function instead of a page list 
	producing function. Each page transition function generates one page for the 
113
114
	printer. An additional feature of printPagePerPage is that it is possible to
	set the origin of the printer Pictures.
Peter Achten's avatar
Peter Achten committed
115
116
117
118
119
120
121
122

	doDialog:
		identical to print. 
	emulateScreen:
		identical to print.
	x:
		this value is passed to the prepare function.
	prepare:
123
		this function calculates the initial page print state. 
Peter Achten's avatar
Peter Achten committed
124
		Iff there are no pages to print, the return Boolean must be True.
125
		The returned Point is the Origin of the first printer Picture.
Peter Achten's avatar
Peter Achten committed
126
127
128
	pages:
		this state transition function produces the printed pages. 
		The state argument consists of the state information and an initial printer
129
		Picture which Origin has been set by the previous return Point value. 
Peter Achten's avatar
Peter Achten committed
130
		If there are no more pages to print, the return Boolean must be True. In 
131
132
133
134
135
		that case the result of printPagePerPage is (StartedPrinting state),
		with state the current state value. If printing should continue, the
		return Boolean is False.
		The returned Point is the Origin of the next printer Picture. 
	printSetup, env:
Peter Achten's avatar
Peter Achten committed
136
137
		identical to print.
	
138
	If printing is cancelled via the print dialog, then (Cancelled x) will be
Peter Achten's avatar
Peter Achten committed
139
140
	returned, otherwise (StartedPrinting ...)
*/
141
142
143
144
 
instance PrintEnvironments World
// other instances are the Files subworld and PSt (see osprint.dcl)