~jaro/balkon

0615750e4579cfdb72cebbc24c22e23491d5e102 — Jaro 1 year, 5 months ago 5e218e2
Autodetect text direction for legacy interface.
M .golden/paginatedParagraphLayout/spannedArabicFiller20em.golden => .golden/paginatedParagraphLayout/spannedArabicFiller20em.golden +4 -4
@@ 180,7 180,7 @@
            { fragmentUserData = ()
            , fragmentLine = 2
            , fragmentAncestorBoxes =
                [ AncestorBox {boxUserData = (), boxLeftEdge = SpacedEdge 0, boxRightEdge = NoEdge, boxStartEdge = SpacedEdge 0, boxEndEdge = NoEdge}
                [ AncestorBox {boxUserData = (), boxLeftEdge = NoEdge, boxRightEdge = SpacedEdge 0, boxStartEdge = SpacedEdge 0, boxEndEdge = NoEdge}
                ]
            , fragmentRect = Rect {x_origin = 0, y_origin = -1500, x_size = 3213, y_size = -1500}
            , fragmentPen = (0, -1085)


@@ 240,7 240,7 @@
            { fragmentUserData = ()
            , fragmentLine = 3
            , fragmentAncestorBoxes =
                [ AncestorBox {boxUserData = (), boxLeftEdge = NoEdge, boxRightEdge = SpacedEdge 0, boxStartEdge = NoEdge, boxEndEdge = SpacedEdge 0}
                [ AncestorBox {boxUserData = (), boxLeftEdge = SpacedEdge 0, boxRightEdge = NoEdge, boxStartEdge = NoEdge, boxEndEdge = SpacedEdge 0}
                ]
            , fragmentRect = Rect {x_origin = 14300, y_origin = 0, x_size = 4862, y_size = -1500}
            , fragmentPen = (0, -1085)


@@ 320,7 320,7 @@
            { fragmentUserData = ()
            , fragmentLine = 3
            , fragmentAncestorBoxes =
                [ AncestorBox {boxUserData = (), boxLeftEdge = SpacedEdge 0, boxRightEdge = NoEdge, boxStartEdge = SpacedEdge 0, boxEndEdge = NoEdge}
                [ AncestorBox {boxUserData = (), boxLeftEdge = NoEdge, boxRightEdge = SpacedEdge 0, boxStartEdge = SpacedEdge 0, boxEndEdge = NoEdge}
                ]
            , fragmentRect = Rect {x_origin = 0, y_origin = 0, x_size = 3898, y_size = -1500}
            , fragmentPen = (0, -1085)


@@ 339,7 339,7 @@
            { fragmentUserData = ()
            , fragmentLine = 4
            , fragmentAncestorBoxes =
                [ AncestorBox {boxUserData = (), boxLeftEdge = NoEdge, boxRightEdge = SpacedEdge 0, boxStartEdge = NoEdge, boxEndEdge = SpacedEdge 0}
                [ AncestorBox {boxUserData = (), boxLeftEdge = SpacedEdge 0, boxRightEdge = NoEdge, boxStartEdge = NoEdge, boxEndEdge = SpacedEdge 0}
                ]
            , fragmentRect = Rect {x_origin = 12238, y_origin = -1500, x_size = 2357, y_size = -1500}
            , fragmentPen = (0, -1085)

M .golden/paragraphLayout/arabicFiller20em.golden => .golden/paragraphLayout/arabicFiller20em.golden +2 -2
@@ 6,7 6,7 @@ ParagraphLayout
            { fragmentUserData = ()
            , fragmentLine = 1
            , fragmentAncestorBoxes =
                [ AncestorBox {boxUserData = (), boxLeftEdge = SpacedEdge 0, boxRightEdge = NoEdge, boxStartEdge = SpacedEdge 0, boxEndEdge = NoEdge}
                [ AncestorBox {boxUserData = (), boxLeftEdge = NoEdge, boxRightEdge = SpacedEdge 0, boxStartEdge = SpacedEdge 0, boxEndEdge = NoEdge}
                ]
            , fragmentRect = Rect {x_origin = 0, y_origin = 0, x_size = 19850, y_size = -1500}
            , fragmentPen = (0, -1085)


@@ 184,7 184,7 @@ ParagraphLayout
            { fragmentUserData = ()
            , fragmentLine = 4
            , fragmentAncestorBoxes =
                [ AncestorBox {boxUserData = (), boxLeftEdge = NoEdge, boxRightEdge = SpacedEdge 0, boxStartEdge = NoEdge, boxEndEdge = SpacedEdge 0}
                [ AncestorBox {boxUserData = (), boxLeftEdge = SpacedEdge 0, boxRightEdge = NoEdge, boxStartEdge = NoEdge, boxEndEdge = SpacedEdge 0}
                ]
            , fragmentRect = Rect {x_origin = 0, y_origin = -4500, x_size = 14595, y_size = -1500}
            , fragmentPen = (0, -1085)

M .golden/paragraphLayout/hardBreaksRTL.golden => .golden/paragraphLayout/hardBreaksRTL.golden +2 -2
@@ 6,7 6,7 @@ ParagraphLayout
            { fragmentUserData = ()
            , fragmentLine = 1
            , fragmentAncestorBoxes =
                [ AncestorBox {boxUserData = (), boxLeftEdge = SpacedEdge 0, boxRightEdge = NoEdge, boxStartEdge = SpacedEdge 0, boxEndEdge = NoEdge}
                [ AncestorBox {boxUserData = (), boxLeftEdge = NoEdge, boxRightEdge = SpacedEdge 0, boxStartEdge = SpacedEdge 0, boxEndEdge = NoEdge}
                ]
            , fragmentRect = Rect {x_origin = 0, y_origin = 0, x_size = 2808, y_size = -1500}
            , fragmentPen = (0, -1085)


@@ 137,7 137,7 @@ ParagraphLayout
            { fragmentUserData = ()
            , fragmentLine = 9
            , fragmentAncestorBoxes =
                [ AncestorBox {boxUserData = (), boxLeftEdge = NoEdge, boxRightEdge = SpacedEdge 0, boxStartEdge = NoEdge, boxEndEdge = SpacedEdge 0}
                [ AncestorBox {boxUserData = (), boxLeftEdge = SpacedEdge 0, boxRightEdge = NoEdge, boxStartEdge = NoEdge, boxEndEdge = SpacedEdge 0}
                ]
            , fragmentRect = Rect {x_origin = 0, y_origin = -12000, x_size = 1960, y_size = -1500}
            , fragmentPen = (0, -1085)

M .golden/paragraphLayout/spannedArabicFiller20em.golden => .golden/paragraphLayout/spannedArabicFiller20em.golden +4 -4
@@ 180,7 180,7 @@ ParagraphLayout
            { fragmentUserData = ()
            , fragmentLine = 2
            , fragmentAncestorBoxes =
                [ AncestorBox {boxUserData = (), boxLeftEdge = SpacedEdge 0, boxRightEdge = NoEdge, boxStartEdge = SpacedEdge 0, boxEndEdge = NoEdge}
                [ AncestorBox {boxUserData = (), boxLeftEdge = NoEdge, boxRightEdge = SpacedEdge 0, boxStartEdge = SpacedEdge 0, boxEndEdge = NoEdge}
                ]
            , fragmentRect = Rect {x_origin = 0, y_origin = -1500, x_size = 3213, y_size = -1500}
            , fragmentPen = (0, -1085)


@@ 200,7 200,7 @@ ParagraphLayout
            { fragmentUserData = ()
            , fragmentLine = 3
            , fragmentAncestorBoxes =
                [ AncestorBox {boxUserData = (), boxLeftEdge = NoEdge, boxRightEdge = SpacedEdge 0, boxStartEdge = NoEdge, boxEndEdge = SpacedEdge 0}
                [ AncestorBox {boxUserData = (), boxLeftEdge = SpacedEdge 0, boxRightEdge = NoEdge, boxStartEdge = NoEdge, boxEndEdge = SpacedEdge 0}
                ]
            , fragmentRect = Rect {x_origin = 14300, y_origin = -3000, x_size = 4862, y_size = -1500}
            , fragmentPen = (0, -1085)


@@ 280,7 280,7 @@ ParagraphLayout
            { fragmentUserData = ()
            , fragmentLine = 3
            , fragmentAncestorBoxes =
                [ AncestorBox {boxUserData = (), boxLeftEdge = SpacedEdge 0, boxRightEdge = NoEdge, boxStartEdge = SpacedEdge 0, boxEndEdge = NoEdge}
                [ AncestorBox {boxUserData = (), boxLeftEdge = NoEdge, boxRightEdge = SpacedEdge 0, boxStartEdge = SpacedEdge 0, boxEndEdge = NoEdge}
                ]
            , fragmentRect = Rect {x_origin = 0, y_origin = -3000, x_size = 3898, y_size = -1500}
            , fragmentPen = (0, -1085)


@@ 299,7 299,7 @@ ParagraphLayout
            { fragmentUserData = ()
            , fragmentLine = 4
            , fragmentAncestorBoxes =
                [ AncestorBox {boxUserData = (), boxLeftEdge = NoEdge, boxRightEdge = SpacedEdge 0, boxStartEdge = NoEdge, boxEndEdge = SpacedEdge 0}
                [ AncestorBox {boxUserData = (), boxLeftEdge = SpacedEdge 0, boxRightEdge = NoEdge, boxStartEdge = NoEdge, boxEndEdge = SpacedEdge 0}
                ]
            , fragmentRect = Rect {x_origin = 12238, y_origin = -4500, x_size = 2357, y_size = -1500}
            , fragmentPen = (0, -1085)

M src/Data/Text/ParagraphLayout/Internal/BiDiLevels.hs => src/Data/Text/ParagraphLayout/Internal/BiDiLevels.hs +1 -0
@@ 3,6 3,7 @@ module Data.Text.ParagraphLayout.Internal.BiDiLevels
    , TextLevels (TextLevels)
    , WithLevel
    , dropLevels
    , firstStrongDirection
    , headLevel
    , level
    , levelDirectionH

M src/Data/Text/ParagraphLayout/Internal/Plain.hs => src/Data/Text/ParagraphLayout/Internal/Plain.hs +15 -2
@@ 5,6 5,7 @@ where
import Data.Text.Glyphize (Direction (DirLTR))

import Data.Text.ParagraphLayout.Internal.AncestorBox
import Data.Text.ParagraphLayout.Internal.BiDiLevels
import Data.Text.ParagraphLayout.Internal.BoxOptions
import Data.Text.ParagraphLayout.Internal.Fragment
import Data.Text.ParagraphLayout.Internal.ParagraphOptions


@@ 29,7 30,8 @@ layoutPlain p@(P.Paragraph _ _ spans _) =
-- Span indexes are added to the user data internally, then used to split the
-- resulting fragments according to their corresponding spans.
plainToRich :: P.Paragraph d -> R.Paragraph (Int, d)
plainToRich (P.Paragraph arr off spans opts) = R.Paragraph arr off rootNode opts
plainToRich p@(P.Paragraph arr off spans opts) =
    R.Paragraph arr off rootNode opts
    where
        rootNode = RootBox rootBox
        rootBox = Box spanNodes baseOpts


@@ 39,11 41,22 @@ plainToRich (P.Paragraph arr off spans opts) = R.Paragraph arr off rootNode opts
            (boxFromPlain baseOpts i s)
            defaultBoxOptions
        indexedSpans = zip [0 ..] spans
        baseOpts = (defaultTextOptions DirLTR)
        baseOpts = (defaultTextOptions $ detectDirection p)
            { textFont = paragraphFont opts
            , textLineHeight = paragraphLineHeight opts
            }

-- | Simplified autodetection of text direction for plain text,
-- to provide temporary compatibility with the old interface which
-- did not allow setting text direction explicitly.
--
-- Note that the detected direction carries over hard line breaks,
-- which is not compliant with the Unicode Bidirectional Algorithm.
detectDirection :: P.Paragraph d -> Direction
detectDirection p = case firstStrongDirection (P.paragraphText p) of
    Just dir -> dir
    Nothing -> DirLTR

-- | Convert a legacy `Span` to a rich text box with one text node inside.
--
-- Add the given index to the user data, so that it can be extracted later.