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 ParagraphAlignment
- data BoxCollapse
- data BoxSpacing = BoxSpacingLeftRight Int32 Int32
- data VerticalAlignment
- = AlignLineTop
- | AlignLineBottom
- | AlignBaseline Int32
- data LineHeight
- data ParagraphOptions
- defaultParagraphOptions :: ParagraphOptions
- paragraphAlignment :: ParagraphOptions -> ParagraphAlignment
- 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
- class EmptyText t
- strut :: EmptyText t => d -> RootNode t d -> RootNode t d
- data BoxOptions
- defaultBoxOptions :: BoxOptions
- data TextOptions
- defaultTextOptions :: Direction -> TextOptions
- boxSpacing :: BoxOptions -> BoxSpacing
- boxCollapse :: BoxOptions -> BoxCollapse
- boxVerticalAlignment :: BoxOptions -> VerticalAlignment
- activateBoxSpacing :: BoxSpacing -> BoxOptions -> BoxOptions
- textFont :: TextOptions -> Font
- textAscender :: TextOptions -> Maybe Int32
- textDescender :: TextOptions -> Maybe Int32
- 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
- paragraphLines :: [Line]
- paragraphFragments :: [Fragment d]
- paragraphSafeWidth :: ParagraphLayout d -> Int32
- data Line = Line {
- lineNumber :: Int
- lineRect :: Rect Int32
- data Fragment d = Fragment {
- fragmentUserData :: d
- fragmentLine :: Int
- fragmentAncestorBoxes :: [AncestorBox d]
- fragmentContentRect :: Rect Int32
- 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 ParagraphAlignment #
Determines how the contents of the paragraph should be aligned horizontally, that is, how should fragments be stacked inside each line when there is space available.
This has no effect on lines with overflowing content.
AlignStart | Behave like |
AlignEnd | Behave like |
AlignLeft | Stack fragments to the left edge of each line, leaving free space on the right side. The leftmost fragment on each non-overflowing line will have its
|
AlignRight | Stack fragments to the right edge of each line, leaving free space on the left side. The rightmost fragment on each non-overflowing line will have its
|
AlignCentreH | Stack fragments to the horizontal centre of each line, leaving free space split evenly between each side. |
Instances
Eq ParagraphAlignment | |
Defined in Data.Text.ParagraphLayout.Internal.ParagraphAlignment (==) :: ParagraphAlignment -> ParagraphAlignment -> Bool (/=) :: ParagraphAlignment -> ParagraphAlignment -> Bool | |
Read ParagraphAlignment | |
Defined in Data.Text.ParagraphLayout.Internal.ParagraphAlignment readsPrec :: Int -> ReadS ParagraphAlignment readList :: ReadS [ParagraphAlignment] readPrec :: ReadPrec ParagraphAlignment readListPrec :: ReadPrec [ParagraphAlignment] | |
Show ParagraphAlignment | |
Defined in Data.Text.ParagraphLayout.Internal.ParagraphAlignment showsPrec :: Int -> ParagraphAlignment -> ShowS show :: ParagraphAlignment -> String showList :: [ParagraphAlignment] -> ShowS |
data BoxCollapse #
Determines how an inline box affects the height of a line that would otherwise be empty.
Note that for this setting to have any effect, the box must be the ancestor
of at least one (possibly empty) text sequence, so that it can generate
a Fragment
.
For CSS-compliant behaviour:
- Ensure that empty boxes contain empty text sequences as mentioned above.
This can be achieved using the
strut
function. - Set
AllowBoxCollapse
for boxes with zero margins, padding, and borders. - Set
AvoidBoxCollapse
for boxes with non-zero margins, padding, or borders.
Note that BoxSpacing
may contain zero values even when calculated from
non-zero CSS values, because of rounding to integer values and/or because
of adding together positive and negative values that cancel out. You should
therefore compare the individual computed values for margins, padding, and
borders with zero, and set boxCollapse
to AllowBoxCollapse
if and only
if all these values are equal to zero.
AllowBoxCollapse | The box should disappear when possible to make empty lines invisible. |
AvoidBoxCollapse | The box should be preserved when possible, making lines visible even when they would otherwise be empty. |
Instances
Eq BoxCollapse | |
Defined in Data.Text.ParagraphLayout.Internal.BoxOptions (==) :: BoxCollapse -> BoxCollapse -> Bool (/=) :: BoxCollapse -> BoxCollapse -> Bool | |
Read BoxCollapse | |
Defined in Data.Text.ParagraphLayout.Internal.BoxOptions readsPrec :: Int -> ReadS BoxCollapse readList :: ReadS [BoxCollapse] readPrec :: ReadPrec BoxCollapse readListPrec :: ReadPrec [BoxCollapse] | |
Show BoxCollapse | |
Defined in Data.Text.ParagraphLayout.Internal.BoxOptions showsPrec :: Int -> BoxCollapse -> ShowS show :: BoxCollapse -> String showList :: [BoxCollapse] -> ShowS |
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 VerticalAlignment #
Determines how the contents of a line should be aligned vertically, that is, how fragments should fill (and possibly extend) the vertical space inside a line.
Vertical alignment takes place after line breaking.
AlignLineTop | Align the top of this box with the top of the line. The top of this box is the topmost coordinate of any fragment
descended from this box, except for fragments that are descended from
another box with
This behaviour is equivalent to |
AlignLineBottom | Align the bottom of this box with the bottom of the line. The bottom of this box is the bottommost coordinate of any fragment
descended from this box, except for fragments that are descended from
another box with
This behaviour is equivalent to |
AlignBaseline Int32 | Align the baseline of this box with the baseline of its parent box, optionally shifting it by a specified amount upwards.
|
Instances
Eq VerticalAlignment | |
Defined in Data.Text.ParagraphLayout.Internal.BoxOptions (==) :: VerticalAlignment -> VerticalAlignment -> Bool (/=) :: VerticalAlignment -> VerticalAlignment -> Bool | |
Read VerticalAlignment | |
Defined in Data.Text.ParagraphLayout.Internal.BoxOptions readsPrec :: Int -> ReadS VerticalAlignment readList :: ReadS [VerticalAlignment] readPrec :: ReadPrec VerticalAlignment readListPrec :: ReadPrec [VerticalAlignment] | |
Show VerticalAlignment | |
Defined in Data.Text.ParagraphLayout.Internal.BoxOptions showsPrec :: Int -> VerticalAlignment -> ShowS show :: VerticalAlignment -> String showList :: [VerticalAlignment] -> ShowS |
data LineHeight #
Determines the preferred line height of text in the resulting layout.
Normal | The amount of vertical space taken up by the text in the layout will be exactly the distance between its font's ascender and descender line, with no further adjustment. |
Absolute Int32 | The amount of vertical space taken up by the text in the layout will be exactly the provided value. If this value is different from the distance between the font's ascender and descender line, the difference will be split in two equal parts (within a rounding error) and applied as half-leading both above and below the glyphs. |
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.
In order to get CSS defaults, use:
defaultParagraphOptions { paragraphAlignment = AlignStart }
Instances
Eq ParagraphOptions | |
Defined in Data.Text.ParagraphLayout.Internal.ParagraphOptions (==) :: ParagraphOptions -> ParagraphOptions -> Bool (/=) :: ParagraphOptions -> ParagraphOptions -> Bool |
defaultParagraphOptions :: ParagraphOptions #
ParagraphOptions
with backwards-compatible values.
Note that this sets paragraphAlignment
to AlignLeft
,
whereas the CSS default should be AlignStart
.
Paragraph options
These are record selectors that can be used for reading as well as updating specific option fields.
paragraphAlignment :: ParagraphOptions -> ParagraphAlignment #
Alignment of non-overflowing lines within the paragraph.
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 types that can represent an empty text sequence in a tree.
empty
Instances
EmptyText Int | |
Defined in Data.Text.ParagraphLayout.Internal.Tree empty :: Int | |
EmptyText Text | |
Defined in Data.Text.ParagraphLayout.Internal.Tree |
strut :: EmptyText t => d -> RootNode t d -> RootNode t d #
Insert an empty text sequence with the given user data into each empty 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.
In order to get CSS defaults, use:
defaultBoxOptions { boxVerticalAlignment = AlignBaseline 0 }
Instances
Eq BoxOptions | |
Defined in Data.Text.ParagraphLayout.Internal.BoxOptions (==) :: BoxOptions -> BoxOptions -> Bool (/=) :: BoxOptions -> BoxOptions -> Bool |
defaultBoxOptions :: BoxOptions #
BoxOptions
with backwards-compatible values.
Note that this sets boxVerticalAlignment
to AlignLineTop
,
whereas the CSS default should be `AlignBaseline 0`.
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.
In order to get CSS-compliant behaviour, consider using
activateBoxSpacing
instead.
boxCollapse :: BoxOptions -> BoxCollapse #
Determines how this box affects the height of a line that would otherwise be empty.
boxVerticalAlignment :: BoxOptions -> VerticalAlignment #
Determines how fragments are aligned vertically within a line.
activateBoxSpacing :: BoxSpacing -> BoxOptions -> BoxOptions #
Shorthand for updating boxSpacing
and setting boxCollapse
to AvoidBoxCollapse
.
Can be used to activate CSS-compliant rendering of empty boxes whose spacing is calculated from non-zero values.
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.
textAscender :: TextOptions -> Maybe Int32 #
How much to add to the text's baseline coordinate to reach its ascender line. This is usually a positive value.
If set to Nothing
, the font's own ascender
metric will be used.
Setting an explicit value with
is intended as an override
for situations where the text is intended to be replaced by an object
with differently calculated dimensions.Just
x
textDescender :: TextOptions -> Maybe Int32 #
How much to add to the text's baseline coordinate to reach its descender line. Note that this is usually a negative value because the descender is usually below the baseline.
If set to Nothing
, the font's own descender
metric will be used.
Setting an explicit value with
is intended as an override
for situations where the text is intended to be replaced by an object
with differently calculated dimensions.Just
x
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
paragraphSafeWidth :: ParagraphLayout d -> Int32 #
Width of the widest line, including spacing.
This is the smallest paragraphMaxWidth
that will not introduce new line breaks.
When paragraphMaxWidth
is set to maxBound
,
paragraphSafeWidth
can be used to determine the max-content
width of the
paragraph for CSS.
Information about a line in a laid out paragraph.
Line | |
|
Instances
Eq Line | |
Read Line | |
Defined in Data.Text.ParagraphLayout.Internal.Line | |
Show Line | |
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 |