From 1555a8cc7b5b6ad8c7f365564876dc6f5649f19c Mon Sep 17 00:00:00 2001 From: Jaro Date: Tue, 7 Mar 2023 09:47:09 +0100 Subject: [PATCH] Move non-public modules into Internal namespace. --- balkon.cabal | 35 +++-- src/Data/Text/ParagraphLayout.hs | 21 ++- .../ParagraphLayout/{ => Internal}/Break.hs | 2 +- .../{ => Internal}/Fragment.hs | 2 +- .../{ => Internal}/LineHeight.hs | 2 +- .../ParagraphLayout/{ => Internal}/Plain.hs | 23 ++- .../{ => Internal}/ProtoFragment.hs | 2 +- .../{ => Internal}/ResolvedSpan.hs | 6 +- .../ParagraphLayout/{ => Internal}/Run.hs | 10 +- .../{ => ParagraphLayout/Internal}/Script.hs | 2 +- .../ParagraphLayout/{ => Internal}/Span.hs | 2 +- .../{ => Internal}/TextContainer.hs | 2 +- .../{ => ParagraphLayout/Internal}/Zipper.hs | 4 +- src/Data/Text/ParagraphLayout/Rect.hs | 2 +- .../{ => Internal}/BreakSpec.hs | 4 +- .../ParagraphLayout/{ => Internal}/RunSpec.hs | 6 +- .../{ => Internal}/TextContainerSpec.hs | 6 +- .../Internal}/ZipperSpec.hs | 4 +- .../ParagraphLayout/ParagraphConstruction.hs | 2 +- .../Text/ParagraphLayout/ParagraphData.hs | 2 +- test/Data/Text/ParagraphLayout/PlainSpec.hs | 142 ------------------ test/Data/Text/ParagraphLayout/SpanData.hs | 4 +- test/Data/Text/ParagraphLayoutSpec.hs | 138 ++++++++++++++++- 23 files changed, 215 insertions(+), 208 deletions(-) rename src/Data/Text/ParagraphLayout/{ => Internal}/Break.hs (95%) rename src/Data/Text/ParagraphLayout/{ => Internal}/Fragment.hs (96%) rename src/Data/Text/ParagraphLayout/{ => Internal}/LineHeight.hs (79%) rename src/Data/Text/ParagraphLayout/{ => Internal}/Plain.hs (96%) rename src/Data/Text/ParagraphLayout/{ => Internal}/ProtoFragment.hs (87%) rename src/Data/Text/ParagraphLayout/{ => Internal}/ResolvedSpan.hs (77%) rename src/Data/Text/ParagraphLayout/{ => Internal}/Run.hs (93%) rename src/Data/Text/{ => ParagraphLayout/Internal}/Script.hs (98%) rename src/Data/Text/ParagraphLayout/{ => Internal}/Span.hs (88%) rename src/Data/Text/ParagraphLayout/{ => Internal}/TextContainer.hs (96%) rename src/Data/Text/{ => ParagraphLayout/Internal}/Zipper.hs (96%) rename test/Data/Text/ParagraphLayout/{ => Internal}/BreakSpec.hs (97%) rename test/Data/Text/ParagraphLayout/{ => Internal}/RunSpec.hs (90%) rename test/Data/Text/ParagraphLayout/{ => Internal}/TextContainerSpec.hs (94%) rename test/Data/Text/{ => ParagraphLayout/Internal}/ZipperSpec.hs (97%) delete mode 100644 test/Data/Text/ParagraphLayout/PlainSpec.hs diff --git a/balkon.cabal b/balkon.cabal index efab021..2f7afa4 100644 --- a/balkon.cabal +++ b/balkon.cabal @@ -99,20 +99,20 @@ library -- Modules exported by the library. exposed-modules: Data.Text.ParagraphLayout, - Data.Text.ParagraphLayout.Break, - Data.Text.ParagraphLayout.Fragment, - Data.Text.ParagraphLayout.LineHeight, - Data.Text.ParagraphLayout.Plain, - Data.Text.ParagraphLayout.ProtoFragment - Data.Text.ParagraphLayout.Rect, - Data.Text.ParagraphLayout.ResolvedSpan, - Data.Text.ParagraphLayout.Run, - Data.Text.ParagraphLayout.Span, - Data.Text.ParagraphLayout.TextContainer, - Data.Text.Zipper + Data.Text.ParagraphLayout.Internal.Break, + Data.Text.ParagraphLayout.Internal.Fragment, + Data.Text.ParagraphLayout.Internal.LineHeight, + Data.Text.ParagraphLayout.Internal.Plain, + Data.Text.ParagraphLayout.Internal.ProtoFragment + Data.Text.ParagraphLayout.Internal.ResolvedSpan, + Data.Text.ParagraphLayout.Internal.Run, + Data.Text.ParagraphLayout.Internal.Span, + Data.Text.ParagraphLayout.Internal.TextContainer, + Data.Text.ParagraphLayout.Internal.Zipper, + Data.Text.ParagraphLayout.Rect -- Modules included in this library but not exported. - other-modules: Data.Text.Script + other-modules: Data.Text.ParagraphLayout.Internal.Script -- Other library packages from which modules are imported. build-depends: @@ -136,16 +136,15 @@ test-suite balkon-test other-modules: Data.Text.ParagraphLayoutSpec, - Data.Text.ParagraphLayout.BreakSpec, Data.Text.ParagraphLayout.FontLoader, + Data.Text.ParagraphLayout.Internal.BreakSpec, + Data.Text.ParagraphLayout.Internal.RunSpec, + Data.Text.ParagraphLayout.Internal.TextContainerSpec, + Data.Text.ParagraphLayout.Internal.ZipperSpec, Data.Text.ParagraphLayout.ParagraphConstruction, Data.Text.ParagraphLayout.ParagraphData, - Data.Text.ParagraphLayout.PlainSpec, Data.Text.ParagraphLayout.RectSpec, - Data.Text.ParagraphLayout.RunSpec, - Data.Text.ParagraphLayout.SpanData, - Data.Text.ParagraphLayout.TextContainerSpec, - Data.Text.ZipperSpec + Data.Text.ParagraphLayout.SpanData -- Test dependencies. build-depends: diff --git a/src/Data/Text/ParagraphLayout.hs b/src/Data/Text/ParagraphLayout.hs index a8bbae1..5717f29 100644 --- a/src/Data/Text/ParagraphLayout.hs +++ b/src/Data/Text/ParagraphLayout.hs @@ -1,2 +1,21 @@ -module Data.Text.ParagraphLayout () +module Data.Text.ParagraphLayout + (Fragment(Fragment, fragmentPen, fragmentRect, fragmentGlyphs) + ,LineHeight(Absolute, Normal) + ,Paragraph(Paragraph) + ,ParagraphLayout(ParagraphLayout, paragraphRect, spanLayouts) + ,ParagraphOptions + (ParagraphOptions + ,paragraphFont + ,paragraphLineHeight + ,paragraphMaxWidth + ) + ,Span(Span, spanLanguage, spanLength) + ,SpanLayout(SpanLayout) + ,layoutPlain + ) where + +import Data.Text.ParagraphLayout.Internal.Fragment +import Data.Text.ParagraphLayout.Internal.LineHeight +import Data.Text.ParagraphLayout.Internal.Plain +import Data.Text.ParagraphLayout.Internal.Span diff --git a/src/Data/Text/ParagraphLayout/Break.hs b/src/Data/Text/ParagraphLayout/Internal/Break.hs similarity index 95% rename from src/Data/Text/ParagraphLayout/Break.hs rename to src/Data/Text/ParagraphLayout/Internal/Break.hs index 01fee72..dbdeec3 100644 --- a/src/Data/Text/ParagraphLayout/Break.hs +++ b/src/Data/Text/ParagraphLayout/Internal/Break.hs @@ -5,7 +5,7 @@ -- (also called UTF-8 code units or bytes) between the start of the input `Text` -- and the position of the break. The internal offset of the `Text` from the -- start of its underlying byte array is excluded. -module Data.Text.ParagraphLayout.Break (breaksDesc, subOffsetsDesc) +module Data.Text.ParagraphLayout.Internal.Break (breaksDesc, subOffsetsDesc) where import Data.Text (Text) diff --git a/src/Data/Text/ParagraphLayout/Fragment.hs b/src/Data/Text/ParagraphLayout/Internal/Fragment.hs similarity index 96% rename from src/Data/Text/ParagraphLayout/Fragment.hs rename to src/Data/Text/ParagraphLayout/Internal/Fragment.hs index d774697..ba6aec5 100644 --- a/src/Data/Text/ParagraphLayout/Fragment.hs +++ b/src/Data/Text/ParagraphLayout/Internal/Fragment.hs @@ -1,4 +1,4 @@ -module Data.Text.ParagraphLayout.Fragment (Fragment(..)) +module Data.Text.ParagraphLayout.Internal.Fragment (Fragment(..)) where import Data.Int (Int32) diff --git a/src/Data/Text/ParagraphLayout/LineHeight.hs b/src/Data/Text/ParagraphLayout/Internal/LineHeight.hs similarity index 79% rename from src/Data/Text/ParagraphLayout/LineHeight.hs rename to src/Data/Text/ParagraphLayout/Internal/LineHeight.hs index f5a1544..ddcfdfe 100644 --- a/src/Data/Text/ParagraphLayout/LineHeight.hs +++ b/src/Data/Text/ParagraphLayout/Internal/LineHeight.hs @@ -1,4 +1,4 @@ -module Data.Text.ParagraphLayout.LineHeight (LineHeight(..)) +module Data.Text.ParagraphLayout.Internal.LineHeight (LineHeight(..)) where import Data.Int (Int32) diff --git a/src/Data/Text/ParagraphLayout/Plain.hs b/src/Data/Text/ParagraphLayout/Internal/Plain.hs similarity index 96% rename from src/Data/Text/ParagraphLayout/Plain.hs rename to src/Data/Text/ParagraphLayout/Internal/Plain.hs index 59cda80..ebe2f8b 100644 --- a/src/Data/Text/ParagraphLayout/Plain.hs +++ b/src/Data/Text/ParagraphLayout/Internal/Plain.hs @@ -8,13 +8,10 @@ -- example, if @1em = 20px@, if the output pixels are square, and if the output -- coordinates are in 1/64ths of a pixel, you should set both the @x_scale@ and -- the @y_scale@ to @1280@. -module Data.Text.ParagraphLayout.Plain - (LineHeight(..) - ,Paragraph(..) +module Data.Text.ParagraphLayout.Internal.Plain + (Paragraph(..) ,ParagraphLayout(..) ,ParagraphOptions(..) - ,Rect(..) - ,Span(..) ,SpanLayout(..) ,layoutPlain ) @@ -43,15 +40,15 @@ import qualified Data.Text.ICU as BreakStatus (Line) import Data.Text.Internal (Text(Text)) import qualified Data.Text.Lazy as Lazy -import Data.Text.ParagraphLayout.Break -import Data.Text.ParagraphLayout.Fragment -import Data.Text.ParagraphLayout.LineHeight -import qualified Data.Text.ParagraphLayout.ProtoFragment as PF +import Data.Text.ParagraphLayout.Internal.Break +import Data.Text.ParagraphLayout.Internal.Fragment +import Data.Text.ParagraphLayout.Internal.LineHeight +import qualified Data.Text.ParagraphLayout.Internal.ProtoFragment as PF +import qualified Data.Text.ParagraphLayout.Internal.ResolvedSpan as RS +import Data.Text.ParagraphLayout.Internal.Run +import Data.Text.ParagraphLayout.Internal.Span +import Data.Text.ParagraphLayout.Internal.TextContainer import Data.Text.ParagraphLayout.Rect -import qualified Data.Text.ParagraphLayout.ResolvedSpan as RS -import Data.Text.ParagraphLayout.Run -import Data.Text.ParagraphLayout.Span -import Data.Text.ParagraphLayout.TextContainer -- | Text to be laid out as a paragraph. -- diff --git a/src/Data/Text/ParagraphLayout/ProtoFragment.hs b/src/Data/Text/ParagraphLayout/Internal/ProtoFragment.hs similarity index 87% rename from src/Data/Text/ParagraphLayout/ProtoFragment.hs rename to src/Data/Text/ParagraphLayout/Internal/ProtoFragment.hs index 59658d6..c21bd00 100644 --- a/src/Data/Text/ParagraphLayout/ProtoFragment.hs +++ b/src/Data/Text/ParagraphLayout/Internal/ProtoFragment.hs @@ -1,4 +1,4 @@ -module Data.Text.ParagraphLayout.ProtoFragment (ProtoFragment(..)) +module Data.Text.ParagraphLayout.Internal.ProtoFragment (ProtoFragment(..)) where import Data.Int (Int32) diff --git a/src/Data/Text/ParagraphLayout/ResolvedSpan.hs b/src/Data/Text/ParagraphLayout/Internal/ResolvedSpan.hs similarity index 77% rename from src/Data/Text/ParagraphLayout/ResolvedSpan.hs rename to src/Data/Text/ParagraphLayout/Internal/ResolvedSpan.hs index 3434768..b819849 100644 --- a/src/Data/Text/ParagraphLayout/ResolvedSpan.hs +++ b/src/Data/Text/ParagraphLayout/Internal/ResolvedSpan.hs @@ -1,12 +1,12 @@ -module Data.Text.ParagraphLayout.ResolvedSpan (ResolvedSpan(..)) +module Data.Text.ParagraphLayout.Internal.ResolvedSpan (ResolvedSpan(..)) where import Data.Text (Text) import Data.Text.Glyphize (Font) import qualified Data.Text.ICU as BreakStatus (Line) -import Data.Text.ParagraphLayout.LineHeight -import Data.Text.ParagraphLayout.TextContainer +import Data.Text.ParagraphLayout.Internal.LineHeight +import Data.Text.ParagraphLayout.Internal.TextContainer -- | Internal structure containing resolved values that may be shared with -- other spans across the paragraph. diff --git a/src/Data/Text/ParagraphLayout/Run.hs b/src/Data/Text/ParagraphLayout/Internal/Run.hs similarity index 93% rename from src/Data/Text/ParagraphLayout/Run.hs rename to src/Data/Text/ParagraphLayout/Internal/Run.hs index 7855b96..63ecad8 100644 --- a/src/Data/Text/ParagraphLayout/Run.hs +++ b/src/Data/Text/ParagraphLayout/Internal/Run.hs @@ -1,4 +1,4 @@ -module Data.Text.ParagraphLayout.Run (Run(..), spanToRuns) +module Data.Text.ParagraphLayout.Internal.Run (Run(..), spanToRuns) where import Data.List (mapAccumL) @@ -7,11 +7,11 @@ import Data.Text (Text) import Data.Text.Foreign (dropWord8, lengthWord8, takeWord8) import Data.Text.Glyphize (Direction(..)) import qualified Data.Text.ICU.Char as ICUChar -import Data.Text.Script (charScript) -import Data.Text.Zipper -import Data.Text.ParagraphLayout.ResolvedSpan -import Data.Text.ParagraphLayout.TextContainer +import Data.Text.ParagraphLayout.Internal.ResolvedSpan +import Data.Text.ParagraphLayout.Internal.Script (charScript) +import Data.Text.ParagraphLayout.Internal.TextContainer +import Data.Text.ParagraphLayout.Internal.Zipper type ScriptCode = String diff --git a/src/Data/Text/Script.hs b/src/Data/Text/ParagraphLayout/Internal/Script.hs similarity index 98% rename from src/Data/Text/Script.hs rename to src/Data/Text/ParagraphLayout/Internal/Script.hs index 2157681..48a1210 100644 --- a/src/Data/Text/Script.hs +++ b/src/Data/Text/ParagraphLayout/Internal/Script.hs @@ -1,4 +1,4 @@ -module Data.Text.Script (charScript) +module Data.Text.ParagraphLayout.Internal.Script (charScript) where -- TODO: Use a direct interface to the ICU library, if possible. diff --git a/src/Data/Text/ParagraphLayout/Span.hs b/src/Data/Text/ParagraphLayout/Internal/Span.hs similarity index 88% rename from src/Data/Text/ParagraphLayout/Span.hs rename to src/Data/Text/ParagraphLayout/Internal/Span.hs index 2d37347..e8874dd 100644 --- a/src/Data/Text/ParagraphLayout/Span.hs +++ b/src/Data/Text/ParagraphLayout/Internal/Span.hs @@ -1,4 +1,4 @@ -module Data.Text.ParagraphLayout.Span (Span(..)) +module Data.Text.ParagraphLayout.Internal.Span (Span(..)) where -- Paragraph is broken into spans by the caller. diff --git a/src/Data/Text/ParagraphLayout/TextContainer.hs b/src/Data/Text/ParagraphLayout/Internal/TextContainer.hs similarity index 96% rename from src/Data/Text/ParagraphLayout/TextContainer.hs rename to src/Data/Text/ParagraphLayout/Internal/TextContainer.hs index 4277285..3014439 100644 --- a/src/Data/Text/ParagraphLayout/TextContainer.hs +++ b/src/Data/Text/ParagraphLayout/Internal/TextContainer.hs @@ -1,4 +1,4 @@ -module Data.Text.ParagraphLayout.TextContainer +module Data.Text.ParagraphLayout.Internal.TextContainer (SeparableTextContainer ,TextContainer ,getText diff --git a/src/Data/Text/Zipper.hs b/src/Data/Text/ParagraphLayout/Internal/Zipper.hs similarity index 96% rename from src/Data/Text/Zipper.hs rename to src/Data/Text/ParagraphLayout/Internal/Zipper.hs index 726efa0..f4bfb66 100644 --- a/src/Data/Text/Zipper.hs +++ b/src/Data/Text/ParagraphLayout/Internal/Zipper.hs @@ -2,9 +2,7 @@ -- -- All measurements are in UTF-8 code points, each of which can be between -- 1 and 4 bytes long (inclusive). -module Data.Text.Zipper - -- TODO: Consider renaming the module to avoid conflict with text-zipper - -- from Hackage. +module Data.Text.ParagraphLayout.Internal.Zipper (Zipper(preceding, following) ,advanceBy ,atEnd diff --git a/src/Data/Text/ParagraphLayout/Rect.hs b/src/Data/Text/ParagraphLayout/Rect.hs index b2bdfa3..5b79f40 100644 --- a/src/Data/Text/ParagraphLayout/Rect.hs +++ b/src/Data/Text/ParagraphLayout/Rect.hs @@ -1,7 +1,7 @@ -- | Representation of an axis-aligned rectangle on a 2D plane, with one of its -- corners being a designated origin point. module Data.Text.ParagraphLayout.Rect - (Rect(..) + (Rect(Rect, x_origin, y_origin, x_size, y_size) ,height ,union ,width diff --git a/test/Data/Text/ParagraphLayout/BreakSpec.hs b/test/Data/Text/ParagraphLayout/Internal/BreakSpec.hs similarity index 97% rename from test/Data/Text/ParagraphLayout/BreakSpec.hs rename to test/Data/Text/ParagraphLayout/Internal/BreakSpec.hs index 91fe7d7..d37289b 100644 --- a/test/Data/Text/ParagraphLayout/BreakSpec.hs +++ b/test/Data/Text/ParagraphLayout/Internal/BreakSpec.hs @@ -1,4 +1,4 @@ -module Data.Text.ParagraphLayout.BreakSpec (spec) where +module Data.Text.ParagraphLayout.Internal.BreakSpec (spec) where import Data.Text (empty, pack, singleton) import Data.Text.ICU @@ -11,7 +11,7 @@ import Data.Text.ICU import qualified Data.Text.ICU as BreakStatus (Line(..), Word(..)) import Test.Hspec -import Data.Text.ParagraphLayout.Break +import Data.Text.ParagraphLayout.Internal.Break spec :: Spec spec = do diff --git a/test/Data/Text/ParagraphLayout/RunSpec.hs b/test/Data/Text/ParagraphLayout/Internal/RunSpec.hs similarity index 90% rename from test/Data/Text/ParagraphLayout/RunSpec.hs rename to test/Data/Text/ParagraphLayout/Internal/RunSpec.hs index a8752a3..58f5072 100644 --- a/test/Data/Text/ParagraphLayout/RunSpec.hs +++ b/test/Data/Text/ParagraphLayout/Internal/RunSpec.hs @@ -1,12 +1,12 @@ -module Data.Text.ParagraphLayout.RunSpec (spec) where +module Data.Text.ParagraphLayout.Internal.RunSpec (spec) where import Data.Text (pack) import Data.Text.Glyphize (Direction(..)) import Test.Hspec import Data.Text.ParagraphLayout.FontLoader -import Data.Text.ParagraphLayout.ResolvedSpan -import Data.Text.ParagraphLayout.Run +import Data.Text.ParagraphLayout.Internal.ResolvedSpan +import Data.Text.ParagraphLayout.Internal.Run import Data.Text.ParagraphLayout.SpanData spec :: Spec diff --git a/test/Data/Text/ParagraphLayout/TextContainerSpec.hs b/test/Data/Text/ParagraphLayout/Internal/TextContainerSpec.hs similarity index 94% rename from test/Data/Text/ParagraphLayout/TextContainerSpec.hs rename to test/Data/Text/ParagraphLayout/Internal/TextContainerSpec.hs index 17a866b..6ba933f 100644 --- a/test/Data/Text/ParagraphLayout/TextContainerSpec.hs +++ b/test/Data/Text/ParagraphLayout/Internal/TextContainerSpec.hs @@ -1,11 +1,11 @@ -module Data.Text.ParagraphLayout.TextContainerSpec (spec) where +module Data.Text.ParagraphLayout.Internal.TextContainerSpec (spec) where import Data.Text (pack) import Data.Text.Glyphize (Direction(..)) import Test.Hspec -import Data.Text.ParagraphLayout.Run -import Data.Text.ParagraphLayout.TextContainer +import Data.Text.ParagraphLayout.Internal.Run +import Data.Text.ParagraphLayout.Internal.TextContainer inputRuns :: [Run] inputRuns = diff --git a/test/Data/Text/ZipperSpec.hs b/test/Data/Text/ParagraphLayout/Internal/ZipperSpec.hs similarity index 97% rename from test/Data/Text/ZipperSpec.hs rename to test/Data/Text/ParagraphLayout/Internal/ZipperSpec.hs index 6161f47..197b215 100644 --- a/test/Data/Text/ZipperSpec.hs +++ b/test/Data/Text/ParagraphLayout/Internal/ZipperSpec.hs @@ -1,11 +1,11 @@ -module Data.Text.ZipperSpec (spec) where +module Data.Text.ParagraphLayout.Internal.ZipperSpec (spec) where import Control.Monad (forM_) import Data.Text (Text, empty, pack) import qualified Data.Text as Text import Test.Hspec -import qualified Data.Text.Zipper as Zipper +import qualified Data.Text.ParagraphLayout.Internal.Zipper as Zipper sampleText :: Text sampleText = diff --git a/test/Data/Text/ParagraphLayout/ParagraphConstruction.hs b/test/Data/Text/ParagraphLayout/ParagraphConstruction.hs index 5bcd291..6530265 100644 --- a/test/Data/Text/ParagraphLayout/ParagraphConstruction.hs +++ b/test/Data/Text/ParagraphLayout/ParagraphConstruction.hs @@ -20,7 +20,7 @@ import Data.Text.Internal (Text(Text)) import Data.Text.Internal.Lazy (chunk, empty) import qualified Data.Text.Internal.Lazy as Lazy import Data.Text.Lazy (toStrict) -import Data.Text.ParagraphLayout.Plain +import Data.Text.ParagraphLayout (Paragraph(Paragraph) ,ParagraphOptions ,Span(Span) diff --git a/test/Data/Text/ParagraphLayout/ParagraphData.hs b/test/Data/Text/ParagraphLayout/ParagraphData.hs index 3466fd7..07f6d20 100644 --- a/test/Data/Text/ParagraphLayout/ParagraphData.hs +++ b/test/Data/Text/ParagraphLayout/ParagraphData.hs @@ -11,8 +11,8 @@ module Data.Text.ParagraphLayout.ParagraphData ) where +import Data.Text.ParagraphLayout (Paragraph, ParagraphOptions) import Data.Text.ParagraphLayout.ParagraphConstruction -import Data.Text.ParagraphLayout.Plain (Paragraph, ParagraphOptions) emptyParagraph :: ParagraphOptions -> Paragraph emptyParagraph = "x" |<>| "zzzzzzz" diff --git a/test/Data/Text/ParagraphLayout/PlainSpec.hs b/test/Data/Text/ParagraphLayout/PlainSpec.hs deleted file mode 100644 index ce29cd5..0000000 --- a/test/Data/Text/ParagraphLayout/PlainSpec.hs +++ /dev/null @@ -1,142 +0,0 @@ -module Data.Text.ParagraphLayout.PlainSpec (spec) where - -import Data.List (intersperse) -import Data.Text.Glyphize (Font) - -import Test.Hspec -import Test.Hspec.Golden -import System.FilePath (()) -import Data.Text.ParagraphLayout.FontLoader -import Data.Text.ParagraphLayout.Fragment -import Data.Text.ParagraphLayout.LineHeight -import Data.Text.ParagraphLayout.ParagraphData -import Data.Text.ParagraphLayout.Plain - -prettyShow :: ParagraphLayout -> String -prettyShow (ParagraphLayout pr sls) = showParagraphLayout where - showParagraphLayout = concat - [ "ParagraphLayout {paragraphRect = " - , show pr - , ", spanLayouts = [" - , newline - , showSpanLayouts - , newline - , "]}" - , newline - ] - showSpanLayouts = concat $ intersperse commaNewline $ map showSpanLayout sls - showSpanLayout (SpanLayout frags) = concat - [ indent1 - , "SpanLayout [" - , concat $ intersperse ", " $ map showFrag frags - , "]" - ] - showFrag (Fragment r pen glyphs) = concat - [ "Fragment {fragmentRect = " - , show r - , ", " - , "fragmentPen = " - , show pen - , ", " - , "fragmentGlyphs =" - , newline - , indent2 - , "[" - , showGlyphs glyphs - , "]" - , newline - , indent1 - , "}" - ] - showGlyphs = concat . intersperse (commaNewline ++ indent2) . map show - indent1 = " " - indent2 = indent1 ++ indent1 - newline = "\n" - commaNewline = "," ++ newline - -shouldBeGolden :: ParagraphLayout -> FilePath -> Golden ParagraphLayout -shouldBeGolden output_ name = Golden - { output = output_ - , encodePretty = show - , writeToFile = \path -> writeFile path . prettyShow - , readFromFile = \path -> readFile path >>= return . read - , goldenFile = ".golden" name "golden" - , actualFile = Just (".golden" name "actual") - , failFirstTime = False - } - -emptyLayout :: ParagraphLayout -emptyLayout = ParagraphLayout (Rect 0 0 0 0) [] - -emptySpanLayout :: ParagraphLayout -emptySpanLayout = ParagraphLayout (Rect 0 0 0 0) [SpanLayout []] - -opts :: Font -> ParagraphOptions -opts font = ParagraphOptions font Normal 8000 - -spec :: Spec -spec = do - -- Note: This font does not contain Japanese glyphs. - describe "layoutPlain" $ do - describe "with Arabic font" $ before loadPlexSansArabicRegular $ do - it "wraps filler text at 20em" $ \font -> do - let - result = layoutPlain $ arabicFillerParagraph $ - (opts font) - { paragraphMaxWidth = 20000 } - result `shouldBeGolden` "arabicFiller20em" - describe "with Latin font" $ before loadUbuntuRegular $ do - it "handles input with no spans" $ \font -> do - let result = layoutPlain $ emptyParagraph $ opts font - result `shouldBe` emptyLayout - it "handles one span with no text" $ \font -> do - let result = layoutPlain $ emptySpanParagraph $ opts font - result `shouldBe` emptySpanLayout - it "handles Czech hello" $ \font -> do - let result = layoutPlain $ czechHelloParagraph $ opts font - result `shouldBeGolden` "czechHelloParagraph" - it "handles mixed languages in LTR layout" $ \font -> do - let result = layoutPlain $ mixedLanguageLTRParagraph $ opts font - result `shouldBeGolden` "mixedLanguageLTRParagraph" - it "handles normal line height" $ \font -> do - let - result = layoutPlain $ trivialParagraph $ - (opts font) - { paragraphLineHeight = Normal } - result `shouldBeGolden` "lineHeightNormal" - it "handles larger line height" $ \font -> do - let - result = layoutPlain $ trivialParagraph $ - (opts font) - { paragraphLineHeight = Absolute 1600 } - result `shouldBeGolden` "lineHeightLarger" - it "handles smaller line height" $ \font -> do - let - result = layoutPlain $ trivialParagraph $ - (opts font) - { paragraphLineHeight = Absolute 599 } - result `shouldBeGolden` "lineHeightSmaller" - it "wraps by characters when line is ultra narrow" $ \font -> do - let - result = layoutPlain $ czechHelloParagraph $ - (opts font) - { paragraphMaxWidth = 100 } - result `shouldBeGolden` "czechHelloParagraphUltraNarrow" - it "wraps lorem ipsum at 20em" $ \font -> do - let - result = layoutPlain $ loremIpsumParagraph $ - (opts font) - { paragraphMaxWidth = 20000 } - result `shouldBeGolden` "loremIpsum20em" - it "wraps lorem ipsum at 100em" $ \font -> do - let - result = layoutPlain $ loremIpsumParagraph $ - (opts font) - { paragraphMaxWidth = 100000 } - result `shouldBeGolden` "loremIpsum100em" - it "wraps mixed-script words correctly" $ \font -> do - let - result = layoutPlain $ mixedScriptWordsParagraph $ - (opts font) - { paragraphMaxWidth = 6000 } - result `shouldBeGolden` "mixedScriptWordsParagraph" diff --git a/test/Data/Text/ParagraphLayout/SpanData.hs b/test/Data/Text/ParagraphLayout/SpanData.hs index 47fb163..ac7d0be 100644 --- a/test/Data/Text/ParagraphLayout/SpanData.hs +++ b/test/Data/Text/ParagraphLayout/SpanData.hs @@ -7,8 +7,8 @@ where import Data.Text (pack) import Data.Text.Glyphize (Font) -import Data.Text.ParagraphLayout.LineHeight (LineHeight(Normal)) -import Data.Text.ParagraphLayout.ResolvedSpan (ResolvedSpan(..)) +import Data.Text.ParagraphLayout (LineHeight(Normal)) +import Data.Text.ParagraphLayout.Internal.ResolvedSpan (ResolvedSpan(..)) emptySpan :: Font -> ResolvedSpan emptySpan font = ResolvedSpan diff --git a/test/Data/Text/ParagraphLayoutSpec.hs b/test/Data/Text/ParagraphLayoutSpec.hs index ab6149c..9ef24b1 100644 --- a/test/Data/Text/ParagraphLayoutSpec.hs +++ b/test/Data/Text/ParagraphLayoutSpec.hs @@ -1,6 +1,142 @@ module Data.Text.ParagraphLayoutSpec (spec) where +import Data.List (intersperse) +import Data.Text.Glyphize (Font) + import Test.Hspec +import Test.Hspec.Golden +import System.FilePath (()) +import Data.Text.ParagraphLayout +import Data.Text.ParagraphLayout.FontLoader +import Data.Text.ParagraphLayout.ParagraphData +import Data.Text.ParagraphLayout.Rect + + +prettyShow :: ParagraphLayout -> String +prettyShow (ParagraphLayout pr sls) = showParagraphLayout where + showParagraphLayout = concat + [ "ParagraphLayout {paragraphRect = " + , show pr + , ", spanLayouts = [" + , newline + , showSpanLayouts + , newline + , "]}" + , newline + ] + showSpanLayouts = concat $ intersperse commaNewline $ map showSpanLayout sls + showSpanLayout (SpanLayout frags) = concat + [ indent1 + , "SpanLayout [" + , concat $ intersperse ", " $ map showFrag frags + , "]" + ] + showFrag (Fragment r pen glyphs) = concat + [ "Fragment {fragmentRect = " + , show r + , ", " + , "fragmentPen = " + , show pen + , ", " + , "fragmentGlyphs =" + , newline + , indent2 + , "[" + , showGlyphs glyphs + , "]" + , newline + , indent1 + , "}" + ] + showGlyphs = concat . intersperse (commaNewline ++ indent2) . map show + indent1 = " " + indent2 = indent1 ++ indent1 + newline = "\n" + commaNewline = "," ++ newline + +shouldBeGolden :: ParagraphLayout -> FilePath -> Golden ParagraphLayout +shouldBeGolden output_ name = Golden + { output = output_ + , encodePretty = show + , writeToFile = \path -> writeFile path . prettyShow + , readFromFile = \path -> readFile path >>= return . read + , goldenFile = ".golden" name "golden" + , actualFile = Just (".golden" name "actual") + , failFirstTime = False + } + +emptyLayout :: ParagraphLayout +emptyLayout = ParagraphLayout (Rect 0 0 0 0) [] + +emptySpanLayout :: ParagraphLayout +emptySpanLayout = ParagraphLayout (Rect 0 0 0 0) [SpanLayout []] + +opts :: Font -> ParagraphOptions +opts font = ParagraphOptions font Normal 8000 spec :: Spec -spec = return () +spec = do + -- Note: This font does not contain Japanese glyphs. + describe "layoutPlain" $ do + describe "with Arabic font" $ before loadPlexSansArabicRegular $ do + it "wraps filler text at 20em" $ \font -> do + let + result = layoutPlain $ arabicFillerParagraph $ + (opts font) + { paragraphMaxWidth = 20000 } + result `shouldBeGolden` "arabicFiller20em" + describe "with Latin font" $ before loadUbuntuRegular $ do + it "handles input with no spans" $ \font -> do + let result = layoutPlain $ emptyParagraph $ opts font + result `shouldBe` emptyLayout + it "handles one span with no text" $ \font -> do + let result = layoutPlain $ emptySpanParagraph $ opts font + result `shouldBe` emptySpanLayout + it "handles Czech hello" $ \font -> do + let result = layoutPlain $ czechHelloParagraph $ opts font + result `shouldBeGolden` "czechHelloParagraph" + it "handles mixed languages in LTR layout" $ \font -> do + let result = layoutPlain $ mixedLanguageLTRParagraph $ opts font + result `shouldBeGolden` "mixedLanguageLTRParagraph" + it "handles normal line height" $ \font -> do + let + result = layoutPlain $ trivialParagraph $ + (opts font) + { paragraphLineHeight = Normal } + result `shouldBeGolden` "lineHeightNormal" + it "handles larger line height" $ \font -> do + let + result = layoutPlain $ trivialParagraph $ + (opts font) + { paragraphLineHeight = Absolute 1600 } + result `shouldBeGolden` "lineHeightLarger" + it "handles smaller line height" $ \font -> do + let + result = layoutPlain $ trivialParagraph $ + (opts font) + { paragraphLineHeight = Absolute 599 } + result `shouldBeGolden` "lineHeightSmaller" + it "wraps by characters when line is ultra narrow" $ \font -> do + let + result = layoutPlain $ czechHelloParagraph $ + (opts font) + { paragraphMaxWidth = 100 } + result `shouldBeGolden` "czechHelloParagraphUltraNarrow" + it "wraps lorem ipsum at 20em" $ \font -> do + let + result = layoutPlain $ loremIpsumParagraph $ + (opts font) + { paragraphMaxWidth = 20000 } + result `shouldBeGolden` "loremIpsum20em" + it "wraps lorem ipsum at 100em" $ \font -> do + let + result = layoutPlain $ loremIpsumParagraph $ + (opts font) + { paragraphMaxWidth = 100000 } + result `shouldBeGolden` "loremIpsum100em" + it "wraps mixed-script words correctly" $ \font -> do + let + result = layoutPlain $ mixedScriptWordsParagraph $ + (opts font) + { paragraphMaxWidth = 6000 } + result `shouldBeGolden` "mixedScriptWordsParagraph" -- 2.30.2