~jaro/balkon

81d758baf4c7f7ab803edccb4dd1bb7e82a4753d — Jaro 11 months ago ff8e9d3
Test handling of empty lines.
A .golden/richParagraphLayout/newline1Paragraph.golden => .golden/richParagraphLayout/newline1Paragraph.golden +15 -0
@@ 0,0 1,15 @@
ParagraphLayout
    { paragraphRect = Rect {x_origin = 0, y_origin = 0, x_size = 0, y_size = -1500}
    , paragraphFragments =
        [ Fragment
            { fragmentUserData = "text"
            , fragmentLine = 1
            , fragmentAncestorBoxes =
                []
            , fragmentRect = Rect {x_origin = 0, y_origin = 0, x_size = 0, y_size = -1500}
            , fragmentPen = (0, -1085)
            , fragmentGlyphs =
                []
            }
        ]
    }

A .golden/richParagraphLayout/newline1TextParagraph.golden => .golden/richParagraphLayout/newline1TextParagraph.golden +26 -0
@@ 0,0 1,26 @@
ParagraphLayout
    { paragraphRect = Rect {x_origin = 0, y_origin = 0, x_size = 351, y_size = -3000}
    , paragraphFragments =
        [ Fragment
            { fragmentUserData = "text"
            , fragmentLine = 1
            , fragmentAncestorBoxes =
                []
            , fragmentRect = Rect {x_origin = 0, y_origin = 0, x_size = 0, y_size = -1500}
            , fragmentPen = (0, -1085)
            , fragmentGlyphs =
                []
            }
        , Fragment
            { fragmentUserData = "text"
            , fragmentLine = 2
            , fragmentAncestorBoxes =
                []
            , fragmentRect = Rect {x_origin = 0, y_origin = -1500, x_size = 351, y_size = -1500}
            , fragmentPen = (0, -1085)
            , fragmentGlyphs =
                [ (GlyphInfo {codepoint = 26, cluster = 7, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False}, GlyphPos {x_advance = 351, y_advance = 0, x_offset = 0, y_offset = 0})
                ]
            }
        ]
    }

A .golden/richParagraphLayout/newline2Paragraph.golden => .golden/richParagraphLayout/newline2Paragraph.golden +25 -0
@@ 0,0 1,25 @@
ParagraphLayout
    { paragraphRect = Rect {x_origin = 0, y_origin = 0, x_size = 0, y_size = -3000}
    , paragraphFragments =
        [ Fragment
            { fragmentUserData = "text"
            , fragmentLine = 1
            , fragmentAncestorBoxes =
                []
            , fragmentRect = Rect {x_origin = 0, y_origin = 0, x_size = 0, y_size = -1500}
            , fragmentPen = (0, -1085)
            , fragmentGlyphs =
                []
            }
        , Fragment
            { fragmentUserData = "text"
            , fragmentLine = 2
            , fragmentAncestorBoxes =
                []
            , fragmentRect = Rect {x_origin = 0, y_origin = -1500, x_size = 0, y_size = -1500}
            , fragmentPen = (0, -1085)
            , fragmentGlyphs =
                []
            }
        ]
    }

A .golden/richParagraphLayout/newline2TextParagraph.golden => .golden/richParagraphLayout/newline2TextParagraph.golden +36 -0
@@ 0,0 1,36 @@
ParagraphLayout
    { paragraphRect = Rect {x_origin = 0, y_origin = 0, x_size = 351, y_size = -4500}
    , paragraphFragments =
        [ Fragment
            { fragmentUserData = "text"
            , fragmentLine = 1
            , fragmentAncestorBoxes =
                []
            , fragmentRect = Rect {x_origin = 0, y_origin = 0, x_size = 0, y_size = -1500}
            , fragmentPen = (0, -1085)
            , fragmentGlyphs =
                []
            }
        , Fragment
            { fragmentUserData = "text"
            , fragmentLine = 2
            , fragmentAncestorBoxes =
                []
            , fragmentRect = Rect {x_origin = 0, y_origin = -1500, x_size = 0, y_size = -1500}
            , fragmentPen = (0, -1085)
            , fragmentGlyphs =
                []
            }
        , Fragment
            { fragmentUserData = "text"
            , fragmentLine = 3
            , fragmentAncestorBoxes =
                []
            , fragmentRect = Rect {x_origin = 0, y_origin = -3000, x_size = 351, y_size = -1500}
            , fragmentPen = (0, -1085)
            , fragmentGlyphs =
                [ (GlyphInfo {codepoint = 26, cluster = 8, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False}, GlyphPos {x_advance = 351, y_advance = 0, x_offset = 0, y_offset = 0})
                ]
            }
        ]
    }

