@@ 128,11 128,11 @@ library balkon-internal
Data.Text.ParagraphLayout.Internal.Fragment,
Data.Text.ParagraphLayout.Internal.LineHeight,
Data.Text.ParagraphLayout.Internal.LinePagination,
+ Data.Text.ParagraphLayout.Internal.Paginable,
Data.Text.ParagraphLayout.Internal.Paragraph,
Data.Text.ParagraphLayout.Internal.ParagraphConstruction,
Data.Text.ParagraphLayout.Internal.ParagraphLayout,
Data.Text.ParagraphLayout.Internal.ParagraphLine,
- Data.Text.ParagraphLayout.Internal.ParagraphPagination,
Data.Text.ParagraphLayout.Internal.Plain,
Data.Text.ParagraphLayout.Internal.Rect,
Data.Text.ParagraphLayout.Internal.ResolvedSpan,
@@ 42,8 42,8 @@ where
import Data.Text.ParagraphLayout.Internal.Fragment
import Data.Text.ParagraphLayout.Internal.LineHeight
import Data.Text.ParagraphLayout.Internal.LinePagination
+import Data.Text.ParagraphLayout.Internal.Paginable
import Data.Text.ParagraphLayout.Internal.Paragraph
import Data.Text.ParagraphLayout.Internal.ParagraphLayout
-import Data.Text.ParagraphLayout.Internal.ParagraphPagination
import Data.Text.ParagraphLayout.Internal.Plain
import Data.Text.ParagraphLayout.Internal.Span
@@ 1,4 1,8 @@
module Data.Text.ParagraphLayout.Internal.ParagraphPagination
module Data.Text.ParagraphLayout.Internal.Paginable
(PageOptions(..)
,Paginable
,paginate
)
where
import Data.Int (Int32)
@@ 30,7 34,7 @@ data PageOptions = PageOptions
}
-- | Break a paragraph in order to fit the given pagination constraints.
-- | Typeclass for layouts that can be broken into pages.
--
-- The first component of the output determines whether a page break should
-- be inserted before the paragraph.
@@ 42,14 46,21 @@ data PageOptions = PageOptions
-- The third component of the output will be `Just` the remainder of the
-- paragraph that can be passed to this function again, or `Nothing` if there
-- is nothing left to put on further pages.
paginate :: PageOptions -> ParagraphLayout ->
(PageContinuity, ParagraphLayout, Maybe ParagraphLayout)
paginate opts pl = case paginateLines o w h1 h2 ls of
(c, ls1, []) -> (c, mergeLines ls1, Nothing)
(c, ls1, ls2) -> (c, mergeLines ls1, Just (mergeLines ls2))
where
o = pageOrphans opts
w = pageWidows opts
h1 = pageCurrentHeight opts
h2 = pageNextHeight opts
ls = cutLines pl
class Paginable pl where
paginate :: PageOptions -> pl -> (PageContinuity, pl, Maybe pl)
instance Line a => Paginable [a] where
paginate opts ls = case paginateLines o w h1 h2 ls of
(c, p, []) -> (c, p, Nothing)
(c, p, rest) -> (c, p, Just rest)
where
o = pageOrphans opts
w = pageWidows opts
h1 = pageCurrentHeight opts
h2 = pageNextHeight opts
-- | Break a paragraph in order to fit the given pagination constraints.
instance Paginable ParagraphLayout where
paginate opts pl = case paginate opts (cutLines pl) of
(c, p, Nothing) -> (c, mergeLines p, Nothing)
(c, p, Just rest) -> (c, mergeLines p, Just (mergeLines rest))