~jaro/balkon

d2da70ca731a9161efaa12fc0dbd8b24783ba161 — Jaro 1 year, 4 months ago e5196ad
Store parent text options in ResolvedBox.

This is required for vertically aligning the box with its parent.
M src/Data/Text/ParagraphLayout/Internal/ResolvedBox.hs => src/Data/Text/ParagraphLayout/Internal/ResolvedBox.hs +2 -0
@@ 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
    }

M src/Data/Text/ParagraphLayout/Internal/Tree.hs => src/Data/Text/ParagraphLayout/Internal/Tree.hs +3 -2
@@ 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

M test/Data/Text/ParagraphLayout/Internal/ApplyBoxesSpec.hs => test/Data/Text/ParagraphLayout/Internal/ApplyBoxesSpec.hs +2 -1
@@ 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

M test/Data/Text/ParagraphLayout/Internal/RunSpec.hs => test/Data/Text/ParagraphLayout/Internal/RunSpec.hs +2 -1
@@ 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