From ebfdbbdb57733dad57c02aba88fa6d14e706e7e7 Mon Sep 17 00:00:00 2001 From: Jaro Date: Wed, 3 May 2023 14:01:08 +0200 Subject: [PATCH] Deduplicate pagination code. --- src/Data/Text/ParagraphLayout/Internal/Paginable.hs | 11 +++++++---- .../Text/ParagraphLayout/Internal/ParagraphLine.hs | 3 ++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/Data/Text/ParagraphLayout/Internal/Paginable.hs b/src/Data/Text/ParagraphLayout/Internal/Paginable.hs index 35731bb..312782b 100644 --- a/src/Data/Text/ParagraphLayout/Internal/Paginable.hs +++ b/src/Data/Text/ParagraphLayout/Internal/Paginable.hs @@ -79,14 +79,17 @@ instance Line a => Paginable [a] where -- | Implementation of paginating a plain text paragraph layout. -- Breaks the layout on page boundaries and automatically adjusts coordinates. instance Paginable (Plain.ParagraphLayout d) 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)) + paginate = paginateLayout -- | Implementation of paginating a rich text paragraph layout. -- Breaks the layout on page boundaries and automatically adjusts coordinates. instance Paginable (Rich.ParagraphLayout d) where - paginate opts pl = case paginate opts (cutLines pl) of + paginate = paginateLayout + +paginateLayout :: (Line a, GenericLayout a) => + PageOptions -> a -> (PageContinuity, a, Maybe a) +paginateLayout 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)) diff --git a/src/Data/Text/ParagraphLayout/Internal/ParagraphLine.hs b/src/Data/Text/ParagraphLayout/Internal/ParagraphLine.hs index 656f988..e0a3f79 100644 --- a/src/Data/Text/ParagraphLayout/Internal/ParagraphLine.hs +++ b/src/Data/Text/ParagraphLayout/Internal/ParagraphLine.hs @@ -1,6 +1,7 @@ -- | Splitting paragraph layouts between lines. module Data.Text.ParagraphLayout.Internal.ParagraphLine - ( cutLines + ( GenericLayout + , cutLines , mergeLines ) where -- 2.30.2