Safe Haskell | None |
---|---|
Language | Haskell2010 |
Interface for laying out paragraphs of rich text.
The main entry point is the function layoutRich
.
Synopsis
- data Paragraph d = Paragraph Array Int (RootNode Int d) ParagraphOptions
- constructParagraph :: Text -> RootNode Text d -> Text -> ParagraphOptions -> Paragraph d
- data BoxSpacing = BoxSpacingLeftRight Int32 Int32
- data LineHeight
- data ParagraphOptions
- defaultParagraphOptions :: ParagraphOptions
- paragraphLineHeight :: ParagraphOptions -> LineHeight
- paragraphMaxWidth :: ParagraphOptions -> Int32
- data RootNode t d = RootBox (Box t d)
- data InnerNode t d
- = InlineBox d (Box t d) BoxOptions
- | TextSequence d t
- data Box t d = Box [InnerNode t d] TextOptions
- data BoxOptions
- defaultBoxOptions :: BoxOptions
- data TextOptions
- defaultTextOptions :: Direction -> TextOptions
- boxSpacing :: BoxOptions -> BoxSpacing
- textFont :: TextOptions -> Font
- textLineHeight :: TextOptions -> LineHeight
- textLanguage :: TextOptions -> String
- textDirection :: TextOptions -> Direction
- paragraphSpanBounds :: Paragraph d -> NonEmpty Int
- paragraphSpanTexts :: Paragraph d -> [Text]
- paragraphText :: Paragraph d -> Text
- layoutRich :: Paragraph d -> ParagraphLayout d
- data ParagraphLayout d = ParagraphLayout {
- paragraphRect :: Rect Int32
- paragraphFragments :: [Fragment d]
- data Fragment d = Fragment {
- fragmentUserData :: d
- fragmentLine :: Int
- fragmentAncestorBoxes :: [AncestorBox d]
- fragmentRect :: Rect Int32
- fragmentPen :: (Int32, Int32)
- fragmentGlyphs :: [(GlyphInfo, GlyphPos)]
- fragmentSpacedRect :: Fragment d -> Rect Int32
- data AncestorBox d = AncestorBox {
- boxUserData :: d
- boxLeftEdge :: BoxEdge
- boxRightEdge :: BoxEdge
- boxStartEdge :: BoxEdge
- boxEndEdge :: BoxEdge
- data BoxEdge
- = NoEdge
- | SpacedEdge Int32
Documentation
Text to be laid out as a single paragraph.
May be divided into a hierarchy of boxes and spans.
The input text must be encoded as UTF-8 in a contiguous byte array.
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.
Paragraph | |
|
:: 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
|
data BoxSpacing #
Determines the amount of empty space to add around a box.
BoxSpacingLeftRight | Specification using absolute directions, unaffected by text direction. (However, text direction is still used in case of fragmentation, to determine how to map the first (last) fragment to left (right).) |
|
Instances
Eq BoxSpacing | |
Defined in Data.Text.ParagraphLayout.Internal.BoxOptions (==) :: BoxSpacing -> BoxSpacing -> Bool (/=) :: BoxSpacing -> BoxSpacing -> Bool | |
Read BoxSpacing | |
Defined in Data.Text.ParagraphLayout.Internal.BoxOptions readsPrec :: Int -> ReadS BoxSpacing readList :: ReadS [BoxSpacing] readPrec :: ReadPrec BoxSpacing readListPrec :: ReadPrec [BoxSpacing] | |
Show BoxSpacing | |
Defined in Data.Text.ParagraphLayout.Internal.BoxOptions showsPrec :: Int -> BoxSpacing -> ShowS show :: BoxSpacing -> String showList :: [BoxSpacing] -> ShowS |
data LineHeight #
Determines the preferred line height of text in the resulting layout.
Normal | Determine the preferred line height automatically using its ascent and descent metrics. |
Absolute Int32 | Set the preferred line height independently of the font. |
Instances
Eq LineHeight | |
Defined in Data.Text.ParagraphLayout.Internal.LineHeight (==) :: LineHeight -> LineHeight -> Bool (/=) :: LineHeight -> LineHeight -> Bool | |
Read LineHeight | |
Defined in Data.Text.ParagraphLayout.Internal.LineHeight readsPrec :: Int -> ReadS LineHeight readList :: ReadS [LineHeight] readPrec :: ReadPrec LineHeight readListPrec :: ReadPrec [LineHeight] | |
Show LineHeight | |
Defined in Data.Text.ParagraphLayout.Internal.LineHeight showsPrec :: Int -> LineHeight -> ShowS show :: LineHeight -> String showList :: [LineHeight] -> ShowS |
data ParagraphOptions #
Defines options relevant to the entire paragraph.
This record type is likely to be extended in the future.
Use defaultParagraphOptions
and update it with specific record selectors
instead of constructing ParagraphOptions
directly.
Instances
Eq ParagraphOptions | |
Defined in Data.Text.ParagraphLayout.Internal.ParagraphOptions (==) :: ParagraphOptions -> ParagraphOptions -> Bool (/=) :: ParagraphOptions -> ParagraphOptions -> Bool |
defaultParagraphOptions :: ParagraphOptions #
ParagraphOptions
with default values.
Paragraph options
These are record selectors that can be used for reading as well as updating specific option fields.
paragraphLineHeight :: ParagraphOptions -> LineHeight #
Preferred line height of the resulting fragments.
paragraphMaxWidth :: ParagraphOptions -> Int32 #
Line width at which line breaking should occur. Lines will be broken at language-appropriate boundaries. If a line still exceeds this limit then, it will be broken at character boundaries, and if it already consists of a single cluster that cannot be further broken down, it will overflow.
Content tree
Root of the paragraph tree.
Non-root node of the paragraph tree.
InlineBox | An inline box, nested in another box. |
| |
TextSequence | A leaf node containing text. |
|
A box with content and a defined format. Corresponds to a DOM element.
Box | |
|
data BoxOptions #
Style options to be applied to an inline box.
This record type is likely to be extended in the future.
Use defaultBoxOptions
and update it with specific record selectors
instead of constructing BoxOptions
directly.
Instances
Eq BoxOptions | |
Defined in Data.Text.ParagraphLayout.Internal.BoxOptions (==) :: BoxOptions -> BoxOptions -> Bool (/=) :: BoxOptions -> BoxOptions -> Bool |
defaultBoxOptions :: BoxOptions #
BoxOptions
with default values.
data TextOptions #
Style options to be applied to a text sequence.
This record type is likely to be extended in the future.
Use defaultTextOptions
and update it with specific record selectors
instead of constructing TextOptions
directly.
Instances
Eq TextOptions | |
Defined in Data.Text.ParagraphLayout.Internal.TextOptions (==) :: TextOptions -> TextOptions -> Bool (/=) :: TextOptions -> TextOptions -> Bool |
:: Direction | Required value for |
-> TextOptions |
TextOptions
with default values.
Box options
These are record selectors that can be used for reading as well as updating specific option fields.
boxSpacing :: BoxOptions -> BoxSpacing #
Determines amount of empty space to add before the first fragment and/or after the last fragment of this box.
This can be used to reserve space for a left margin, border, and/or padding.
Text options
These are record selectors that can be used for reading as well as updating specific option fields.
textFont :: TextOptions -> Font #
Font to be used for shaping and measurement.
Make sure to set its scale (see optionScale
) using
the same units that you want in the output.
textLineHeight :: TextOptions -> LineHeight #
Preferred line height of the resulting fragments.
textLanguage :: TextOptions -> String #
IETF BCP 47 language tag, such as the value expected to be found in
the HTML lang
attribute, specifying the primary language for the
span's text content. An empty string explicitly means "language unknown".
Used for selecting the appropriate glyphs and line breaking rules, primarily in East Asian languages.
textDirection :: TextOptions -> Direction #
Base text direction.
Used to determine which box fragment gets the left spacing and which gets the right spacing when broken over multiple lines.
When applied to the root box in a paragraph, this is also used to determine the base direction of the paragraph.
Verification
paragraphSpanBounds :: Paragraph d -> NonEmpty Int #
paragraphSpanTexts :: Paragraph d -> [Text] #
paragraphText :: Paragraph d -> Text #
Output layout
layoutRich :: Paragraph d -> ParagraphLayout d #
Lay out a rich text paragraph.
data ParagraphLayout d #
The resulting layout of the whole paragraph.
ParagraphLayout | |
|
Instances
A unit of text laid out in a rectangular area.
Roughly equivalent to the term text fragment as used in CSS Display Module Level 3.
An input span (or text sequence in CSS terms) can be broken into multiple fragments because of line breaking, because of bidirectional ordering, or because it contains glyphs from multiple scripts.
Fragment | |
|
Instances
Eq d => Eq (Fragment d) | |
Read d => Read (Fragment d) | |
Defined in Data.Text.ParagraphLayout.Internal.Fragment | |
Show d => Show (Fragment d) | |
fragmentSpacedRect :: Fragment d -> Rect Int32 #
Physical position of the fragment within the paragraph, with spacing added to the glyph advances. This is the space that the fragment takes up in the paragraph.
data AncestorBox d #
Describes the relationship of a fragment to an inline box that contains it.
A box can have many fragments, and a fragment contained by a box is also contained by all ancestors of that box.
The root inline box, which forms the basis of each paragraph, is implied and not described by this type of record.
AncestorBox | |
|
Instances
Eq d => Eq (AncestorBox d) | |
Defined in Data.Text.ParagraphLayout.Internal.AncestorBox (==) :: AncestorBox d -> AncestorBox d -> Bool (/=) :: AncestorBox d -> AncestorBox d -> Bool | |
Read d => Read (AncestorBox d) | |
Defined in Data.Text.ParagraphLayout.Internal.AncestorBox readsPrec :: Int -> ReadS (AncestorBox d) readList :: ReadS [AncestorBox d] readPrec :: ReadPrec (AncestorBox d) readListPrec :: ReadPrec [AncestorBox d] | |
Show d => Show (AncestorBox d) | |
Defined in Data.Text.ParagraphLayout.Internal.AncestorBox showsPrec :: Int -> AncestorBox d -> ShowS show :: AncestorBox d -> String showList :: [AncestorBox d] -> ShowS |
Describes either the absence, or the presence and size, of a box edge at a given position.
NoEdge | The given box does not have an edge here. This typically means that the box was fragmented and that the given edge is associated with another fragment. |
SpacedEdge Int32 | The given box has an edge here, adding a given amount of empty space
from the |