module Data.Text.ParagraphLayout.Internal.ProtoFragment ( ProtoFragment (direction, advance, glyphs, hardBreak) , 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)] , hardBreak :: Bool -- ^ Marks fragment that ends with a forced line break. } -- | Construct a `ProtoFragment`, automatically calculating the total advance -- for a horizontal text direction. protoFragmentH :: Direction -> BiDi.Level -> [(GlyphInfo, GlyphPos)] -> Bool -> ProtoFragment protoFragmentH dir lvl gs hard = ProtoFragment dir lvl adv gs hard where adv = sum $ map (x_advance . snd) gs instance BiDi.WithLevel ProtoFragment where level = level -- BiDi.level = ProtoFragment.level