StdPrint.dcl 5.57 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
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
37
38
39
40
41
42
class PrintSetupEnvironments env
  where
	defaultPrintSetup	::	!*env -> (!PrintSetup, !*env)
		// returns a default print setup 
	printSetupDialog	::	!PrintSetup !*env -> (!PrintSetup, !*env)
		// lets the user choose a print setup via the print setup dialog
		
instance PrintSetupEnvironments World
43
instance PrintSetupEnvironments (IOSt .l)
Peter Achten's avatar
Peter Achten committed
44

45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
getPageDimensions	::	!PrintSetup	!Bool->	PageDimensions
instance == PageDimensions

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

freadPrintSetup		::	!*File !*env -> (!Bool, !PrintSetup, !*File, !*env)	
					|	PrintSetupEnvironments env
//	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
66
67
68
69
70
71
72
73
74
75
	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 
76
77
		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
78
79
80
81
82
	env:
		a PrintEnvironment is either the PSt or the Files system. 
*/

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

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

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

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

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