~jaro/balkon

ref: 5eed51e7970bd2a2f5aed8b79ded3cad44728575 balkon/src/Data/Text/ParagraphLayout/Internal/ProtoFragment.hs -rw-r--r-- 875 bytes
5eed51e7Jaro Add test for Devanagari. 1 year, 8 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
module Data.Text.ParagraphLayout.Internal.ProtoFragment
    (ProtoFragment(direction, advance, glyphs)
    ,protoFragmentH
    )
where

import Data.Int (Int32)
import Data.Text.Glyphize (Direction, GlyphInfo, GlyphPos(x_advance))

-- | A box fragment which has not been positioned yet.
data ProtoFragment = ProtoFragment
    { direction :: Maybe Direction
    -- ^ Text direction, which is constant within a fragment.
    , advance :: Int32
    -- ^ Total advance of glyphs in this fragment,
    -- depending on the text direction.
    , glyphs :: [(GlyphInfo, GlyphPos)]
    }

-- | Construct a `ProtoFragment`, automatically calculating the total advance
-- for a horizontal text direction.
protoFragmentH :: Maybe Direction -> [(GlyphInfo, GlyphPos)] -> ProtoFragment
protoFragmentH dir gs = ProtoFragment dir adv gs
    where
        adv = sum $ map (x_advance . snd) gs