From 69e92e75ea01ea2631277c40c5b6fdc36e538337 Mon Sep 17 00:00:00 2001 From: Jaro Date: Wed, 26 Apr 2023 10:05:55 +0200 Subject: [PATCH] Separate interface-independent constants. --- balkon.cabal | 1 + .../Internal/ParagraphExtents.hs | 26 +++++++++++++++++++ .../Text/ParagraphLayout/Internal/Plain.hs | 1 + .../Internal/Plain/ParagraphLayout.hs | 22 ++-------------- 4 files changed, 30 insertions(+), 20 deletions(-) create mode 100644 src/Data/Text/ParagraphLayout/Internal/ParagraphExtents.hs diff --git a/balkon.cabal b/balkon.cabal index 51920dc..c8e172a 100644 --- a/balkon.cabal +++ b/balkon.cabal @@ -121,6 +121,7 @@ library balkon-internal -- Modules used purely internally and not in any tests. other-modules: + Data.Text.ParagraphLayout.Internal.ParagraphExtents, Data.Text.ParagraphLayout.Internal.ParagraphLine, Data.Text.ParagraphLayout.Internal.ProtoFragment, Data.Text.ParagraphLayout.Internal.Script diff --git a/src/Data/Text/ParagraphLayout/Internal/ParagraphExtents.hs b/src/Data/Text/ParagraphLayout/Internal/ParagraphExtents.hs new file mode 100644 index 0000000..bc6ca9a --- /dev/null +++ b/src/Data/Text/ParagraphLayout/Internal/ParagraphExtents.hs @@ -0,0 +1,26 @@ +module Data.Text.ParagraphLayout.Internal.ParagraphExtents + ( paragraphOriginX + , paragraphOriginY + , containRects + , emptyRect + ) +where + +import Data.Text.ParagraphLayout.Internal.Rect + +paragraphOriginX :: (Num a) => a +paragraphOriginX = 0 + +paragraphOriginY :: (Num a) => a +paragraphOriginY = 0 + +emptyRect :: (Num a) => Rect a +emptyRect = Rect + { x_origin = paragraphOriginX + , y_origin = paragraphOriginY + , x_size = 0 + , y_size = 0 + } + +containRects :: (Ord a, Num a) => [Rect a] -> Rect a +containRects = foldr union emptyRect diff --git a/src/Data/Text/ParagraphLayout/Internal/Plain.hs b/src/Data/Text/ParagraphLayout/Internal/Plain.hs index c98c653..ce4ff1f 100644 --- a/src/Data/Text/ParagraphLayout/Internal/Plain.hs +++ b/src/Data/Text/ParagraphLayout/Internal/Plain.hs @@ -28,6 +28,7 @@ import Data.Text.ParagraphLayout.Internal.BiDiReorder import Data.Text.ParagraphLayout.Internal.Break import Data.Text.ParagraphLayout.Internal.Fragment import Data.Text.ParagraphLayout.Internal.LineHeight +import Data.Text.ParagraphLayout.Internal.ParagraphExtents import Data.Text.ParagraphLayout.Internal.ParagraphOptions import Data.Text.ParagraphLayout.Internal.Plain.Paragraph import Data.Text.ParagraphLayout.Internal.Plain.ParagraphLayout diff --git a/src/Data/Text/ParagraphLayout/Internal/Plain/ParagraphLayout.hs b/src/Data/Text/ParagraphLayout/Internal/Plain/ParagraphLayout.hs index eb73c5b..70ee28b 100644 --- a/src/Data/Text/ParagraphLayout/Internal/Plain/ParagraphLayout.hs +++ b/src/Data/Text/ParagraphLayout/Internal/Plain/ParagraphLayout.hs @@ -6,8 +6,6 @@ module Data.Text.ParagraphLayout.Internal.Plain.ParagraphLayout , mapFragments , paragraphFragments , paragraphLayout - , paragraphOriginX - , paragraphOriginY , shapedRuns ) where @@ -15,6 +13,7 @@ where import Data.Int (Int32) import Data.Text.ParagraphLayout.Internal.Fragment +import Data.Text.ParagraphLayout.Internal.ParagraphExtents import Data.Text.ParagraphLayout.Internal.Rect import Data.Text.ParagraphLayout.Internal.Span @@ -26,23 +25,6 @@ data ParagraphLayout d = ParagraphLayout } deriving (Eq, Read, Show) -paragraphOriginX :: (Num a) => a -paragraphOriginX = 0 - -paragraphOriginY :: (Num a) => a -paragraphOriginY = 0 - -empty :: (Num a) => Rect a -empty = Rect - { x_origin = paragraphOriginX - , y_origin = paragraphOriginY - , x_size = 0 - , y_size = 0 - } - -containRects :: (Ord a, Num a) => [Rect a] -> Rect a -containRects = foldr union empty - -- | Wrap the given `SpanLayout`s and compute their containing rectangle. paragraphLayout :: [SpanLayout d] -> ParagraphLayout d paragraphLayout sls = ParagraphLayout pRect sls @@ -51,7 +33,7 @@ paragraphLayout sls = ParagraphLayout pRect sls -- | A `ParagraphLayout` with an infinite number of empty spans. -- Useful as an identity element for `appendFragments`. emptyParagraphLayout :: ParagraphLayout d -emptyParagraphLayout = ParagraphLayout empty $ repeat (SpanLayout []) +emptyParagraphLayout = ParagraphLayout emptyRect $ repeat (SpanLayout []) -- | Remove fragments that do not match the given predicate. -- -- 2.30.2