~jaro/balkon

ddfeaa503aaca344bc22d438fef5af45f7e00463 — Jaro 10 months ago cf3ec3e
Test boxes with no text or only a space.
A .golden/richParagraphLayout/emptyBoxMiddle.golden => .golden/richParagraphLayout/emptyBoxMiddle.golden +46 -0
@@ 0,0 1,46 @@
ParagraphLayout
    { paragraphRect = Rect {x_origin = 0, y_origin = 0, x_size = 5193, y_size = -1121}
    , paragraphFragments =
        [ Fragment
            { fragmentUserData = "text1"
            , fragmentLine = 1
            , fragmentAncestorBoxes =
                []
            , fragmentRect = Rect {x_origin = 0, y_origin = 0, x_size = 3139, y_size = -1121}
            , fragmentPen = (0, -932)
            , fragmentGlyphs =
                [ (GlyphInfo {codepoint = 72, cluster = 6, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False}, GlyphPos {x_advance = 559, y_advance = 0, x_offset = 0, y_offset = 0})
                , (GlyphInfo {codepoint = 80, cluster = 7, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False}, GlyphPos {x_advance = 861, y_advance = 0, x_offset = 0, y_offset = 0})
                , (GlyphInfo {codepoint = 83, cluster = 8, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False}, GlyphPos {x_advance = 589, y_advance = 0, x_offset = 0, y_offset = 0})
                , (GlyphInfo {codepoint = 87, cluster = 9, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False}, GlyphPos {x_advance = 402, y_advance = 0, x_offset = 0, y_offset = 0})
                , (GlyphInfo {codepoint = 92, cluster = 10, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False}, GlyphPos {x_advance = 497, y_advance = 0, x_offset = 0, y_offset = 0})
                , (GlyphInfo {codepoint = 3, cluster = 11, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False}, GlyphPos {x_advance = 231, y_advance = 0, x_offset = 0, y_offset = 0})
                ]
            }
        , Fragment
            { fragmentUserData = "emptyText"
            , fragmentLine = 1
            , fragmentAncestorBoxes =
                [ AncestorBox {boxUserData = "box1", boxLeftEdge = SpacedEdge 50, boxRightEdge = SpacedEdge 100, boxStartEdge = SpacedEdge 50, boxEndEdge = SpacedEdge 100}
                ]
            , fragmentRect = Rect {x_origin = 3189, y_origin = 0, x_size = 0, y_size = -1121}
            , fragmentPen = (0, -932)
            , fragmentGlyphs =
                []
            }
        , Fragment
            { fragmentUserData = "text2"
            , fragmentLine = 1
            , fragmentAncestorBoxes =
                []
            , fragmentRect = Rect {x_origin = 3289, y_origin = 0, x_size = 1904, y_size = -1121}
            , fragmentPen = (0, -932)
            , fragmentGlyphs =
                [ (GlyphInfo {codepoint = 3, cluster = 12, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False}, GlyphPos {x_advance = 231, y_advance = 0, x_offset = 0, y_offset = 0})
                , (GlyphInfo {codepoint = 69, cluster = 13, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False}, GlyphPos {x_advance = 589, y_advance = 0, x_offset = 0, y_offset = 0})
                , (GlyphInfo {codepoint = 82, cluster = 14, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False}, GlyphPos {x_advance = 573, y_advance = 0, x_offset = 0, y_offset = 0})
                , (GlyphInfo {codepoint = 91, cluster = 15, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False}, GlyphPos {x_advance = 511, y_advance = 0, x_offset = 0, y_offset = 0})
                ]
            }
        ]
    }

