~jaro/balkon

efcef179a0e0ca9bf126b3b5a32a8094f55faaf5 — Jaro 1 year, 6 months ago 882969e
Add required textDirection to TextOptions.
M CHANGELOG.md => CHANGELOG.md +2 -0
@@ 7,6 7,8 @@
    * Supports multiple fonts in the same paragraph. Where line height varies,
      text will be aligned by its top edge.

    * Requires user to set base text direction (LTR or RTL).

* Moved existing plain text interface into `Data.Text.ParagraphLayout.Plain`
  submodule and marked it as deprecated.


M lib/Data/Text/ParagraphLayout/Rich.hs => lib/Data/Text/ParagraphLayout/Rich.hs +1 -0
@@ 33,6 33,7 @@ module Data.Text.ParagraphLayout.Rich
    , textFont
    , textLineHeight
    , textLanguage
    , textDirection
    -- ** Verification
    , paragraphSpanBounds
    , paragraphSpanTexts

M src/Data/Text/ParagraphLayout/Internal/Plain.hs => src/Data/Text/ParagraphLayout/Internal/Plain.hs +3 -1
@@ 2,6 2,8 @@
module Data.Text.ParagraphLayout.Internal.Plain (layoutPlain)
where

import Data.Text.Glyphize (Direction (DirLTR))

import Data.Text.ParagraphLayout.Internal.BoxOptions
import Data.Text.ParagraphLayout.Internal.Fragment
import Data.Text.ParagraphLayout.Internal.ParagraphOptions


@@ 36,7 38,7 @@ plainToRich (P.Paragraph arr off spans opts) = R.Paragraph arr off rootNode opts
            (boxFromPlain baseOpts i s)
            defaultBoxOptions
        indexedSpans = zip [0 ..] spans
        baseOpts = defaultTextOptions
        baseOpts = (defaultTextOptions DirLTR)
            { textFont = paragraphFont opts
            , textLineHeight = paragraphLineHeight opts
            }

M src/Data/Text/ParagraphLayout/Internal/TextOptions.hs => src/Data/Text/ParagraphLayout/Internal/TextOptions.hs +14 -4
@@ 4,7 4,7 @@ module Data.Text.ParagraphLayout.Internal.TextOptions
    )
where

import Data.Text.Glyphize (Font, emptyFont)
import Data.Text.Glyphize (Direction, Font, emptyFont)

import Data.Text.ParagraphLayout.Internal.LineHeight



@@ 31,10 31,16 @@ data TextOptions = TextOptions
    -- Used for selecting the appropriate glyphs and line breaking rules,
    -- primarily in East Asian languages.

    , textDirection :: Direction
    -- ^ Base text direction.
    -- Used to determine which box fragment gets the left spacing and which
    -- gets the right spacing when broken over multiple lines.
    --
    -- TODO: Also use for the visual order of boxes.

    -- TODO: textVerticalAlign
    -- TODO: textLetterSpacing
    -- TODO: textWordSpacing
    -- TODO: textDirection
    -- TODO: textFontFeatures
    -- TODO: textSoftBreaks



@@ 42,9 48,13 @@ data TextOptions = TextOptions
    deriving (Eq)

-- | `TextOptions` with default values.
defaultTextOptions :: TextOptions
defaultTextOptions = TextOptions
defaultTextOptions
    :: Direction
    -- ^ Required value for `textDirection`.
    -> TextOptions
defaultTextOptions dir = TextOptions
    { textFont = emptyFont
    , textLineHeight = Normal
    , textLanguage = ""
    , textDirection = dir
    }

M test/Data/Text/ParagraphLayout/Internal/TreeSpec.hs => test/Data/Text/ParagraphLayout/Internal/TreeSpec.hs +12 -9
@@ 6,6 6,9 @@ import Data.Text.ParagraphLayout.Internal.ResolvedBox
import Data.Text.ParagraphLayout.Internal.TextOptions
import Data.Text.ParagraphLayout.Internal.Tree

