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 Data.Text.ParagraphLayout.Internal.BiDiLevels
-- | 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
instance WithLevel ProtoFragment where
level pf = case direction pf of
-- TODO: Allow externally set paragraph embedding level.
-- TODO: Properly calculate BiDi levels.
Just DirLTR -> 0
Just DirRTL -> 1
Just DirTTB -> 0
Just DirBTT -> 1
Nothing -> 0