~jaro/balkon

6e011c818a62f3d3ae7554f67f24fc8f3abf031b — Jaro 1 year, 6 months ago 4fda24f
Allow generating an empty run.
M src/Data/Text/ParagraphLayout/Internal/Run.hs => src/Data/Text/ParagraphLayout/Internal/Run.hs +16 -1
@@ 78,7 78,22 @@ considerNext z = case next z of
data Merged a = Incompatible | Merged a

spanToRuns :: ResolvedSpan d -> [Run]
spanToRuns s = snd $ mapAccumL run 0 $ protoRuns zipper levels
spanToRuns s
    | Text.null (spanText s) = [emptyRun]
    | otherwise = spanToRuns' s
    where
        emptyRun = Run
            { runOffsetInSpan = 0
            , runText = Text.empty
            , runLevel = defaultLevel
            , runDirection = levelDirectionH defaultLevel
            , runScript = Nothing
            , runHardBreak = False
            }
        defaultLevel = baseLevel $ spanBiDiLevels s

spanToRuns' :: ResolvedSpan d -> [Run]
spanToRuns' s = snd $ mapAccumL run 0 $ protoRuns zipper levels
    where
        wholeText = spanText s
        zipper = start wholeText

M test/Data/Text/ParagraphLayout/Internal/RunSpec.hs => test/Data/Text/ParagraphLayout/Internal/RunSpec.hs +11 -2
@@ 1,6 1,6 @@
module Data.Text.ParagraphLayout.Internal.RunSpec (spec) where

import Data.Text (Text, pack)
import Data.Text (Text, empty, pack)
import Data.Text.Glyphize (Direction (..), emptyFont)

import Test.Hspec


@@ 49,7 49,16 @@ spec = do
        it "handles span with no text" $ do
            let inputSpan = sampleSpan englishEmpty allLTR
            let runs = spanToRuns inputSpan
            runs `shouldBe` []
            runs `shouldBe`
                [ Run
                    { runOffsetInSpan = 0
                    , runText = empty
                    , runLevel = 0
                    , runDirection = DirLTR
                    , runScript = Nothing
                    , runHardBreak = False
                    }
                ]
        it "handles Czech hello" $ do
            let inputSpan = sampleSpan czechHello allLTR
            let runs = spanToRuns inputSpan