~jaro/balkon

dfa301d6c0659e437ae66d72787a23b4393b33f2 — Jaro 11 months ago 0680c59
Expose piecewise paragraph construction.
M lib/Data/Text/ParagraphLayout/Rich.hs => lib/Data/Text/ParagraphLayout/Rich.hs +1 -0
@@ 4,6 4,7 @@
module Data.Text.ParagraphLayout.Rich
    -- * Input paragraph
    ( Paragraph (Paragraph)
    , constructParagraph
    , BoxSpacing (BoxSpacingLeftRight)
    , LineHeight (Absolute, Normal)
    , ParagraphOptions

M src/Data/Text/ParagraphLayout/Internal/Rich/Paragraph.hs => src/Data/Text/ParagraphLayout/Internal/Rich/Paragraph.hs +20 -2
@@ 24,6 24,8 @@ import Data.Text.ParagraphLayout.Internal.Tree
-- You may need to use "Data.Text.Internal" in order to determine the byte
-- array and the necessary offsets to construct the paragraph without copying
-- data.
--
-- Alternatively, you can use `constructParagraph` with piecewise text.
data Paragraph d = Paragraph

    Array


@@ 49,8 51,24 @@ data Paragraph d = Paragraph
    ParagraphOptions
    -- ^ Options applying to the paragraph as a whole.

constructParagraph :: Text -> RootNode Text d -> Text -> ParagraphOptions ->
    Paragraph d
-- | Construct a `Paragraph` from a tree containing individual pieces of text,
-- plus an optional prefix and suffix, all encoded as UTF-8.
--
-- This internally concatenates all input text into one contiguous byte array.
--
-- Alternatively, you can construct a `Paragraph` directly to avoid copying
-- data.
constructParagraph
    :: Text
    -- ^ Optional prefix. Will not be laid out but may affect the output.
    -> RootNode Text d
    -- ^ Parts of the text to be laid out, represented as a tree.
    -> Text
    -- ^ Optional suffix. Will not be laid out but may affect the output.
    -> ParagraphOptions
    -- ^ Options to apply to the paragraph as a whole.
    -> Paragraph d
    -- ^ Constructed paragraph that can be passed to `layoutRich`.
constructParagraph prefix root suffix = Paragraph arr afterPrefix root'
    where
        (Text arr beforePrefix _) = txt