~jaro/balkon

5fa1efb1b56816aa7c3034856fac9ef709889e99 — Jaro 1 year, 9 months ago 7f62b6d
Decompose ProtoFragment construction.
M src/Data/Text/ParagraphLayout/Internal/Plain.hs => src/Data/Text/ParagraphLayout/Internal/Plain.hs +2 -4
@@ 20,7 20,7 @@ import Data.Text.Glyphize
    ,Direction(..)
    ,FontExtents(..)
    ,GlyphInfo
    ,GlyphPos(x_advance)
    ,GlyphPos
    ,defaultBuffer
    ,fontExtentsForDir
    ,shape


@@ 207,10 207,8 @@ breakSplits closed (x:xs) = splits ++ breakSplits (x:closed) xs
layoutRunH :: WithSpan Run -> WithSpan PF.ProtoFragment
layoutRunH (WithSpan rs run) = WithSpan rs pf
    where
        pf = PF.ProtoFragment dir totalX glyphs
        pf = PF.protoFragmentH dir glyphs
        glyphs = shapeRun (WithSpan rs run)
        positions = map snd glyphs
        totalX = sum $ map x_advance positions
        dir = runDirection run

-- | Calculate layout for the given run independently of its position.

M src/Data/Text/ParagraphLayout/Internal/ProtoFragment.hs => src/Data/Text/ParagraphLayout/Internal/ProtoFragment.hs +12 -2
@@ 1,8 1,11 @@
module Data.Text.ParagraphLayout.Internal.ProtoFragment (ProtoFragment(..))
module Data.Text.ParagraphLayout.Internal.ProtoFragment
    (ProtoFragment(direction, advance, glyphs)
    ,protoFragmentH
    )
where

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

-- | A box fragment which has not been positioned yet.
data ProtoFragment = ProtoFragment


@@ 13,3 16,10 @@ data ProtoFragment = ProtoFragment
    -- 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