t :: TextOptions
t = defaultTextOptions undefined

complexTree :: RootNode String
complexTree = RootBox $ Box
    [ TextSequence "a" 1


@@ 20,7 23,7 @@ complexTree = RootBox $ Box
                    [ TextSequence "d" 1
                    , TextSequence "e" 1
                    ]
                    defaultTextOptions
                    t
                )
                defaultBoxOptions
            , TextSequence "f" 1


@@ 33,16 36,16 @@ complexTree = RootBox $ Box
                        (Box
                            [ TextSequence "h" 1
                            ]
                            defaultTextOptions
                            t
                        )
                        defaultBoxOptions
                    , TextSequence "i" 1
                    ]
                    defaultTextOptions
                    t
                )
                defaultBoxOptions
            ]
            defaultTextOptions
            t
        )
        defaultBoxOptions
    , InlineBox


@@ 54,7 57,7 @@ complexTree = RootBox $ Box
                    [ TextSequence "j" 1
                    , TextSequence "k" 1
                    ]
                    defaultTextOptions
                    t
                )
                defaultBoxOptions
            , InlineBox


@@ 65,20 68,20 @@ complexTree = RootBox $ Box
                        (Box
                            [ TextSequence "l" 1
                            ]
                            defaultTextOptions
                            t
                        )
                        defaultBoxOptions
                    ]
                    defaultTextOptions
                    t
                )
                defaultBoxOptions
            , TextSequence "m" 1
            ]
            defaultTextOptions
            t
        )
        defaultBoxOptions
    ]
    defaultTextOptions
    t

leafData :: Leaf d -> d
leafData (TextLeaf d _ _ _) = d

M test/Data/Text/ParagraphLayout/Rich/ParagraphData.hs => test/Data/Text/ParagraphLayout/Rich/ParagraphData.hs +2 -2
@@ 6,7 6,7 @@ module Data.Text.ParagraphLayout.Rich.ParagraphData
where

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

import Data.Text.ParagraphLayout.Internal.BoxOptions
import Data.Text.ParagraphLayout.Internal.ParagraphOptions


@@ 15,7 15,7 @@ import Data.Text.ParagraphLayout.Internal.TextOptions
import Data.Text.ParagraphLayout.Internal.TreeOfTexts

t_ :: TextOptions
t_ = defaultTextOptions
t_ = defaultTextOptions DirLTR

b_ :: BoxOptions
b_ = defaultBoxOptions

M test/Data/Text/ParagraphLayout/SpanData.hs => test/Data/Text/ParagraphLayout/SpanData.hs +4 -4
@@ 6,7 6,7 @@ module Data.Text.ParagraphLayout.SpanData
where

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

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


@@ 23,7 23,7 @@ emptySpan font = ResolvedSpan
    , spanIndex = 0
    , spanOffsetInParagraph = 0
    , spanText = pack ""
    , spanTextOptions = defaultTextOptions
    , spanTextOptions = (defaultTextOptions DirLTR)
        { textFont = font
        , textLineHeight = Normal
        , textLanguage = "en"


@@ 39,7 39,7 @@ czechHello font = ResolvedSpan
    , spanIndex = 0
    , spanOffsetInParagraph = 0
    , spanText = pack "Ahoj, světe!"
    , spanTextOptions = defaultTextOptions
    , spanTextOptions = (defaultTextOptions DirLTR)
        { textFont = font
        , textLineHeight = Normal
        , textLanguage = "cs"


@@ 55,7 55,7 @@ serbianMixedScript font = ResolvedSpan
    , spanIndex = 0
    , spanOffsetInParagraph = 0
    , spanText = pack "Vikipedija (Википедија)"
    , spanTextOptions = defaultTextOptions
    , spanTextOptions = (defaultTextOptions DirLTR)
        { textFont = font
        , textLineHeight = Normal
        , textLanguage = "sr"