~jaro/balkon

278ffb65d2bef8d684bdd94fd3b1f546efd6a41d — Jaro 1 year, 8 months ago e92c514
Qualify Plain interface.
7 files changed, 65 insertions(+), 37 deletions(-)

M CHANGELOG.md
M balkon.cabal
M lib/Data/Text/ParagraphLayout.hs
A lib/Data/Text/ParagraphLayout/Plain.hs
M test/Data/Text/ParagraphLayout/Plain/ParagraphData.hs
R test/Data/Text/{ParagraphLayoutSpec.hs => ParagraphLayout/PlainSpec.hs}
M test/Data/Text/ParagraphLayout/PrettyShow.hs
M CHANGELOG.md => CHANGELOG.md +3 -0
@@ 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.


M balkon.cabal => balkon.cabal +2 -1
@@ 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,

M lib/Data/Text/ParagraphLayout.hs => lib/Data/Text/ParagraphLayout.hs +6 -27
@@ 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

A lib/Data/Text/ParagraphLayout/Plain.hs => lib/Data/Text/ParagraphLayout/Plain.hs +43 -0
@@ 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

M test/Data/Text/ParagraphLayout/Plain/ParagraphData.hs => test/Data/Text/ParagraphLayout/Plain/ParagraphData.hs +1 -1
@@ 20,7 20,7 @@ module Data.Text.ParagraphLayout.Plain.ParagraphData
    )
where

import Data.Text.ParagraphLayout
import Data.Text.ParagraphLayout.Plain
    ( Paragraph
    , ParagraphOptions
    , SpanOptions (spanLanguage)

R test/Data/Text/ParagraphLayoutSpec.hs => test/Data/Text/ParagraphLayout/PlainSpec.hs +2 -1
@@ 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

M test/Data/Text/ParagraphLayout/PrettyShow.hs => test/Data/Text/ParagraphLayout/PrettyShow.hs +8 -7
@@ 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