~jaro/balkon

balkon/src/Data/Text/ParagraphLayout/Internal/TextOptions.hs -rw-r--r-- 3.0 KiB
9e3b0ec7Jaro Set release date for v1.3.0.0. 1 year, 4 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
module Data.Text.ParagraphLayout.Internal.TextOptions
    ( TextOptions (..)
    , defaultTextOptions
    )
where

import Data.Int (Int32)
import Data.Text.Glyphize (Direction, 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.

    , textAscender :: Maybe Int32
    -- ^ How much to add to the text's baseline coordinate to reach its
    -- ascender line. This is usually a positive value.
    --
    -- If set to `Nothing`, the font's own `Data.Text.Glyphize.ascender`
    -- metric will be used.
    --
    -- Setting an explicit value with @`Just` x@ is intended as an override
    -- for situations where the text is intended to be replaced by an object
    -- with differently calculated dimensions.

    , textDescender :: Maybe Int32
    -- ^ How much to add to the text's baseline coordinate to reach its
    -- descender line. Note that this is usually a negative value because
    -- the descender is usually below the baseline.
    --
    -- If set to `Nothing`, the font's own `Data.Text.Glyphize.descender`
    -- metric will be used.
    --
    -- Setting an explicit value with @`Just` x@ is intended as an override
    -- for situations where the text is intended to be replaced by an object
    -- with differently calculated dimensions.

    , 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.

    , 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.
    --
    -- When applied to the root box in a paragraph, this is also used to
    -- determine the base direction of the paragraph.

    -- TODO: textLetterSpacing
    -- TODO: textWordSpacing
    -- TODO: textFontFeatures
    -- TODO: textSoftBreaks

    }
    deriving (Eq)

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