From 04fdd17a9811ee19b7ab9537b709171aab2d23a5 Mon Sep 17 00:00:00 2001 From: Jaro Date: Fri, 19 May 2023 10:39:30 +0200 Subject: [PATCH] Add Arabic examples to spanToRuns tests. --- .../Text/ParagraphLayout/Internal/RunSpec.hs | 35 +++++++++++++++++ test/Data/Text/ParagraphLayout/SpanData.hs | 38 ++++++++++++++++++- 2 files changed, 72 insertions(+), 1 deletion(-) diff --git a/test/Data/Text/ParagraphLayout/Internal/RunSpec.hs b/test/Data/Text/ParagraphLayout/Internal/RunSpec.hs index 2d5ba37..7ec3f5b 100644 --- a/test/Data/Text/ParagraphLayout/Internal/RunSpec.hs +++ b/test/Data/Text/ParagraphLayout/Internal/RunSpec.hs @@ -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" + } + ] diff --git a/test/Data/Text/ParagraphLayout/SpanData.hs b/test/Data/Text/ParagraphLayout/SpanData.hs index daaed20..810f1f5 100644 --- a/test/Data/Text/ParagraphLayout/SpanData.hs +++ b/test/Data/Text/ParagraphLayout/SpanData.hs @@ -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: +-- +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 = [] + } -- 2.30.2