A .golden/richParagraphLayout/spaceBoxMiddle.golden => .golden/richParagraphLayout/spaceBoxMiddle.golden +45 -0
@@ 0,0 1,45 @@
ParagraphLayout
    { paragraphRect = Rect {x_origin = 0, y_origin = 0, x_size = 4635, y_size = -1121}
    , paragraphFragments =
        [ Fragment
            { fragmentUserData = "text1"
            , fragmentLine = 1
            , fragmentAncestorBoxes =
                []
            , fragmentRect = Rect {x_origin = 0, y_origin = 0, x_size = 2581, y_size = -1121}
            , fragmentPen = (0, -932)
            , fragmentGlyphs =
                [ (GlyphInfo {codepoint = 86, cluster = 6, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False}, GlyphPos {x_advance = 446, y_advance = 0, x_offset = 0, y_offset = 0})
                , (GlyphInfo {codepoint = 83, cluster = 7, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False}, GlyphPos {x_advance = 589, y_advance = 0, x_offset = 0, y_offset = 0})
                , (GlyphInfo {codepoint = 68, cluster = 8, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False}, GlyphPos {x_advance = 522, y_advance = 0, x_offset = 0, y_offset = 0})
                , (GlyphInfo {codepoint = 70, cluster = 9, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False}, GlyphPos {x_advance = 465, y_advance = 0, x_offset = 0, y_offset = 0})
                , (GlyphInfo {codepoint = 72, cluster = 10, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False}, GlyphPos {x_advance = 559, y_advance = 0, x_offset = 0, y_offset = 0})
                ]
            }
        , Fragment
            { fragmentUserData = "text2"
            , fragmentLine = 1
            , fragmentAncestorBoxes =
                [ AncestorBox {boxUserData = "box1", boxLeftEdge = SpacedEdge 50, boxRightEdge = SpacedEdge 100, boxStartEdge = SpacedEdge 50, boxEndEdge = SpacedEdge 100}
                ]
            , fragmentRect = Rect {x_origin = 2631, y_origin = 0, x_size = 231, y_size = -1121}
            , fragmentPen = (0, -932)
            , fragmentGlyphs =
                [ (GlyphInfo {codepoint = 3, cluster = 11, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False}, GlyphPos {x_advance = 231, y_advance = 0, x_offset = 0, y_offset = 0})
                ]
            }
        , Fragment
            { fragmentUserData = "text3"
            , fragmentLine = 1
            , fragmentAncestorBoxes =
                []
            , fragmentRect = Rect {x_origin = 2962, y_origin = 0, x_size = 1673, y_size = -1121}
            , fragmentPen = (0, -932)
            , fragmentGlyphs =
                [ (GlyphInfo {codepoint = 69, cluster = 12, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False}, GlyphPos {x_advance = 589, y_advance = 0, x_offset = 0, y_offset = 0})
                , (GlyphInfo {codepoint = 82, cluster = 13, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False}, GlyphPos {x_advance = 573, y_advance = 0, x_offset = 0, y_offset = 0})
                , (GlyphInfo {codepoint = 91, cluster = 14, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False}, GlyphPos {x_advance = 511, y_advance = 0, x_offset = 0, y_offset = 0})
                ]
            }
        ]
    }

M test/Data/Text/ParagraphLayout/Rich/ParagraphData.hs => test/Data/Text/ParagraphLayout/Rich/ParagraphData.hs +35 -1
@@ 1,5 1,6 @@
module Data.Text.ParagraphLayout.Rich.ParagraphData
    ( hardBoxBreakLTRParagraph
    ( emptyBoxParagraph
    , hardBoxBreakLTRParagraph
    , hardBoxBreakRTLParagraph
    , intraWordBreakParagraph
    , loremIpsumParagraph


@@ 15,6 16,7 @@ module Data.Text.ParagraphLayout.Rich.ParagraphData
    , newline2Paragraph
    , newline2TextParagraph
    , softBreakParagraph
    , spaceBoxParagraph
    )
where



@@ 48,6 50,22 @@ box label boxOpts textOpts nodes = InlineBox label (Box nodes textOpts) boxOpts
text :: d -> String -> InnerNode Text d
text label contents = TextSequence label (pack contents)

emptyBoxParagraph :: Font -> ParagraphOptions -> Paragraph String
emptyBoxParagraph font = constructParagraph
    (pack "prefix")
    (rootBox t
        [ text "text1" "empty "
        , box "box1" b t
            [ text "emptyText" ""
            ]
        , text "text2" " box"
        ]
    )
    (pack "suffix")
    where
        b = b_ { boxSpacing = BoxSpacingLeftRight 50 100 }
        t = tLTR { textFont = font, textLanguage = "en" }

hardBoxBreakLTRParagraph :: Font -> ParagraphOptions -> Paragraph String
hardBoxBreakLTRParagraph font = constructParagraph
    (pack "prefix")


@@ 314,3 332,19 @@ softBreakParagraph spacing font = constructParagraph
    where
        b = b_ { boxSpacing = BoxSpacingLeftRight spacing spacing }
        t = tLTR { textFont = font, textLanguage = "en" }

spaceBoxParagraph :: Font -> ParagraphOptions -> Paragraph String
spaceBoxParagraph font = constructParagraph
    (pack "prefix")
    (rootBox t
        [ text "text1" "space"
        , box "box1" b t
            [ text "text2" " "
            ]
        , text "text3" "box"
        ]
    )
    (pack "suffix")
    where
        b = b_ { boxSpacing = BoxSpacingLeftRight 50 100 }
        t = tLTR { textFont = font, textLanguage = "en" }

M test/Data/Text/ParagraphLayout/RichSpec.hs => test/Data/Text/ParagraphLayout/RichSpec.hs +18 -0
@@ 166,6 166,24 @@ spec = do
                let result = layoutRich input
                result `shouldBeGolden` "mixedScriptWrap"

            it "handles empty box in the middle of the line" $ do
                let opts = defaultParagraphOptions
                        { paragraphAlignment = AlignStart
                        , paragraphMaxWidth = 5193
                        }
                let input = emptyBoxParagraph font opts
                let result = layoutRich input
                result `shouldBeGolden` "emptyBoxMiddle"

            it "handles space box in the middle of the line" $ do
                let opts = defaultParagraphOptions
                        { paragraphAlignment = AlignStart
                        , paragraphMaxWidth = 4635
                        }
                let input = spaceBoxParagraph font opts
                let result = layoutRich input
                result `shouldBeGolden` "spaceBoxMiddle"

            it "handles nested boxes" $ do
                let opts = defaultParagraphOptions
                        { paragraphAlignment = AlignStart