@@ 41,6 41,7 @@ import Data.Text.ParagraphLayout.Internal.WithSpan
-- This is redundant.
-- TODO: Consider using `ResolvedSpan` as `fragmentUserData`, then swapping it
-- for the actual `spanUserData` before returning it to the user.
+type ProtoFragmentWithSpan d = WithSpan d PF.ProtoFragment
type FragmentWithSpan d = WithSpan d (Fragment d)
-- | Create a multi-line layout from the given runs, splitting them as
@@ 67,7 68,7 @@ nonEmptyItems = catMaybes . map nonEmpty . toList
-- The output is a two-dimensional list of fragments positioned along the
-- horizontal axis.
layoutLines ::
- Int32 -> NonEmpty (WithSpan d Run) -> NonEmpty [WithSpan d PF.ProtoFragment]
+ Int32 -> NonEmpty (WithSpan d Run) -> NonEmpty [ProtoFragmentWithSpan d]
layoutLines maxWidth runs = case nonEmpty rest of
-- Everything fits. We are done.
Nothing -> fitting :| []
@@ 85,7 86,7 @@ layoutLines maxWidth runs = case nonEmpty rest of
-- @vertical-align: top@ in CSS.
--
-- TODO: For rich text, allow other types of vertical alignment.
-positionLineH :: Int32 -> (Int, NonEmpty (WithSpan d PF.ProtoFragment)) ->
+positionLineH :: Int32 -> (Int, NonEmpty (ProtoFragmentWithSpan d)) ->
(Int32, NonEmpty (FragmentWithSpan d))
positionLineH originY (line, pfs) = (nextY, frags)
where
@@ 97,7 98,7 @@ positionLineH originY (line, pfs) = (nextY, frags)
-- | Position the given horizontal fragment on a line,
-- using @originY@ as its top edge and @originX@ as its left edge,
-- returning the X coordinate of its right edge for continuation.
-positionFragmentH :: Int -> Int32 -> Int32 -> WithSpan d PF.ProtoFragment ->
+positionFragmentH :: Int -> Int32 -> Int32 -> ProtoFragmentWithSpan d ->
(Int32, FragmentWithSpan d)
positionFragmentH line originY originX (WithSpan rs pf) =
(nextX, WithSpan rs frag)
@@ 122,7 123,7 @@ positionFragmentH line originY originX (WithSpan rs pf) =
-- to fit as much content as possible without exceeding the maximum line width,
-- and return the remaining runs to be placed on other lines.
layoutAndWrapRunsH :: Int32 -> NonEmpty (WithSpan d Run) ->
- ([WithSpan d PF.ProtoFragment], [WithSpan d Run])
+ ([ProtoFragmentWithSpan d], [WithSpan d Run])
layoutAndWrapRunsH maxWidth runs = NonEmpty.head $ validLayouts
where
validLayouts = dropWhile1 tooLong layouts
@@ 205,15 206,15 @@ dropWhile1 p list = case NonEmpty.uncons list of
-- | Calculate layout for multiple horizontal runs on the same line, without
-- any breaking.
-layoutRunsH :: [WithSpan d Run] -> [WithSpan d PF.ProtoFragment]
+layoutRunsH :: [WithSpan d Run] -> [ProtoFragmentWithSpan d]
layoutRunsH runs = map layoutRunH runs
-- | Sum of all advances within the given fragments.
-totalAdvances :: [WithSpan d PF.ProtoFragment] -> Int32
+totalAdvances :: [ProtoFragmentWithSpan d] -> Int32
totalAdvances pfs = sum $ map (\ (WithSpan _ pf) -> PF.advance pf) pfs
-- | Calculate layout for the given horizontal run and attach extra information.
-layoutRunH :: WithSpan d Run -> WithSpan d PF.ProtoFragment
+layoutRunH :: WithSpan d Run -> ProtoFragmentWithSpan d
layoutRunH (WithSpan rs run) = WithSpan rs pf
where
pf = PF.protoFragmentH dir glyphs