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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
module Data.Text.ParagraphLayout.Rich.ParagraphData
( hardBoxBreakLTRParagraph
, hardBoxBreakRTLParagraph
, loremIpsumParagraph
, mixedSizesParagraph
, nestedBoxesParagraph
)
where
import Data.Text (pack)
import Data.Text.Glyphize (Direction (DirLTR, DirRTL), Font)
import Data.Text.ParagraphLayout.Internal.BoxOptions
import Data.Text.ParagraphLayout.Internal.ParagraphOptions
import Data.Text.ParagraphLayout.Internal.Rich.Paragraph
import Data.Text.ParagraphLayout.Internal.TextOptions
import Data.Text.ParagraphLayout.Internal.TreeOfTexts
tLTR :: TextOptions
tLTR = defaultTextOptions DirLTR
tRTL :: TextOptions
tRTL = defaultTextOptions DirRTL
b_ :: BoxOptions
b_ = defaultBoxOptions
rootBox :: TextOptions -> [InnerNode d] -> RootNode d
rootBox opts nodes = RootBox (Box nodes opts)
box :: d -> BoxOptions -> TextOptions -> [InnerNode d] -> InnerNode d
box label boxOpts textOpts nodes = InlineBox label (Box nodes textOpts) boxOpts
text :: d -> String -> InnerNode d
text label contents = TextSequence label (pack contents)
hardBoxBreakLTRParagraph :: Font -> ParagraphOptions -> Paragraph String
hardBoxBreakLTRParagraph font = constructParagraph
(pack "prefix")
(rootBox t
[ text "text1" "ababab"
, box "box1" b1 t
[ box "box2" b2 t
[ text "text2" "abab\nabab"
]
]
, text "text3" "ababab"
]
)
(pack "suffix")
where
b1 = b_ { boxSpacing = BoxSpacingLeftRight 50 100 }
b2 = b_ { boxSpacing = BoxSpacingLeftRight 150 200 }
t = tLTR { textFont = font, textLanguage = "zxx" }
hardBoxBreakRTLParagraph :: Font -> ParagraphOptions -> Paragraph String
hardBoxBreakRTLParagraph font = constructParagraph
(pack "prefix")
(rootBox t
[ text "text1" "اباباب"
, box "box1" b1 t
[ box "box2" b2 t
[ text "text2" "اباب\nاباب"
]
]
, text "text3" "اباباب"
]
)
(pack "suffix")
where
b1 = b_ { boxSpacing = BoxSpacingLeftRight 50 100 }
b2 = b_ { boxSpacing = BoxSpacingLeftRight 150 200 }
t = tRTL { textFont = font, textLanguage = "zxx" }
-- | Filler text using the Latin script.
-- Source: <https://www.lipsum.com/>
loremIpsumParagraph :: Font -> ParagraphOptions -> Paragraph String
loremIpsumParagraph font = constructParagraph
(pack "xxxx")
(rootBox t
[ text "text" "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
]
)
(pack "z")
where
t = tLTR { textFont = font, textLanguage = "zxx" }
mixedSizesParagraph :: (Font, Font) -> ParagraphOptions -> Paragraph String
mixedSizesParagraph (bigFont, smallFont) = constructParagraph
(pack "prefix")
(rootBox tBig
[ text "bigText1" "big "
, box "smallBox1" b_ tSmall
[ text "smallText1" "small "
]
, text "bigText2" "big "
, box "smallBox2" b_ tSmall
[ text "smallText2" "small "
]
, text "bigText3" "big"
]
)
(pack "suffix")
where
tBig = tLTR { textFont = bigFont, textLanguage = "en" }
tSmall = tLTR { textFont = smallFont, textLanguage = "en" }
nestedBoxesParagraph :: Font -> ParagraphOptions -> Paragraph String
nestedBoxesParagraph font = constructParagraph
(pack "prefix")
(rootBox t
[ text "text1" "this paragraph has "
, box "box2" b_ t
[ box "box3" b_ t
[ text "text2" "nested "
]
, text "text3" "boxes"
]
]
)
(pack "suffix")
where
t = tLTR { textFont = font, textLanguage = "en" }