summaryrefslogtreecommitdiff
path: root/files/practicum/TextCompose.dcl
blob: 85962d669c37ac0147073cda9f0fb442182064fa (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
definition module TextCompose

import StdEnv

/** This module implements a number of operations to compose blocks of text.
*/
::	Text
::	AlignH		=	LeftH | CenterH | RightH	// align left, center, right  horizontally
::	AlignV		=	TopV  | CenterV | BottomV	// align top,  center, bottom vertically
::	Width		:== NrOfChars
::	Height		:== NrOfLines
::	NrOfChars	:== Int							// 0 <= nr of chars
::	NrOfLines	:== Int							// 0 <= nr of lines

/** zero
	returns the empty text: horz align [zero] = zero and vert align [zero] = zero.
*/
instance zero Text

/** toText (ah,reqw) (av,reqh) a
	transforms the String representation of a into a text block that is atleast
	reqw characters wide and consists of atleast reqh lines.
	The String representation of a determines whether more width or height is
	required.
	The text is aligned horizontally according to ah, and vertically according to av.
*/
toText					:: !(!AlignH,!Width) !(!AlignV,!Height) !a -> Text | toString a

/** fitText a
	transforms the String representation of a with: toText (LeftH,0) (TopV,0) a.
*/
fitText					:: !a -> Text | toString a

/** toString text
	adds a newline character to each line in text, and concatenates them.
*/
instance toString Text

/** sizeOf x
	determines the number of characters text block x is wide and the number of lines 
	it consists of.
*/
class sizeOf a			:: !a -> (!Width,!Height)
instance sizeOf String
instance sizeOf Text

/** horz av texts
	puts all text blocks within texts next to each other, and aligning them according to av.
	It is assumed that all lines within a text block have the same width.
*/
horz					:: !AlignV ![Text] -> Text

/** vert ah texts
	puts all text blocks within text below each other, and aligning them according to ah.
*/
vert					:: !AlignH ![Text] -> Text

/** repeath n c
	creates a single line of text consisting of n occurrences of c.
	It is illegal to pass '\n' as argument c.
*/
repeath					:: !Int !Char -> Text

/** repeatv n c
	creates a single column of text consisting of n occurrences of c.
	It is illegal to pass '\n' as argument c.
*/
repeatv					:: !Int !Char -> Text

/** frame t
	creates a new text that has a frame around t.
*/
frame					:: !Text -> Text