~jaro/balkon

63a571647035682e5d177186b58d59a58ce37a8c — Jaro 1 year, 18 days ago a0aa097
Define BoxOptions and TextOptions for formatting.

Differentiating the two record types reflects the fact that the root
inline box cannot be styled but its text contents can.
M balkon.cabal => balkon.cabal +2 -0
@@ 102,6 102,7 @@ library balkon-internal
    -- Modules exported to tests and to the public part of the library.
    exposed-modules:
        Data.Text.ParagraphLayout.Internal.BiDiReorder,
        Data.Text.ParagraphLayout.Internal.BoxOptions,
        Data.Text.ParagraphLayout.Internal.Break,
        Data.Text.ParagraphLayout.Internal.Fragment,
        Data.Text.ParagraphLayout.Internal.LineHeight,


@@ 117,6 118,7 @@ library balkon-internal
        Data.Text.ParagraphLayout.Internal.Run,
        Data.Text.ParagraphLayout.Internal.Span,
        Data.Text.ParagraphLayout.Internal.TextContainer,
        Data.Text.ParagraphLayout.Internal.TextOptions,
        Data.Text.ParagraphLayout.Internal.Zipper

    -- Modules used purely internally and not in any tests.

A src/Data/Text/ParagraphLayout/Internal/BoxOptions.hs => src/Data/Text/ParagraphLayout/Internal/BoxOptions.hs +52 -0
@@ 0,0 1,52 @@
module Data.Text.ParagraphLayout.Internal.BoxOptions
    ( BoxOptions (..)
    , BoxSpacing (..)
    , defaultBoxOptions
    )
where

import Data.Int (Int32)

-- | Style options to be applied to an inline box.
--
-- This record type is likely to be extended in the future.
-- Use `defaultBoxOptions` and update it with specific record selectors
-- instead of constructing `BoxOptions` directly.
data BoxOptions = BoxOptions

    { boxSpacing :: BoxSpacing
    -- Determines amount of empty space to add before the first fragment
    -- and/or after the last fragment of this box.
    --
    -- This can be used to reserve space for a left margin, border,
    -- and/or padding.

    }
    deriving (Eq)

-- | Determines the amount of empty space to add around a box.
data BoxSpacing

    -- | Specification using absolute directions, unaffected by text direction.
    --
    -- (However, text direction is still used in case of fragmentation,
    -- to determine how to map the first (last) fragment to left (right).)
    = BoxSpacingLeftRight

        Int32
        -- ^ Amount of empty space to add to the left side of the
        -- first fragment (for LTR text) or last fragment (for RTL text)
        -- created from this box.

        Int32
        -- ^ Amount of empty space to add to the right side of the
        -- first fragment (for RTL text) or last fragment (for LTR text)
        -- created from this box.

    deriving (Eq, Show, Read)

-- | `BoxOptions` with default values.
defaultBoxOptions :: BoxOptions
defaultBoxOptions = BoxOptions
    { boxSpacing = BoxSpacingLeftRight 0 0
    }

A src/Data/Text/ParagraphLayout/Internal/TextOptions.hs => src/Data/Text/ParagraphLayout/Internal/TextOptions.hs +50 -0
@@ 0,0 1,50 @@
module Data.Text.ParagraphLayout.Internal.TextOptions
    ( TextOptions (..)
    , defaultTextOptions
    )
where

import Data.Text.Glyphize (Font, emptyFont)

import Data.Text.ParagraphLayout.Internal.LineHeight

-- | Style options to be applied to a text sequence.
--
-- This record type is likely to be extended in the future.
-- Use `defaultTextOptions` and update it with specific record selectors
-- instead of constructing `TextOptions` directly.
data TextOptions = TextOptions

    { textFont :: Font
    -- ^ Font to be used for shaping and measurement.
    -- Make sure to set its scale (see `Data.Text.Glyphize.optionScale`) using
    -- the same units that you want in the output.

    , textLineHeight :: LineHeight
    -- ^ Preferred line height of the resulting fragments.

    , textLanguage :: String
    -- ^ IETF BCP 47 language tag, such as the value expected to be found in
    -- the HTML @lang@ attribute, specifying the primary language for the
    -- span's text content. An empty string explicitly means "language unknown".
    --
    -- Used for selecting the appropriate glyphs and line breaking rules,
    -- primarily in East Asian languages.

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

    }
    deriving (Eq)

-- | `TextOptions` with default values.
defaultTextOptions :: TextOptions
defaultTextOptions = TextOptions
    { textFont = emptyFont
    , textLineHeight = Normal
    , textLanguage = ""
    }