~jaro/balkon

04fdd17a9811ee19b7ab9537b709171aab2d23a5 — Jaro 1 year, 5 months ago 8b8b095
Add Arabic examples to spanToRuns tests.
M test/Data/Text/ParagraphLayout/Internal/RunSpec.hs => test/Data/Text/ParagraphLayout/Internal/RunSpec.hs +35 -0
@@ 24,6 24,17 @@ spec = do
                    , runScript = Just "Latn"
                    }
                ]
        it "handles Arabic hello" $ do
            let inputSpan = arabicHello emptyFont
            let runs = spanToRuns inputSpan
            runs `shouldBe`
                [ Run
                    { runOffsetInSpan = 0
                    , runText = spanText inputSpan
                    , runDirection = Just DirRTL
                    , runScript = Just "Arab"
                    }
                ]
        it "handles Serbian with mixed script" $ do
            let inputSpan = serbianMixedScript emptyFont
            let runs = spanToRuns inputSpan


@@ 42,3 53,27 @@ spec = do
                    , runScript = Just "Cyrl"
                    }
                ]
        it "handles English text with Arabic inside" $ do
            let inputSpan = englishAroundArabic emptyFont
            let runs = spanToRuns inputSpan
            runs `shouldBe`
                [ Run
                    { runOffsetInSpan = 0
                    , runText = pack "The title is "
                    , runDirection = Just DirLTR
                    , runScript = Just "Latn"
                    }
                , Run
                    { runOffsetInSpan = 13
                    -- TODO: The final space should be excluded.
                    , runText = pack "مفتاح معايير الويب "
                    , runDirection = Just DirRTL
                    , runScript = Just "Arab"
                    }
                , Run
                    { runOffsetInSpan = 48
                    , runText = pack "in Arabic."
                    , runDirection = Just DirLTR
                    , runScript = Just "Latn"
                    }
                ]

M test/Data/Text/ParagraphLayout/SpanData.hs => test/Data/Text/ParagraphLayout/SpanData.hs +37 -1
@@ 1,12 1,14 @@
module Data.Text.ParagraphLayout.SpanData
    ( emptySpan
    , czechHello
    , arabicHello
    , serbianMixedScript
    , englishAroundArabic
    )
where

import Data.Text (pack)
import Data.Text.Glyphize (Direction (DirLTR), Font)
import Data.Text.Glyphize (Direction (DirLTR, DirRTL), Font)

import Data.Text.ParagraphLayout.Internal.BoxOptions
import Data.Text.ParagraphLayout.Internal.LineHeight


@@ 49,6 51,22 @@ czechHello font = ResolvedSpan
    , spanCharacterBreaks = []
    }

arabicHello :: Font -> ResolvedSpan ()
arabicHello font = ResolvedSpan
    { spanUserData = ()
    , spanIndex = 0
    , spanOffsetInParagraph = 0
    , spanText = pack "سلام"
    , spanTextOptions = (defaultTextOptions DirRTL)
        { textFont = font
        , textLineHeight = Normal
        , textLanguage = "ar"
        }
    , spanBoxes = [defaultBox DirRTL]
    , spanLineBreaks = []
    , spanCharacterBreaks = []
    }

serbianMixedScript :: Font -> ResolvedSpan ()
serbianMixedScript font = ResolvedSpan
    { spanUserData = ()


@@ 64,3 82,21 @@ serbianMixedScript font = ResolvedSpan
    , spanLineBreaks = []
    , spanCharacterBreaks = []
    }

-- | Source:
-- <https://www.w3.org/International/articles/inline-bidi-markup/uba-basics>
englishAroundArabic :: Font -> ResolvedSpan ()
englishAroundArabic font = ResolvedSpan
    { spanUserData = ()
    , spanIndex = 0
    , spanOffsetInParagraph = 0
    , spanText = pack "The title is مفتاح معايير الويب in Arabic."
    , spanTextOptions = (defaultTextOptions DirLTR)
        { textFont = font
        , textLineHeight = Normal
        , textLanguage = "en"
        }
    , spanBoxes = [defaultBox DirLTR]
    , spanLineBreaks = []
    , spanCharacterBreaks = []
    }