StdPrint.dcl 5.53 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
20
// MW11 was from	StdPicture		import	Picture, Point
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
21
from	StdFile			import	FileEnv, Files
Peter Achten's avatar
Peter Achten committed
22

23
24
25
26
27
28
29
30
31
32
33
34
::	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
35

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

printSetupDialog	::	!PrintSetup !*printEnv -> (!PrintSetup, !*printEnv)
					|	PrintEnvironments printEnv
42
43
44
45
46
47
48
49
50
		// 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)	
51
					|	FileEnv env
52
53
54
55
56
57
58
59
60
61
62
63
64
//	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
		->	(!PrintSetup,!*printEnv)
		|	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
65
66
67
68
69
70
71
72
73
74
	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 
75
76
		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
77
78
79
80
81
	env:
		a PrintEnvironment is either the PSt or the Files system. 
*/

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

87
/*	printUpdateFunction doDialog update area printSetup env
Peter Achten's avatar
Peter Achten committed
88
89
90
91
92
93
94
95
96
	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. 
97
	printSetup,env,result value:
Peter Achten's avatar
Peter Achten committed
98
99
100
		identical to print.
*/

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

110
/*	printPagePerPage doDialog emulateScreen x prepare pages printSetup env
Peter Achten's avatar
Peter Achten committed
111
112
113
114
	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 
115
116
	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
117
118
119
120
121
122
123
124

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