~jaro/balkon

ref: 88a5b6c714c5543b01d63d836ad403b5755d8d76 balkon/src/Data/Text/ParagraphLayout/Internal/ProtoFragment.hs -rw-r--r-- 1.2 KiB
88a5b6c7Jaro Test shaping across intra-word breaks. 1 year, 5 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
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))

import qualified Data.Text.ParagraphLayout.Internal.BiDiLevels as BiDi

-- | A box fragment which has not been positioned yet.
data ProtoFragment = ProtoFragment
    { direction :: Direction
    -- ^ Text direction, which is constant within a fragment.
    , level :: BiDi.Level
    -- ^ BiDi embedding level.
    -- Should be even for LTR fragments and odd for RTL fragments.
    , 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 :: Direction -> BiDi.Level -> [(GlyphInfo, GlyphPos)] ->
    ProtoFragment
protoFragmentH dir lvl gs = ProtoFragment dir lvl adv gs
    where
        adv = sum $ map (x_advance . snd) gs

instance BiDi.WithLevel ProtoFragment where
    level = level -- BiDi.level = ProtoFragment.level