From a7d7542dc646a5fd124ef71e71ce260889f1701b Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Tue, 2 Feb 2016 19:24:50 +0100 Subject: Moved to 1415 directory --- 1415/files/practicum/TextCompose.dcl | 73 ++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 1415/files/practicum/TextCompose.dcl (limited to '1415/files/practicum/TextCompose.dcl') diff --git a/1415/files/practicum/TextCompose.dcl b/1415/files/practicum/TextCompose.dcl new file mode 100644 index 0000000..85962d6 --- /dev/null +++ b/1415/files/practicum/TextCompose.dcl @@ -0,0 +1,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 -- cgit v1.2.3