~jaro/balkon

8067edb9bfff08bbf03aa67c6cc57efbc20f4531 — Jaro 1 year, 7 months ago 28ccd0e
Deduplicate code in SpanData.
1 files changed, 20 insertions(+), 62 deletions(-)

M test/Data/Text/ParagraphLayout/SpanData.hs
M test/Data/Text/ParagraphLayout/SpanData.hs => test/Data/Text/ParagraphLayout/SpanData.hs +20 -62
@@ 19,84 19,42 @@ import Data.Text.ParagraphLayout.Internal.TextOptions
defaultBox :: Direction -> ResolvedBox ()
defaultBox dir = ResolvedBox () 0 defaultBoxOptions dir

emptySpan :: Font -> ResolvedSpan ()
emptySpan font = ResolvedSpan
sampleSpan :: Direction -> String -> String -> Font -> ResolvedSpan ()
sampleSpan dir lang str font = ResolvedSpan
    { spanUserData = ()
    , spanIndex = 0
    , spanOffsetInParagraph = 0
    , spanText = pack ""
    , spanTextOptions = (defaultTextOptions DirLTR)
    , spanText = text
    , spanTextOptions = (defaultTextOptions dir)
        { textFont = font
        , textLineHeight = Normal
        , textLanguage = "en"
        , textLanguage = lang
        }
    , spanBoxes = [defaultBox DirLTR]
    , spanBoxes = [defaultBox dir]
    , spanLineBreaks = []
    , spanCharacterBreaks = []
    }
    where
        text = pack str

emptySpan :: Font -> ResolvedSpan ()
emptySpan = sampleSpan DirLTR "en"
    ""

czechHello :: Font -> ResolvedSpan ()
czechHello font = ResolvedSpan
    { spanUserData = ()
    , spanIndex = 0
    , spanOffsetInParagraph = 0
    , spanText = pack "Ahoj, světe!"
    , spanTextOptions = (defaultTextOptions DirLTR)
        { textFont = font
        , textLineHeight = Normal
        , textLanguage = "cs"
        }
    , spanBoxes = [defaultBox DirLTR]
    , spanLineBreaks = []
    , spanCharacterBreaks = []
    }
czechHello = sampleSpan DirLTR "cs"
    "Ahoj, světe!"

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 = []
    }
arabicHello = sampleSpan DirRTL "ar"
    "سلام"

serbianMixedScript :: Font -> ResolvedSpan ()
serbianMixedScript font = ResolvedSpan
    { spanUserData = ()
    , spanIndex = 0
    , spanOffsetInParagraph = 0
    , spanText = pack "Vikipedija (Википедија)"
    , spanTextOptions = (defaultTextOptions DirLTR)
        { textFont = font
        , textLineHeight = Normal
        , textLanguage = "sr"
        }
    , spanBoxes = [defaultBox DirLTR]
    , spanLineBreaks = []
    , spanCharacterBreaks = []
    }
serbianMixedScript = sampleSpan DirLTR "sr"
    "Vikipedija (Википедија)"

-- | 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 = []
    }
englishAroundArabic = sampleSpan DirLTR "en"
    "The title is مفتاح معايير الويب in Arabic."