From 278ffb65d2bef8d684bdd94fd3b1f546efd6a41d Mon Sep 17 00:00:00 2001 From: Jaro Date: Tue, 25 Apr 2023 02:54:52 +0200 Subject: [PATCH] Qualify Plain interface. --- CHANGELOG.md | 3 ++ balkon.cabal | 3 +- lib/Data/Text/ParagraphLayout.hs | 33 +++----------- lib/Data/Text/ParagraphLayout/Plain.hs | 43 +++++++++++++++++++ .../ParagraphLayout/Plain/ParagraphData.hs | 2 +- .../PlainSpec.hs} | 3 +- test/Data/Text/ParagraphLayout/PrettyShow.hs | 15 ++++--- 7 files changed, 65 insertions(+), 37 deletions(-) create mode 100644 lib/Data/Text/ParagraphLayout/Plain.hs rename test/Data/Text/{ParagraphLayoutSpec.hs => ParagraphLayout/PlainSpec.hs} (99%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8310213..7e764fb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## 1.0.0.0 -- TBD +* Separated plain text layout interface into `Data.Text.ParagraphLayout.Plain` + submodule, in anticipation of a rich text interface. + * Future-proofed `ParagraphOptions` and `SpanOptions` by hiding their constructors. Use `defaultParagraphOptions` and `defaultSpanOptions` instead. diff --git a/balkon.cabal b/balkon.cabal index 10e01e9..51920dc 100644 --- a/balkon.cabal +++ b/balkon.cabal @@ -142,6 +142,7 @@ library exposed-modules: Data.Text.ParagraphLayout, Data.Text.ParagraphLayout.ParagraphConstruction, + Data.Text.ParagraphLayout.Plain, Data.Text.ParagraphLayout.Rect -- Other library packages from which modules are imported. @@ -162,7 +163,6 @@ test-suite balkon-test main-is: Spec.hs other-modules: - Data.Text.ParagraphLayoutSpec, Data.Text.ParagraphLayout.FontLoader, Data.Text.ParagraphLayout.Internal.BiDiReorderSpec, Data.Text.ParagraphLayout.Internal.BreakSpec, @@ -171,6 +171,7 @@ test-suite balkon-test Data.Text.ParagraphLayout.Internal.TextContainerSpec, Data.Text.ParagraphLayout.Internal.ZipperSpec, Data.Text.ParagraphLayout.Plain.ParagraphData, + Data.Text.ParagraphLayout.PlainSpec, Data.Text.ParagraphLayout.PrettyShow, Data.Text.ParagraphLayout.PrettyShow.Golden, Data.Text.ParagraphLayout.RectSpec, diff --git a/lib/Data/Text/ParagraphLayout.hs b/lib/Data/Text/ParagraphLayout.hs index 22a69af..5aa08a5 100644 --- a/lib/Data/Text/ParagraphLayout.hs +++ b/lib/Data/Text/ParagraphLayout.hs @@ -1,4 +1,8 @@ --- | +-- | Generic functions for manipulating paragraph layout. +-- +-- In order to create such paragraph layout in the first place, see +-- "Data.Text.ParagraphLayout.Plain". Only a plain text interface is +-- currently available. -- -- Positions and distances are represented as 32-bit integers. Their unit must -- be defined by the caller, who must calculate the desired dimensions of the @@ -13,9 +17,7 @@ -- -- Y coordinates increase from bottom to top. module Data.Text.ParagraphLayout - ( Fragment (Fragment, fragmentPen, fragmentRect, fragmentGlyphs) - , LineHeight (Absolute, Normal) - , PageContinuity (Break, Continue) + ( PageContinuity (Break, Continue) , PageOptions ( PageOptions , pageCurrentHeight @@ -24,32 +26,9 @@ module Data.Text.ParagraphLayout , pageWidows ) , Paginable - , Paragraph (Paragraph) - , ParagraphLayout (ParagraphLayout, paragraphRect, spanLayouts) - , ParagraphOptions - ( paragraphFont - , paragraphLineHeight - , paragraphMaxWidth - ) - , Span (Span, spanLength, spanOptions) - , SpanLayout (SpanLayout) - , SpanOptions (spanLanguage) - , defaultParagraphOptions - , defaultSpanOptions - , layoutPlain , paginate - , paragraphSpanBounds - , paragraphSpanTexts - , paragraphText ) 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.ParagraphOptions -import Data.Text.ParagraphLayout.Internal.Plain -import Data.Text.ParagraphLayout.Internal.Plain.Paragraph -import Data.Text.ParagraphLayout.Internal.Plain.ParagraphLayout -import Data.Text.ParagraphLayout.Internal.Span diff --git a/lib/Data/Text/ParagraphLayout/Plain.hs b/lib/Data/Text/ParagraphLayout/Plain.hs new file mode 100644 index 0000000..1714843 --- /dev/null +++ b/lib/Data/Text/ParagraphLayout/Plain.hs @@ -0,0 +1,43 @@ +-- | Interface for laying out paragraphs of plain text. +-- +-- This interface only allows one font with a fixed line height to be used for +-- the entire paragraph. As a consequence, all lines will have the same height. +module Data.Text.ParagraphLayout.Plain + -- * Input paragraph + ( Paragraph (Paragraph) + , LineHeight (Absolute, Normal) + , ParagraphOptions + , defaultParagraphOptions + -- ** Paragraph options + -- | These are record selectors that can be used for reading + -- as well as updating specific option fields. + , paragraphFont + , paragraphLineHeight + , paragraphMaxWidth + -- ** Text spans + , Span (Span, spanLength, spanOptions) + , SpanOptions + , defaultSpanOptions + -- ** Span options + -- | These are record selectors that can be used for reading + -- as well as updating specific option fields. + , spanLanguage + -- ** Verification + , paragraphSpanBounds + , paragraphSpanTexts + , paragraphText + -- * Output layout + , layoutPlain + , ParagraphLayout (ParagraphLayout, paragraphRect, spanLayouts) + , SpanLayout (SpanLayout) + , Fragment (Fragment, fragmentPen, fragmentRect, fragmentGlyphs) + ) +where + +import Data.Text.ParagraphLayout.Internal.Fragment +import Data.Text.ParagraphLayout.Internal.LineHeight +import Data.Text.ParagraphLayout.Internal.ParagraphOptions +import Data.Text.ParagraphLayout.Internal.Plain +import Data.Text.ParagraphLayout.Internal.Plain.Paragraph +import Data.Text.ParagraphLayout.Internal.Plain.ParagraphLayout +import Data.Text.ParagraphLayout.Internal.Span diff --git a/test/Data/Text/ParagraphLayout/Plain/ParagraphData.hs b/test/Data/Text/ParagraphLayout/Plain/ParagraphData.hs index 838a8d8..7753fc7 100644 --- a/test/Data/Text/ParagraphLayout/Plain/ParagraphData.hs +++ b/test/Data/Text/ParagraphLayout/Plain/ParagraphData.hs @@ -20,7 +20,7 @@ module Data.Text.ParagraphLayout.Plain.ParagraphData ) where -import Data.Text.ParagraphLayout +import Data.Text.ParagraphLayout.Plain ( Paragraph , ParagraphOptions , SpanOptions (spanLanguage) diff --git a/test/Data/Text/ParagraphLayoutSpec.hs b/test/Data/Text/ParagraphLayout/PlainSpec.hs similarity index 99% rename from test/Data/Text/ParagraphLayoutSpec.hs rename to test/Data/Text/ParagraphLayout/PlainSpec.hs index 808d244..744201b 100644 --- a/test/Data/Text/ParagraphLayoutSpec.hs +++ b/test/Data/Text/ParagraphLayout/PlainSpec.hs @@ -1,10 +1,11 @@ -module Data.Text.ParagraphLayoutSpec (spec) where +module Data.Text.ParagraphLayout.PlainSpec (spec) where import Test.Hspec import System.FilePath (()) import Data.Text.ParagraphLayout import Data.Text.ParagraphLayout.FontLoader import Data.Text.ParagraphLayout.Internal.Plain.ParagraphLayout +import Data.Text.ParagraphLayout.Plain import Data.Text.ParagraphLayout.Plain.ParagraphData import Data.Text.ParagraphLayout.PrettyShow import Data.Text.ParagraphLayout.PrettyShow.Golden diff --git a/test/Data/Text/ParagraphLayout/PrettyShow.hs b/test/Data/Text/ParagraphLayout/PrettyShow.hs index cdff80e..5638eda 100644 --- a/test/Data/Text/ParagraphLayout/PrettyShow.hs +++ b/test/Data/Text/ParagraphLayout/PrettyShow.hs @@ -9,6 +9,7 @@ where import Data.List (intersperse) import Data.Text.ParagraphLayout import Data.Text.ParagraphLayout.Internal.Fragment (ShapedRun) +import qualified Data.Text.ParagraphLayout.Plain as Plain class PrettyShow a where prettyShow :: a -> String @@ -34,7 +35,7 @@ instance PrettyShow ShapedRun' where , ")" ] -type Page = (PageContinuity, ParagraphLayout) +type Page = (PageContinuity, Plain.ParagraphLayout) newtype Pages = Pages { getPages :: [Page] } deriving (Eq) @@ -55,8 +56,8 @@ instance PrettyShow Page' where , ")" ] -instance PrettyShow ParagraphLayout where - prettyShow (ParagraphLayout pr sls) = concat +instance PrettyShow Plain.ParagraphLayout where + prettyShow (Plain.ParagraphLayout pr sls) = concat [ "ParagraphLayout" , newline , indent1 @@ -73,15 +74,15 @@ instance PrettyShow ParagraphLayout where , newline ] -instance PrettyShow SpanLayout where - prettyShow (SpanLayout frags) = concat +instance PrettyShow Plain.SpanLayout where + prettyShow (Plain.SpanLayout frags) = concat [ "SpanLayout" , newline , concat $ commaFirstList indent2 $ map prettyShow frags ] -instance PrettyShow Fragment where - prettyShow (Fragment r pen glyphs) = concat +instance PrettyShow Plain.Fragment where + prettyShow (Plain.Fragment r pen glyphs) = concat [ "Fragment" , newline , indent3 -- 2.30.2