module Data.Text.ParagraphLayout.Rich.ParagraphData
( hardBoxBreakLTRParagraph
, hardBoxBreakRTLParagraph
, loremIpsumParagraph
, mixedDirectionComplexParagraph
, mixedDirectionSimpleParagraph
, mixedScriptParagraph
, mixedSizesParagraph
, nestedBoxesParagraph
, neutralDirectionParagraph
, softBreakParagraph
)
where
import Data.Int (Int32)
import Data.Text (Text, empty, 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.Tree
import Data.Text.ParagraphLayout.TextData
tLTR :: TextOptions
tLTR = defaultTextOptions DirLTR
tRTL :: TextOptions
tRTL = defaultTextOptions DirRTL
b_ :: BoxOptions
b_ = defaultBoxOptions
rootBox :: TextOptions -> [InnerNode Text d] -> RootNode Text d
rootBox opts nodes = RootBox (Box nodes opts)
box :: d -> BoxOptions -> TextOptions -> [InnerNode Text d] -> InnerNode Text d
box label boxOpts textOpts nodes = InlineBox label (Box nodes textOpts) boxOpts
text :: d -> String -> InnerNode Text 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" }
-- | Edge case:
-- Directionally neutral characters between box boundary and direction boundary.
--
-- In the case of a LTR paragraph, neutral characters should only be considered
-- RTL when surrounded by RTL characters on both sides, otherwise they should
-- be LTR.
--
-- In the case of a RTL paragraph, neutral characters should only be considered
-- LTR when surrounded by LTR characters on both sides, otherwise they should
-- be RTL.
--
-- Box boundaries should not, by default, affect the direction of neutral
-- characters.
mixedDirectionComplexParagraph :: Direction -> Font -> ParagraphOptions ->
Paragraph String
mixedDirectionComplexParagraph dir font = constructParagraph
(pack "prefix")
(rootBox t
[ text "text1" " . > ab . > ba . > "
, box "box1" b_ t
[ text "text2" " . > اب . > با . > tu . > ut . > "
]
, text "text3" " . > تو . > وت . > "
]
)
(pack "suffix")
where
t = (defaultTextOptions dir) { textFont = font, textLanguage = "zxx" }
-- | A paragraph that contains only strongly directional letters of mixed
-- directions, no spaces or other neutral characters, for basic BiDi tests.
mixedDirectionSimpleParagraph :: Direction -> Font -> ParagraphOptions ->
Paragraph String
mixedDirectionSimpleParagraph dir font = constructParagraph
empty
(rootBox t [TextSequence "text" textContents])
empty
where
t = (defaultTextOptions dir) { textFont = font, textLanguage = lang }
(_, lang, textContents, _) = mixedDirectionSimple dir
mixedScriptParagraph :: Font -> ParagraphOptions -> Paragraph String
mixedScriptParagraph font = constructParagraph
(pack "prefix")
(rootBox t
[ text "text1" "jjjжжж"
-- Box starting on script boundary:
, box "box1" b1 t
-- Box continuing over script boundary:
[ text "text2" "jjjжжж" ]
-- Box ending outside script boundary:
, text "text3" "жжж"
-- Box starting outside script boundary:
, box "box2" b2 t
-- Box continuing over two script boundaries:
[ text "text4" "жжжjjjжжж" ]
-- Box ending on script boundary:
, text "text5" "jjj"
]
)
(pack "suffix")
where
b1 = b_ { boxSpacing = BoxSpacingLeftRight 50 100 }
b2 = b_ { boxSpacing = BoxSpacingLeftRight 150 200 }
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" }
-- | A paragraph that contains only characters in the BiDi class
-- /Other neutrals (ON)/. This includes characters that can be mirrored.
neutralDirectionParagraph :: Direction -> Font -> ParagraphOptions ->
Paragraph String
neutralDirectionParagraph dir font = constructParagraph
(pack "_»")
(rootBox t [text "text" "…―>"])
(pack "*†")
where
t = (defaultTextOptions dir) { textFont = font, textLanguage = "zxx" }
softBreakParagraph :: Int32 -> Font -> ParagraphOptions -> Paragraph String
softBreakParagraph spacing font = constructParagraph
(pack "prefix")
(rootBox t
[ text "text1" "Lorem "
, text "text2" "ipsum "
, box "box2" b t
[ text "text3" "dolor "
, text "text4" "sit "
, text "text5" "amet,"
]
]
)
(pack "suffix")
where
b = b_ { boxSpacing = BoxSpacingLeftRight spacing spacing }
t = tLTR { textFont = font, textLanguage = "en" }