From d2da70ca731a9161efaa12fc0dbd8b24783ba161 Mon Sep 17 00:00:00 2001 From: Jaro Date: Thu, 29 Jun 2023 22:34:05 +0200 Subject: [PATCH] Store parent text options in ResolvedBox. This is required for vertically aligning the box with its parent. --- src/Data/Text/ParagraphLayout/Internal/ResolvedBox.hs | 2 ++ src/Data/Text/ParagraphLayout/Internal/Tree.hs | 5 +++-- test/Data/Text/ParagraphLayout/Internal/ApplyBoxesSpec.hs | 3 ++- test/Data/Text/ParagraphLayout/Internal/RunSpec.hs | 3 ++- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Data/Text/ParagraphLayout/Internal/ResolvedBox.hs b/src/Data/Text/ParagraphLayout/Internal/ResolvedBox.hs index 552212c..f3b0a5d 100644 --- a/src/Data/Text/ParagraphLayout/Internal/ResolvedBox.hs +++ b/src/Data/Text/ParagraphLayout/Internal/ResolvedBox.hs @@ -13,12 +13,14 @@ import Data.Int (Int32) import Data.Text.Glyphize (Direction (DirLTR, DirRTL)) import Data.Text.ParagraphLayout.Internal.BoxOptions +import Data.Text.ParagraphLayout.Internal.TextOptions -- | Internal structure describing an inline box. -- May be shared by multiple fragments. data ResolvedBox d = ResolvedBox { boxUserData :: d , boxIndex :: Int + , boxParentTextOptions :: TextOptions , boxOptions :: BoxOptions , boxDirection :: Direction } diff --git a/src/Data/Text/ParagraphLayout/Internal/Tree.hs b/src/Data/Text/ParagraphLayout/Internal/Tree.hs index 64e3df1..e53136b 100644 --- a/src/Data/Text/ParagraphLayout/Internal/Tree.hs +++ b/src/Data/Text/ParagraphLayout/Internal/Tree.hs @@ -142,9 +142,10 @@ flattenNode :: Int -> BoxPath d -> TextOptions -> InnerNode t d -> (Int, [Leaf t d]) flattenNode idx path textOpts (TextSequence d t) = (idx, [TextLeaf d t textOpts path]) -flattenNode idx path _ (InlineBox d (Box ns textOpts) boxOpts) = - flattenNodes (idx + 1) (ResolvedBox d idx boxOpts dir : path) textOpts ns +flattenNode idx path parentTextOpts (InlineBox d (Box ns textOpts) boxOpts) = + flattenNodes (idx + 1) box textOpts ns where + box = ResolvedBox d idx parentTextOpts boxOpts dir : path dir = textDirection textOpts -- | Concatenate all pieces of text from a `Text` tree, plus an optional prefix diff --git a/test/Data/Text/ParagraphLayout/Internal/ApplyBoxesSpec.hs b/test/Data/Text/ParagraphLayout/Internal/ApplyBoxesSpec.hs index f83b5e1..b37e6c6 100644 --- a/test/Data/Text/ParagraphLayout/Internal/ApplyBoxesSpec.hs +++ b/test/Data/Text/ParagraphLayout/Internal/ApplyBoxesSpec.hs @@ -14,7 +14,8 @@ import Data.Text.ParagraphLayout.Internal.TextOptions import Data.Text.ParagraphLayout.Internal.WithSpan trivialBox :: d -> Int -> Direction -> ResolvedBox d -trivialBox d i dir = ResolvedBox d i defaultBoxOptions dir +trivialBox d i dir = + ResolvedBox d i (defaultTextOptions dir) defaultBoxOptions dir trivialSpan :: d -> Int -> Direction -> [ResolvedBox d] -> ResolvedSpan d trivialSpan d i dir bs = ResolvedSpan diff --git a/test/Data/Text/ParagraphLayout/Internal/RunSpec.hs b/test/Data/Text/ParagraphLayout/Internal/RunSpec.hs index 8c7019c..699cfb7 100644 --- a/test/Data/Text/ParagraphLayout/Internal/RunSpec.hs +++ b/test/Data/Text/ParagraphLayout/Internal/RunSpec.hs @@ -15,7 +15,8 @@ import Data.Text.ParagraphLayout.RunLengthEncoding import Data.Text.ParagraphLayout.TextData defaultBox :: Direction -> ResolvedBox () -defaultBox dir = ResolvedBox () 0 defaultBoxOptions dir +defaultBox dir = + ResolvedBox () 0 (defaultTextOptions dir) defaultBoxOptions dir sampleSpan :: (Direction, String, Text, a) -> TextLevels -> ResolvedSpan () sampleSpan (dir, lang, text, _) levels = ResolvedSpan -- 2.30.2