M test/Data/Text/ParagraphLayout/Rich/ParagraphData.hs => test/Data/Text/ParagraphLayout/Rich/ParagraphData.hs +36 -0
@@ 10,6 10,10 @@ module Data.Text.ParagraphLayout.Rich.ParagraphData
    , mixedSizesParagraph
    , nestedBoxesParagraph
    , neutralDirectionParagraph
    , newline1Paragraph
    , newline1TextParagraph
    , newline2Paragraph
    , newline2TextParagraph
    , softBreakParagraph
    )
where


@@ 261,6 265,38 @@ neutralDirectionParagraph dir font = constructParagraph
    where
        t = (defaultTextOptions dir) { textFont = font, textLanguage = "zxx" }

newline1Paragraph :: Font -> ParagraphOptions -> Paragraph String
newline1Paragraph font = constructParagraph
    (pack "prefix")
    (rootBox t [ text "text" "\n" ])
    (pack "suffix")
    where
        t = tRTL { textFont = font, textLanguage = "zxx" }

newline1TextParagraph :: Font -> ParagraphOptions -> Paragraph String
newline1TextParagraph font = constructParagraph
    (pack "prefix")
    (rootBox t [ text "text" "\nt" ])
    (pack "suffix")
    where
        t = tRTL { textFont = font, textLanguage = "zxx" }

newline2Paragraph :: Font -> ParagraphOptions -> Paragraph String
newline2Paragraph font = constructParagraph
    (pack "prefix")
    (rootBox t [ text "text" "\n\n" ])
    (pack "suffix")
    where
        t = tRTL { textFont = font, textLanguage = "zxx" }

newline2TextParagraph :: Font -> ParagraphOptions -> Paragraph String
newline2TextParagraph font = constructParagraph
    (pack "prefix")
    (rootBox t [ text "text" "\n\nt" ])
    (pack "suffix")
    where
        t = tRTL { textFont = font, textLanguage = "zxx" }

softBreakParagraph :: Int32 -> Font -> ParagraphOptions -> Paragraph String
softBreakParagraph spacing font = constructParagraph
    (pack "prefix")

M test/Data/Text/ParagraphLayout/RichSpec.hs => test/Data/Text/ParagraphLayout/RichSpec.hs +24 -0
@@ 127,6 127,30 @@ spec = do
        describe "with Arabic font" $ do
            font <- runIO $ loadFont arabicFont 0 testingOptions

            it "makes space for one newline" $ do
                let opts = defaultParagraphOptions
                let input = newline1Paragraph font opts
                let result = layoutRich input
                result `shouldBeGolden` "newline1Paragraph"

            it "makes space for one newline plus text" $ do
                let opts = defaultParagraphOptions
                let input = newline1TextParagraph font opts
                let result = layoutRich input
                result `shouldBeGolden` "newline1TextParagraph"

            it "makes space for two newlines" $ do
                let opts = defaultParagraphOptions
                let input = newline2Paragraph font opts
                let result = layoutRich input
                result `shouldBeGolden` "newline2Paragraph"

            it "makes space for two newlines plus text" $ do
                let opts = defaultParagraphOptions
                let input = newline2TextParagraph font opts
                let result = layoutRich input
                result `shouldBeGolden` "newline2TextParagraph"

            it "handles hard break in RTL boxes" $ do
                let opts = defaultParagraphOptions
                let input = hardBoxBreakRTLParagraph font opts