From 882969e0d9acabfc05f5ccad69c63d64983b9814 Mon Sep 17 00:00:00 2001 From: Jaro Date: Sat, 6 May 2023 08:27:32 +0200 Subject: [PATCH] Link ResolvedSpan to boxes. --- src/Data/Text/ParagraphLayout/Internal/ResolvedSpan.hs | 2 ++ src/Data/Text/ParagraphLayout/Internal/Rich.hs | 3 ++- test/Data/Text/ParagraphLayout/SpanData.hs | 8 ++++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Data/Text/ParagraphLayout/Internal/ResolvedSpan.hs b/src/Data/Text/ParagraphLayout/Internal/ResolvedSpan.hs index 5d39fbc..314b930 100644 --- a/src/Data/Text/ParagraphLayout/Internal/ResolvedSpan.hs +++ b/src/Data/Text/ParagraphLayout/Internal/ResolvedSpan.hs @@ -4,6 +4,7 @@ where import Data.Text (Text) import qualified Data.Text.ICU as BreakStatus (Line) +import Data.Text.ParagraphLayout.Internal.ResolvedBox import Data.Text.ParagraphLayout.Internal.TextContainer import Data.Text.ParagraphLayout.Internal.TextOptions @@ -15,6 +16,7 @@ data ResolvedSpan d = ResolvedSpan , spanOffsetInParagraph :: Int , spanText :: Text , spanTextOptions :: TextOptions + , spanBoxes :: [ResolvedBox d] , spanLineBreaks :: [(Int, BreakStatus.Line)] -- TODO: Can be optimised by starting with the shortest line break. , spanCharacterBreaks :: [(Int, ())] diff --git a/src/Data/Text/ParagraphLayout/Internal/Rich.hs b/src/Data/Text/ParagraphLayout/Internal/Rich.hs index 0c89403..3ad7a8a 100644 --- a/src/Data/Text/ParagraphLayout/Internal/Rich.hs +++ b/src/Data/Text/ParagraphLayout/Internal/Rich.hs @@ -55,7 +55,7 @@ resolveSpans p@(Paragraph _ pStart root _) = do <*> ZipList leaves <*> ZipList sStarts <*> ZipList sTexts - let (TextLeaf userData _ textOpts _) = leaf + let (TextLeaf userData _ textOpts boxes) = leaf let lang = textLanguage textOpts let lBreaks = paragraphBreaks breakLine pText lang let cBreaks = paragraphBreaks breakCharacter pText lang @@ -66,6 +66,7 @@ resolveSpans p@(Paragraph _ pStart root _) = do -- TODO: Consider adding checks for array bounds. , RS.spanText = sText , RS.spanTextOptions = textOpts + , RS.spanBoxes = boxes , RS.spanLineBreaks = subOffsetsDesc (sStart - pStart) lBreaks , RS.spanCharacterBreaks = subOffsetsDesc (sStart - pStart) cBreaks } diff --git a/test/Data/Text/ParagraphLayout/SpanData.hs b/test/Data/Text/ParagraphLayout/SpanData.hs index 87f4bc3..63fec2f 100644 --- a/test/Data/Text/ParagraphLayout/SpanData.hs +++ b/test/Data/Text/ParagraphLayout/SpanData.hs @@ -8,10 +8,15 @@ where import Data.Text (pack) import Data.Text.Glyphize (Font) +import Data.Text.ParagraphLayout.Internal.BoxOptions import Data.Text.ParagraphLayout.Internal.LineHeight +import Data.Text.ParagraphLayout.Internal.ResolvedBox import Data.Text.ParagraphLayout.Internal.ResolvedSpan import Data.Text.ParagraphLayout.Internal.TextOptions +defaultBox :: ResolvedBox () +defaultBox = ResolvedBox () 0 defaultBoxOptions + emptySpan :: Font -> ResolvedSpan () emptySpan font = ResolvedSpan { spanUserData = () @@ -23,6 +28,7 @@ emptySpan font = ResolvedSpan , textLineHeight = Normal , textLanguage = "en" } + , spanBoxes = [defaultBox] , spanLineBreaks = [] , spanCharacterBreaks = [] } @@ -38,6 +44,7 @@ czechHello font = ResolvedSpan , textLineHeight = Normal , textLanguage = "cs" } + , spanBoxes = [defaultBox] , spanLineBreaks = [] , spanCharacterBreaks = [] } @@ -53,6 +60,7 @@ serbianMixedScript font = ResolvedSpan , textLineHeight = Normal , textLanguage = "sr" } + , spanBoxes = [defaultBox] , spanLineBreaks = [] , spanCharacterBreaks = [] } -- 2.30.2